Skip to content

Deployment preview on Vercel #20

Deployment preview on Vercel

Deployment preview on Vercel #20

Workflow file for this run

name: Deploy PR previews
on:
pull_request:
types:
- opened
- reopened
- synchronize
- closed
branches:
- main
jobs:
deploy-preview:
runs-on: ubuntu-latest
concurrency: 2
if: github.event.action != 'closed'
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:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request' && (github.event.action == 'closed' || github.event.action == 'merged')
steps:
# Checkout to the gh-pages branch
- name: Checkout
uses: actions/checkout@v3
with:
ref: gh-pages
# Delete the deployment folder for the PR
- name: Delete PR preview folder
run: rm -rf pr-preview/${{ github.event.pull_request.number }}