18
18
PR_NUMBER : ${{ github.event.pull_request.number || github.event.issue.number }}
19
19
20
20
jobs :
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
+
21
36
deploy-to-control-plane-review :
37
+ needs : check-concurrent
22
38
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))
28
45
runs-on : ubuntu-latest
29
46
47
+ permissions :
48
+ contents : read
49
+ deployments : write
50
+ pull-requests : write
51
+
30
52
outputs :
31
53
app_url : ${{ steps.deploy.outputs.app_url }}
32
54
deployment_id : ${{ steps.create-deployment.outputs.deployment_id }}
33
55
34
56
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
+
35
71
- name : Create GitHub Deployment
36
72
id : create-deployment
37
73
uses : actions/github-script@v7
@@ -73,13 +109,37 @@ jobs:
73
109
description: 'Deployment is in progress'
74
110
});
75
111
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 }}
77
125
78
126
- name : Update deployment status (success)
79
127
if : success()
80
128
uses : actions/github-script@v7
81
129
with :
82
130
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
+
83
143
await github.rest.repos.createDeploymentStatus({
84
144
owner: context.repo.owner,
85
145
repo: context.repo.repo,
@@ -94,6 +154,17 @@ jobs:
94
154
uses : actions/github-script@v7
95
155
with :
96
156
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
+
97
168
await github.rest.repos.createDeploymentStatus({
98
169
owner: context.repo.owner,
99
170
repo: context.repo.repo,
0 commit comments