Skip to content

Commit

Permalink
Update prcheckmerge.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
berlintay authored Sep 1, 2024
1 parent 8209530 commit 96b3df9
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions .github/workflows/prcheckmerge.yml
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

0 comments on commit 96b3df9

Please sign in to comment.