Merge pull request #108 from konard/issue-102-99338d5796a5 #163
This file contains hidden or 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 to Vercel | |
| on: | |
| pull_request: | |
| push: | |
| branches: [main] | |
| jobs: | |
| deploy: | |
| name: deploy | |
| runs-on: ubuntu-latest | |
| env: | |
| VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} | |
| steps: | |
| - name: Check Vercel token | |
| id: check | |
| run: | | |
| if [ -z "$VERCEL_TOKEN" ]; then | |
| echo "available=false" >> "$GITHUB_OUTPUT" | |
| echo "⚠️ VERCEL_TOKEN is not configured — skipping deployment" | |
| else | |
| echo "available=true" >> "$GITHUB_OUTPUT" | |
| fi | |
| - uses: actions/checkout@v4 | |
| if: steps.check.outputs.available == 'true' | |
| - uses: actions/setup-node@v4 | |
| if: steps.check.outputs.available == 'true' | |
| with: | |
| node-version: "20" | |
| - name: Install Vercel CLI | |
| if: steps.check.outputs.available == 'true' | |
| run: npm install --global vercel@latest | |
| - name: Pull Vercel environment | |
| if: steps.check.outputs.available == 'true' | |
| run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }} | |
| - name: Build project artifacts | |
| if: steps.check.outputs.available == 'true' | |
| run: vercel build --token=${{ secrets.VERCEL_TOKEN }} | |
| - name: Deploy to Vercel (preview) | |
| if: steps.check.outputs.available == 'true' | |
| id: deploy | |
| run: | | |
| url=$(vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }}) | |
| echo "url=$url" >> "$GITHUB_OUTPUT" | |
| - name: Comment preview URL on PR | |
| if: steps.check.outputs.available == 'true' && github.event_name == 'pull_request' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| github.rest.issues.createComment({ | |
| issue_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body: `🚀 Preview deployed: ${{ steps.deploy.outputs.url }}` | |
| }) |