1818 PR_NUMBER : ${{ github.event.pull_request.number || github.event.issue.number }}
1919
2020jobs :
21+ check-concurrent :
22+ runs-on : ubuntu-latest
23+ outputs :
24+ cancelled : ${{ steps.check.outputs.cancelled }}
25+ steps :
26+ - name : Check for concurrent deployment
27+ id : check
28+ run : |
29+ if [ "${{ github.run_attempt }}" != "1" ]; then
30+ echo "⚠️ Cancelling previous deployment due to new code push..."
31+ echo "cancelled=true" >> $GITHUB_OUTPUT
32+ else
33+ echo "cancelled=false" >> $GITHUB_OUTPUT
34+ fi
35+
2136 deploy-to-control-plane-review :
37+ needs : check-concurrent
2238 if : |
23- github.event_name == 'workflow_dispatch' ||
24- github.event_name == 'pull_request' ||
25- (github.event_name == 'issue_comment' &&
26- github.event.comment.body == '/deploy-review-app' &&
27- github.event.issue.pull_request)
39+ needs.check-concurrent.outputs.cancelled != 'true' &&
40+ (github.event_name == 'workflow_dispatch' ||
41+ github.event_name == 'pull_request' ||
42+ (github.event_name == 'issue_comment' &&
43+ github.event.comment.body == '/deploy-review-app' &&
44+ github.event.issue.pull_request))
2845 runs-on : ubuntu-latest
2946
47+ permissions :
48+ contents : read
49+ deployments : write
50+ pull-requests : write
51+
3052 outputs :
3153 app_url : ${{ steps.deploy.outputs.app_url }}
3254 deployment_id : ${{ steps.create-deployment.outputs.deployment_id }}
3355
3456 steps :
57+ - name : Notify deployment start
58+ uses : actions/github-script@v7
59+ with :
60+ script : |
61+ const message = `🚀 Starting new deployment for commit: ${context.sha.substring(0, 7)}
62+ ${context.payload.commits ? `\nChanges: ${context.payload.commits[0].message}` : ''}`;
63+
64+ await github.rest.issues.createComment({
65+ issue_number: context.issue.number || context.payload.pull_request.number,
66+ owner: context.repo.owner,
67+ repo: context.repo.repo,
68+ body: message
69+ });
70+
3571 - name : Create GitHub Deployment
3672 id : create-deployment
3773 uses : actions/github-script@v7
@@ -73,13 +109,37 @@ jobs:
73109 description: 'Deployment is in progress'
74110 });
75111
76- # ... rest of your existing steps ...
112+ - name : Configure app name
113+ id : app-config
114+ run : |
115+ APP_NAME="qa-react-webpack-rails-tutorial-pr-${{ env.PR_NUMBER }}"
116+ echo "APP_NAME=$APP_NAME" >> $GITHUB_ENV
117+ echo "app_name=$APP_NAME" >> $GITHUB_OUTPUT
118+
119+ - name : Deploy to Control Plane
120+ id : deploy
121+ uses : ./.github/actions/deploy-to-control-plane
122+ with :
123+ app_name : ${{ env.APP_NAME }}
124+ org : ${{ env.CPLN_ORG }}
77125
78126 - name : Update deployment status (success)
79127 if : success()
80128 uses : actions/github-script@v7
81129 with :
82130 script : |
131+ const message = `✅ Deployment successful!
132+ Environment: review-app
133+ Commit: ${context.sha.substring(0, 7)}
134+ URL: ${{ steps.deploy.outputs.app_url }}`;
135+
136+ await github.rest.issues.createComment({
137+ issue_number: context.issue.number || context.payload.pull_request.number,
138+ owner: context.repo.owner,
139+ repo: context.repo.repo,
140+ body: message
141+ });
142+
83143 await github.rest.repos.createDeploymentStatus({
84144 owner: context.repo.owner,
85145 repo: context.repo.repo,
@@ -94,6 +154,17 @@ jobs:
94154 uses : actions/github-script@v7
95155 with :
96156 script : |
157+ const message = `❌ Deployment failed
158+ Commit: ${context.sha.substring(0, 7)}
159+ Please check the [workflow logs](${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}) for details.`;
160+
161+ await github.rest.issues.createComment({
162+ issue_number: context.issue.number || context.payload.pull_request.number,
163+ owner: context.repo.owner,
164+ repo: context.repo.repo,
165+ body: message
166+ });
167+
97168 await github.rest.repos.createDeploymentStatus({
98169 owner: context.repo.owner,
99170 repo: context.repo.repo,
0 commit comments