@@ -5,11 +5,6 @@ run-name: Deploy PR Review App - PR #${{ github.event.pull_request.number || git
5
5
on :
6
6
pull_request :
7
7
types : [opened, synchronize, reopened]
8
- push :
9
- branches :
10
- - ' **' # Any branch
11
- - ' !main' # Except main
12
- - ' !master' # Except master
13
8
issue_comment :
14
9
types : [created]
15
10
workflow_dispatch :
@@ -139,9 +134,9 @@ jobs:
139
134
fi
140
135
fi
141
136
142
- # Extract and set PR data
137
+ # Set PR_NUMBER and override APP_NAME with validated PR number
143
138
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
144
- echo "APP_NAME=${{ vars.REVIEW_APP_PREFIX }}-$PR_NUMBER" >> $GITHUB_ENV
139
+ echo "APP_NAME=${{ vars.REVIEW_APP_PREFIX }}-pr- $PR_NUMBER" >> $GITHUB_ENV
145
140
echo "PR_REF=$(echo $PR_DATA | jq -r .headRefName)" >> $GITHUB_OUTPUT
146
141
echo "PR_SHA=$(echo $PR_DATA | jq -r .headRefOid)" >> $GITHUB_ENV
147
142
@@ -178,40 +173,14 @@ jobs:
178
173
exit 0
179
174
fi
180
175
176
+ # Validate supported event types
181
177
if ! [[ "${{ github.event_name }}" == "workflow_dispatch" || \
182
178
"${{ github.event_name }}" == "issue_comment" || \
183
- "${{ github.event_name }}" == "pull_request" || \
184
- "${{ github.event_name }}" == "push" ]]; then
179
+ "${{ github.event_name }}" == "pull_request" ]]; then
185
180
echo "Error: Unsupported event type ${{ github.event_name }}"
186
181
exit 1
187
182
fi
188
183
189
- # Set DO_DEPLOY based on event type and conditions
190
- if [[ "${{ github.event_name }}" == "pull_request" && \
191
- ("${{ github.event.action }}" == "opened" || \
192
- "${{ github.event.action }}" == "synchronize" || \
193
- "${{ github.event.action }}" == "reopened") ]]; then
194
- echo "DO_DEPLOY=true" >> $GITHUB_ENV
195
- elif [[ "${{ github.event_name }}" == "push" ]]; then
196
- echo "DO_DEPLOY=true" >> $GITHUB_ENV
197
- elif [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
198
- echo "DO_DEPLOY=true" >> $GITHUB_ENV
199
- elif [[ "${{ github.event_name }}" == "issue_comment" ]]; then
200
- if [[ "${{ github.event.issue.pull_request }}" ]]; then
201
- # Trim spaces and check for exact command
202
- COMMENT_BODY=$(echo "${{ github.event.comment.body }}" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
203
- if [[ "$COMMENT_BODY" == "/deploy-review-app" ]]; then
204
- echo "DO_DEPLOY=true" >> $GITHUB_ENV
205
- else
206
- echo "DO_DEPLOY=false" >> $GITHUB_ENV
207
- echo "Skipping deployment - comment '$COMMENT_BODY' does not match '/deploy-review-app'"
208
- fi
209
- else
210
- echo "DO_DEPLOY=false" >> $GITHUB_ENV
211
- echo "Skipping deployment for non-PR comment"
212
- fi
213
- fi
214
-
215
184
- name : Setup Control Plane App if Not Existing
216
185
if : env.DO_DEPLOY != 'false' && env.APP_EXISTS == 'false'
217
186
env :
@@ -233,7 +202,11 @@ jobs:
233
202
body: [
234
203
`🏗️ Building Docker image for PR [#${process.env.PR_NUMBER}](${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/pull/${process.env.PR_NUMBER}), commit [${context.sha.substring(0, 7)}](${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/commit/${context.sha})`,
235
204
'',
236
- `📝 [View Build Logs](${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}/job/${context.job})`,
205
+ '🚀 Deploying to Control Plane...',
206
+ '',
207
+ '⏳ Waiting for deployment to be ready...',
208
+ '',
209
+ `📝 [View Build and Deploy Logs](${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}/job/${context.job})`,
237
210
'',
238
211
process.env.CONSOLE_LINK
239
212
].join('\n')
@@ -266,7 +239,7 @@ jobs:
266
239
};
267
240
268
241
const workflowUrl = await getWorkflowUrl(context.runId);
269
- core.exportVariable('WORKFLOW_URL ', workflowUrl);
242
+ core.exportVariable('BUILD_LOGS_URL ', workflowUrl);
270
243
core.exportVariable('CONSOLE_LINK',
271
244
'🎮 [Control Plane Console](' +
272
245
'https://console.cpln.io/console/org/' + process.env.CPLN_ORG + '/gvc/' + process.env.APP_NAME + '/-info)'
@@ -350,21 +323,43 @@ jobs:
350
323
uses : actions/github-script@v7
351
324
with :
352
325
script : |
353
- const deployingMessage = [
354
- '🚀 Deploying to Control Plane...',
355
- '',
356
- '⏳ Waiting for deployment to be ready...',
357
- '',
358
- '📝 [View Deploy Logs](${{ env.WORKFLOW_URL }})',
359
- '',
360
- process.env.CONSOLE_LINK
361
- ].join('\n');
326
+ // Create deployment status for deploying state
327
+ await github.rest.repos.createDeploymentStatus({
328
+ owner: context.repo.owner,
329
+ repo: context.repo.repo,
330
+ deployment_id: ${{ needs.process-deployment.outputs.deployment_id }},
331
+ state: 'in_progress',
332
+ description: 'Deployment in progress',
333
+ log_url: process.env.BUILD_LOGS_URL
334
+ });
335
+
336
+ // Get the current job URL
337
+ const { data: jobs } = await github.rest.actions.listJobsForWorkflowRun({
338
+ owner: context.repo.owner,
339
+ repo: context.repo.repo,
340
+ run_id: context.runId
341
+ });
362
342
343
+ const currentJob = jobs.jobs.find(job => job.name === context.job);
344
+ const currentJobUrl = `${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}/job/${currentJob.id}`;
345
+
346
+ // Update the PR comment to show deployment is in progress
363
347
await github.rest.issues.updateComment({
364
348
owner: context.repo.owner,
365
349
repo: context.repo.repo,
366
350
comment_id: ${{ needs.build.outputs.comment_id }},
367
- body: deployingMessage
351
+ body: [
352
+ `🏗️ Built Docker image for PR [#${process.env.PR_NUMBER}](${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/pull/${process.env.PR_NUMBER}), commit [${process.env.PR_SHA.substring(0, 7)}](${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/commit/${process.env.PR_SHA})`,
353
+ '',
354
+ '🚀 Deploying to Control Plane...',
355
+ '',
356
+ '⏳ Waiting for deployment to be ready...',
357
+ '',
358
+ process.env.CONSOLE_LINK,
359
+ '',
360
+ `📝 [View Build Logs](${process.env.BUILD_LOGS_URL})`,
361
+ `📝 [View Deploy Logs](${currentJobUrl})`
362
+ ].join('\n')
368
363
});
369
364
370
365
- name : Deploy to Control Plane
@@ -410,21 +405,25 @@ jobs:
410
405
'🚀 [Review App for PR #' + prNumber + '](' + appUrl + ')',
411
406
consoleLink,
412
407
'',
413
- '📋 [View Completed Action Build and Deploy Logs](' + workflowUrl + ')'
408
+ '📝 [View Build and Deploy Logs](' + workflowUrl + ')',
409
+ '',
410
+ `📋 [View Completed Build and Deploy Logs](${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}/jobs/${context.job.id})`
414
411
].join('\n');
415
412
416
413
const failureMessage = [
417
414
'❌ Deployment failed for PR #' + prNumber + ', commit ' + '${{ env.PR_SHA }}',
418
415
'',
419
416
consoleLink,
420
417
'',
421
- '📋 [View Deployment Logs with Errors](' + workflowUrl + ')'
418
+ '📝 [View Build and Deploy Logs](' + workflowUrl + ')',
419
+ '',
420
+ `📋 [View Build and Deploy Logs with Errors](${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}/jobs/${context.job.id})`
422
421
].join('\n');
423
422
424
423
// Update the existing comment
425
424
await github.rest.issues.updateComment({
426
425
owner: context.repo.owner,
427
426
repo: context.repo.repo,
428
- comment_id: ${{ steps.create-comment .outputs.comment-id }},
427
+ comment_id: ${{ needs.build .outputs.comment_id }},
429
428
body: isSuccess ? successMessage : failureMessage
430
429
});
0 commit comments