-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
name: PR Review and Deploy | ||
|
||
on: | ||
pull_request: | ||
types: [opened, synchronize, reopened] | ||
|
||
jobs: | ||
review_and_deploy: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Create review branch | ||
run: | | ||
git fetch origin ${{ github.event.pull_request.head.ref }} | ||
git checkout -b pr-review-${{ github.event.pull_request.number }} origin/${{ github.event.pull_request.head.ref }} | ||
- name: Setup Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: '16' | ||
|
||
- name: Install dependencies | ||
run: npm ci | ||
|
||
- name: Run tests | ||
run: npm test | ||
|
||
- name: Build project | ||
run: npm run build | ||
|
||
- name: Deploy to GitHub Pages | ||
uses: peaceiris/actions-gh-pages@v3 | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
publish_dir: ./build | ||
destination_dir: pr-preview/${{ github.event.pull_request.number }} | ||
|
||
- name: Comment PR with preview link | ||
uses: actions/github-script@v6 | ||
with: | ||
github-token: ${{secrets.GITHUB_TOKEN}} | ||
script: | | ||
github.rest.issues.createComment({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
body: `Preview deployed to https://${context.repo.owner}.github.io/${context.repo.repo}/pr-preview/${context.issue.number}/` | ||
}) | ||
- name: Merge all PRs and deploy via Codespace | ||
run: | | ||
git config --global user.name "github-actions[bot]" | ||
git config --global user.email "github-actions[bot]@users.noreply.github.com" | ||
git fetch origin | ||
git merge --no-commit --no-ff origin/${{ github.event.pull_request.head.ref }} | ||
git push origin main | ||
curl -X POST \ | ||
https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/workflows/deploy.yml/dispatches \ | ||
-H 'Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \ | ||
-H 'Content-Type: application/json' \ | ||
-d '{"ref":"main"}' | ||
- name: Run site via Codespace | ||
uses: github/codespaces-action@v1 | ||
with: | ||
codespace_name: ${{ github.event.pull_request.number }} | ||
codespace_repo: ${{ github.event.repository.name }} | ||
codespace_ref: main | ||
codespace_command: npm start |