|
| 1 | +name: Deployment |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: |
| 6 | + - Test |
| 7 | + types: |
| 8 | + - completed |
| 9 | + |
| 10 | +jobs: |
| 11 | + deploy-preview: |
| 12 | + name: Deploy Preview to Vercel |
| 13 | + runs-on: ubuntu-latest |
| 14 | + if: >- |
| 15 | + github.event.workflow_run.conclusion == 'success' && |
| 16 | + github.event.workflow_run.event == 'pull_request' |
| 17 | +
|
| 18 | + steps: |
| 19 | + - name: Checkout repository |
| 20 | + uses: actions/checkout@v4 |
| 21 | + with: |
| 22 | + ref: ${{ github.event.workflow_run.head_sha }} |
| 23 | + |
| 24 | + - name: Deploy to Vercel (Preview) |
| 25 | + uses: amondnet/vercel-action@v41.1.4 |
| 26 | + id: vercel-preview |
| 27 | + with: |
| 28 | + vercel-token: ${{ secrets.VERCEL_TOKEN }} |
| 29 | + vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }} |
| 30 | + vercel-org-id: ${{ secrets.VERCEL_ORG_ID }} |
| 31 | + github-comment: true |
| 32 | + env: |
| 33 | + VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} |
| 34 | + |
| 35 | + - name: Comment preview URL on PR |
| 36 | + uses: actions/github-script@v8 |
| 37 | + with: |
| 38 | + script: | |
| 39 | + const previewUrl = '${{ steps.vercel-preview.outputs.preview-url }}'; |
| 40 | + const pr = context.payload.workflow_run.pull_requests && context.payload.workflow_run.pull_requests[0]; |
| 41 | + if (!pr) { |
| 42 | + core.warning('No pull request metadata available; skipping preview comment.'); |
| 43 | + return; |
| 44 | + } |
| 45 | + await github.rest.issues.createComment({ |
| 46 | + issue_number: pr.number, |
| 47 | + owner: context.repo.owner, |
| 48 | + repo: context.repo.repo, |
| 49 | + body: `✅ Tests passed! Preview deployment ready:\n\n🔗 ${previewUrl}` |
| 50 | + }); |
| 51 | +
|
| 52 | + deploy-production: |
| 53 | + name: Deploy to Production (Vercel) |
| 54 | + runs-on: ubuntu-latest |
| 55 | + if: >- |
| 56 | + github.event.workflow_run.conclusion == 'success' && |
| 57 | + github.event.workflow_run.event == 'push' && |
| 58 | + github.event.workflow_run.head_branch == 'main' |
| 59 | +
|
| 60 | + steps: |
| 61 | + - name: Checkout repository |
| 62 | + uses: actions/checkout@v4 |
| 63 | + with: |
| 64 | + ref: ${{ github.event.workflow_run.head_sha }} |
| 65 | + |
| 66 | + - name: Deploy to Vercel (Production) |
| 67 | + uses: amondnet/vercel-action@v41.1.4 |
| 68 | + id: vercel-production |
| 69 | + with: |
| 70 | + vercel-token: ${{ secrets.VERCEL_TOKEN }} |
| 71 | + vercel-args: '--prod' |
| 72 | + vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }} |
| 73 | + vercel-org-id: ${{ secrets.VERCEL_ORG_ID }} |
| 74 | + env: |
| 75 | + VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} |
| 76 | + |
| 77 | + - name: Log production deployment |
| 78 | + run: | |
| 79 | + echo "🚀 Production deployment completed" |
| 80 | + echo "Production URL: ${{ steps.vercel-production.outputs.preview-url }}" |
0 commit comments