Spaces:
Running
Running
| name: Deploy frontend (Vercel) | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| branches: [main] | |
| workflow_dispatch: | |
| concurrency: | |
| group: vercel-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| deploy: | |
| name: ${{ github.event_name == 'push' && 'Production' || 'Preview' }} | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: ${{ github.event_name == 'push' && 'production' || 'preview' }} | |
| env: | |
| VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} | |
| VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| - name: Install Vercel CLI | |
| run: npm install --global vercel@latest | |
| - name: Pull Vercel environment information | |
| run: | | |
| if [ "${{ github.event_name }}" = "push" ]; then | |
| vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }} | |
| else | |
| vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }} | |
| fi | |
| - name: Build project artifacts | |
| run: | | |
| if [ "${{ github.event_name }}" = "push" ]; then | |
| vercel build --prod --token=${{ secrets.VERCEL_TOKEN }} | |
| else | |
| vercel build --token=${{ secrets.VERCEL_TOKEN }} | |
| fi | |
| - name: Deploy to Vercel | |
| id: deploy | |
| run: | | |
| if [ "${{ github.event_name }}" = "push" ]; then | |
| URL=$(vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }}) | |
| else | |
| URL=$(vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }}) | |
| fi | |
| echo "url=$URL" >> "$GITHUB_OUTPUT" | |
| echo "Deployed: $URL" | |
| - name: Comment preview URL on PR | |
| if: github.event_name == 'pull_request' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const url = "${{ steps.deploy.outputs.url }}"; | |
| github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| body: `Vercel preview deployed: ${url}`, | |
| }); | |