@@ -87,32 +87,75 @@ jobs:
8787 path : coverage/
8888 retention-days : 30
8989
90- # This job will only run after build-and-test succeeds
90+ # Deploy preview for pull requests
91+ deploy-preview :
92+ name : Deploy Preview to Vercel
93+ runs-on : ubuntu-latest
94+ needs : build-and-test
95+ if : github.event_name == 'pull_request'
96+
97+ steps :
98+ - name : Checkout repository
99+ uses : actions/checkout@v4
100+
101+ - name : Deploy to Vercel (Preview)
102+ uses : amondnet/vercel-action@v25
103+ id : vercel-preview
104+ with :
105+ vercel-token : ${{ secrets.VERCEL_TOKEN }}
106+ vercel-project-id : ${{ secrets.VERCEL_PROJECT_ID }}
107+ vercel-org-id : ${{ secrets.VERCEL_ORG_ID }}
108+ github-comment : true
109+ env :
110+ VERCEL_TOKEN : ${{ secrets.VERCEL_TOKEN }}
111+
112+ - name : Comment preview URL on PR
113+ uses : actions/github-script@v7
114+ if : github.event_name == 'pull_request'
115+ with :
116+ script : |
117+ const previewUrl = '${{ steps.vercel-preview.outputs.preview-url }}';
118+ github.rest.issues.createComment({
119+ issue_number: context.issue.number,
120+ owner: context.repo.owner,
121+ repo: context.repo.repo,
122+ body: `✅ Tests passed! Preview deployment ready:\n\n🔗 ${previewUrl}`
123+ });
124+
125+ # This job will only run after build-and-test succeeds on main branch
91126 deployment-ready :
92- name : Deployment Gate
127+ name : Production Deployment Gate
93128 runs-on : ubuntu-latest
94129 needs : build-and-test
95- if : github.ref == 'refs/heads/main'
130+ if : github.ref == 'refs/heads/main' && github.event_name == 'push'
96131
97132 steps :
98133 - name : All tests passed
99- run : echo "✅ All tests passed. Deployment can proceed."
100- deploy-to-vercel :
101- name : Deploy to Vercel
134+ run : echo "✅ All tests passed. Production deployment can proceed."
135+
136+ # Deploy to production when PR is merged to main
137+ deploy-production :
138+ name : Deploy to Production (Vercel)
102139 runs-on : ubuntu-latest
103140 needs : deployment-ready
104- if : github.ref == 'refs/heads/main' && success()
141+ if : github.ref == 'refs/heads/main' && github.event_name == 'push' && success()
105142
106143 steps :
107144 - name : Checkout repository
108145 uses : actions/checkout@v4
109146
110- - name : Deploy to Vercel
147+ - name : Deploy to Vercel (Production)
111148 uses : amondnet/vercel-action@v25
149+ id : vercel-production
112150 with :
113151 vercel-token : ${{ secrets.VERCEL_TOKEN }}
114152 vercel-args : ' --prod'
115153 vercel-project-id : ${{ secrets.VERCEL_PROJECT_ID }}
116154 vercel-org-id : ${{ secrets.VERCEL_ORG_ID }}
117155 env :
118156 VERCEL_TOKEN : ${{ secrets.VERCEL_TOKEN }}
157+
158+ - name : Log production deployment
159+ run : |
160+ echo "🚀 Production deployment completed"
161+ echo "Production URL: ${{ steps.vercel-production.outputs.preview-url }}"
0 commit comments