@@ -33,10 +33,10 @@ jobs:
3333 debug :
3434 uses : ./.github/workflows/debug-workflow.yml
3535 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
4040 if : |
4141 (github.event_name == 'pull_request') ||
4242 (github.event_name == 'push') ||
@@ -45,12 +45,13 @@ jobs:
4545 github.event.issue.pull_request &&
4646 contains(github.event.comment.body, '/deploy-review-app'))
4747 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 }}
5455 steps :
5556 # Initial checkout only for pull_request and push events
5657 - name : Checkout code
@@ -157,13 +158,6 @@ jobs:
157158 echo "PR_REF=$(echo $PR_DATA | jq -r .headRefName)" >> $GITHUB_OUTPUT
158159 echo "PR_SHA=$(echo $PR_DATA | jq -r .headRefOid)" >> $GITHUB_ENV
159160
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-
167161 - name : Setup Environment
168162 uses : ./.github/actions/setup-environment
169163 with :
@@ -253,26 +247,6 @@ jobs:
253247 });
254248 core.setOutput('comment-id', result.data.id);
255249
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-
276250 - name : Set Deployment URLs
277251 id : set-urls
278252 if : env.DO_DEPLOY != 'false'
@@ -305,30 +279,6 @@ jobs:
305279 'https://console.cpln.io/console/org/' + process.env.CPLN_ORG + '/gvc/' + process.env.APP_NAME + '/-info)'
306280 );
307281
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-
332282 - name : Initialize GitHub Deployment
333283 if : env.DO_DEPLOY != 'false'
334284 uses : actions/github-script@v7
@@ -359,17 +309,58 @@ jobs:
359309
360310 return deployment.data.id;
361311
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+
362346 - name : Build Docker Image
363- if : env.DO_DEPLOY != 'false'
347+ id : build
364348 uses : ./.github/actions/build-docker-image
365349 with :
366350 app_name : ${{ env.APP_NAME }}
367351 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
370362
371363 - name : Update Status - Deploying
372- if : env.DO_DEPLOY != 'false'
373364 uses : actions/github-script@v7
374365 with :
375366 script : |
@@ -378,7 +369,7 @@ jobs:
378369 '',
379370 '⏳ Waiting for deployment to be ready...',
380371 '',
381- '📝 [View Deploy Logs](' + process. env.WORKFLOW_URL + ' )',
372+ '📝 [View Deploy Logs](${{ env.WORKFLOW_URL }} )',
382373 '',
383374 process.env.CONSOLE_LINK
384375 ].join('\n');
0 commit comments