@@ -33,10 +33,10 @@ jobs:
33
33
debug :
34
34
uses : ./.github/workflows/debug-workflow.yml
35
35
with :
36
- debug_enabled : false # Will still run if vars.DEBUG_WORKFLOW is true
37
-
38
- Process-Deployment-Command :
39
- needs : debug # Add this to ensure debug runs first
36
+ debug_enabled : false
37
+
38
+ process-deployment :
39
+ needs : debug
40
40
if : |
41
41
(github.event_name == 'pull_request') ||
42
42
(github.event_name == 'push') ||
@@ -45,12 +45,13 @@ jobs:
45
45
github.event.issue.pull_request &&
46
46
contains(github.event.comment.body, '/deploy-review-app'))
47
47
runs-on : ubuntu-latest
48
- permissions :
49
- contents : read
50
- deployments : write
51
- pull-requests : write
52
- issues : write
53
-
48
+ outputs :
49
+ pr_number : ${{ env.PR_NUMBER }}
50
+ pr_sha : ${{ env.PR_SHA }}
51
+ pr_ref : ${{ steps.getRef.outputs.PR_REF }}
52
+ do_deploy : ${{ env.DO_DEPLOY }}
53
+ comment_id : ${{ steps.create-comment.outputs.comment-id }}
54
+ deployment_id : ${{ steps.init-deployment.outputs.result }}
54
55
steps :
55
56
# Initial checkout only for pull_request and push events
56
57
- name : Checkout code
@@ -157,13 +158,6 @@ jobs:
157
158
echo "PR_REF=$(echo $PR_DATA | jq -r .headRefName)" >> $GITHUB_OUTPUT
158
159
echo "PR_SHA=$(echo $PR_DATA | jq -r .headRefOid)" >> $GITHUB_ENV
159
160
160
- - name : Checkout PR code
161
- if : github.event_name == 'workflow_dispatch' || github.event_name == 'issue_comment'
162
- uses : actions/checkout@v4
163
- with :
164
- fetch-depth : 0
165
- ref : ${{ steps.getRef.outputs.PR_SHA }}
166
-
167
161
- name : Setup Environment
168
162
uses : ./.github/actions/setup-environment
169
163
with :
@@ -253,26 +247,6 @@ jobs:
253
247
});
254
248
core.setOutput('comment-id', result.data.id);
255
249
256
- - name : Update Comment - Building
257
- if : env.DO_DEPLOY != 'false'
258
- uses : actions/github-script@v7
259
- with :
260
- script : |
261
- const buildingMessage = [
262
- `🏗️ Building Docker image for PR #${process.env.PR_NUMBER}, commit ${process.env.PR_SHA}`,
263
- '',
264
- `📝 [View Build Logs](${process.env.WORKFLOW_URL})`,
265
- '',
266
- process.env.CONSOLE_LINK
267
- ].join('\n');
268
-
269
- await github.rest.issues.updateComment({
270
- owner: context.repo.owner,
271
- repo: context.repo.repo,
272
- comment_id: ${{ steps.create-comment.outputs.comment-id }},
273
- body: buildingMessage
274
- });
275
-
276
250
- name : Set Deployment URLs
277
251
id : set-urls
278
252
if : env.DO_DEPLOY != 'false'
@@ -305,30 +279,6 @@ jobs:
305
279
'https://console.cpln.io/console/org/' + process.env.CPLN_ORG + '/gvc/' + process.env.APP_NAME + '/-info)'
306
280
);
307
281
308
- - name : Update Status - Building
309
- if : env.DO_DEPLOY != 'false'
310
- uses : actions/github-script@v7
311
- with :
312
- script : |
313
- const buildingMessage = [
314
- '🏗️ Building Docker image for PR #' + process.env.PR_NUMBER + ', commit ' + '${{ env.PR_SHA }}',
315
- '',
316
- '📝 [View Build Logs](' + process.env.WORKFLOW_URL + ')',
317
- '',
318
- process.env.CONSOLE_LINK
319
- ].join('\n');
320
-
321
- await github.rest.issues.updateComment({
322
- owner: context.repo.owner,
323
- repo: context.repo.repo,
324
- comment_id: ${{ steps.create-comment.outputs.comment-id }},
325
- body: buildingMessage
326
- });
327
-
328
- - name : Checkout PR Branch
329
- if : env.DO_DEPLOY != 'false'
330
- run : git checkout ${{ steps.getRef.outputs.PR_REF }}
331
-
332
282
- name : Initialize GitHub Deployment
333
283
if : env.DO_DEPLOY != 'false'
334
284
uses : actions/github-script@v7
@@ -359,17 +309,58 @@ jobs:
359
309
360
310
return deployment.data.id;
361
311
312
+ build :
313
+ needs : process-deployment
314
+ if : needs.process-deployment.outputs.do_deploy != 'false'
315
+ runs-on : ubuntu-latest
316
+ outputs :
317
+ image_tag : ${{ steps.build.outputs.image_tag }}
318
+ comment_id : ${{ needs.process-deployment.outputs.comment_id }}
319
+ pr_number : ${{ needs.process-deployment.outputs.pr_number }}
320
+ do_deploy : ${{ needs.process-deployment.outputs.do_deploy }}
321
+ steps :
322
+ - name : Checkout code
323
+ uses : actions/checkout@v4
324
+ with :
325
+ ref : ${{ needs.process-deployment.outputs.pr_ref }}
326
+
327
+ - name : Update Status - Building
328
+ uses : actions/github-script@v7
329
+ with :
330
+ script : |
331
+ const buildingMessage = [
332
+ '🏗️ Building Docker image for PR #${{ needs.process-deployment.outputs.pr_number }}, commit ${{ needs.process-deployment.outputs.pr_sha }}',
333
+ '',
334
+ '📝 [View Build Logs](${{ env.WORKFLOW_URL }})',
335
+ '',
336
+ process.env.CONSOLE_LINK
337
+ ].join('\n');
338
+
339
+ await github.rest.issues.updateComment({
340
+ owner: context.repo.owner,
341
+ repo: context.repo.repo,
342
+ comment_id: ${{ needs.process-deployment.outputs.comment_id }},
343
+ body: buildingMessage
344
+ });
345
+
362
346
- name : Build Docker Image
363
- if : env.DO_DEPLOY != 'false'
347
+ id : build
364
348
uses : ./.github/actions/build-docker-image
365
349
with :
366
350
app_name : ${{ env.APP_NAME }}
367
351
org : ${{ vars.CPLN_ORG_STAGING }}
368
- commit : ${{ env.PR_SHA }}
369
- PR_NUMBER : ${{ env.PR_NUMBER }}
352
+ commit : ${{ needs.process-deployment.outputs.pr_sha }}
353
+ PR_NUMBER : ${{ needs.process-deployment.outputs.pr_number }}
354
+
355
+ deploy :
356
+ needs : build
357
+ if : needs.build.outputs.do_deploy != 'false'
358
+ runs-on : ubuntu-latest
359
+ steps :
360
+ - name : Checkout code
361
+ uses : actions/checkout@v4
370
362
371
363
- name : Update Status - Deploying
372
- if : env.DO_DEPLOY != 'false'
373
364
uses : actions/github-script@v7
374
365
with :
375
366
script : |
@@ -378,7 +369,7 @@ jobs:
378
369
'',
379
370
'⏳ Waiting for deployment to be ready...',
380
371
'',
381
- '📝 [View Deploy Logs](' + process. env.WORKFLOW_URL + ' )',
372
+ '📝 [View Deploy Logs](${{ env.WORKFLOW_URL }} )',
382
373
'',
383
374
process.env.CONSOLE_LINK
384
375
].join('\n');
0 commit comments