Deployment preview on Vercel #11
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
name: Deploy PR previews | |
on: | |
pull_request: | |
types: | |
- opened | |
- reopened | |
- synchronize | |
- closed | |
branches: | |
- main | |
jobs: | |
deploy-preview: | |
runs-on: ubuntu-latest | |
concurrency: 2 | |
steps: | |
# Check out the repository | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
# Install dependencies and build project | |
- name: Install dependencies and build | |
run: | | |
yarn install | |
yarn build:pr:preview | |
# Deploy to GitHub Pages | |
- name: Deploy to GitHub Pages | |
uses: JamesIves/github-pages-deploy-action@v4 | |
with: | |
folder: build | |
branch: gh-pages | |
target-folder: pr-preview/${{ github.event.pull_request.number }} | |
clean: true | |
# Comment the deployment URL on the PR | |
- name: Comment PR with deployment URL | |
run: | | |
COMMENT="Preview URL: https://${{ github.repository_owner }}.github.io/${{ github.repository_name }}/pr-preview/${{ github.event.pull_request.number }}" | |
echo "${COMMENT}" > comment.txt | |
cat comment.txt | |
curl -d "{\"body\":\"${COMMENT}\"}" -H "Content-Type: application/json" -X POST "${{ github.api_url }}/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments" -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" | |
cleanup: | |
needs: deploy-preview | |
runs-on: ubuntu-latest | |
if: github.event_name == 'pull_request' && (github.event.action == 'closed' || github.event.action == 'merged') | |
steps: | |
# Delete the deployment folder for the PR | |
- name: Delete PR preview folder | |
run: rm -rf pr-preview/${{ github.event.pull_request.number }} |