@@ -2,14 +2,12 @@ name: Deploy PR Review App to Control Plane
22
33run-name : Deploy PR Review App - PR # ${{ github.event.pull_request.number || github.event.issue.number || github.event.inputs.pr_number }}
44
5+ 56on :
6- pull_request :
7- types : [opened, synchronize, reopened]
87 push :
9- branches :
10- - ' **' # Any branch
11- - ' !main' # Except main
12- - ' !master' # Except master
8+ branches : [ "master" ]
9+ pull_request :
10+ branches : [ "master" ]
1311 issue_comment :
1412 types : [created]
1513 workflow_dispatch :
@@ -24,6 +22,7 @@ concurrency:
2422 cancel-in-progress : true
2523
2624env :
25+ PREFIX : ${{ vars.REVIEW_APP_PREFIX }}
2726 APP_NAME : ${{ vars.REVIEW_APP_PREFIX }}-pr-${{ github.event.pull_request.number || github.event.issue.number || github.event.inputs.pr_number }}
2827 CPLN_TOKEN : ${{ secrets.CPLN_TOKEN_STAGING }}
2928 CPLN_ORG : ${{ vars.CPLN_ORG_STAGING }}
3534 with :
3635 debug_enabled : false
3736
38- process-deployment :
39- needs : debug
37+ deploy :
4038 if : |
4139 (github.event_name == 'pull_request') ||
4240 (github.event_name == 'push') ||
4543 github.event.issue.pull_request &&
4644 contains(github.event.comment.body, '/deploy-review-app'))
4745 runs-on : ubuntu-latest
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 }}
5546 steps :
5647 # Initial checkout only for pull_request and push events
5748 - name : Checkout code
7061 fetch-depth : 0
7162
7263 - name : Validate Required Secrets and Variables
73- uses : ./.github/actions/validate-required-vars
64+ shell : bash
65+ run : |
66+ missing=()
67+
68+ # Check required secrets
69+ if [ -z "$CPLN_TOKEN" ]; then
70+ missing+=("Secret: CPLN_TOKEN_STAGING")
71+ fi
72+
73+ # Check required variables
74+ if [ -z "$CPLN_ORG" ]; then
75+ missing+=("Variable: CPLN_ORG_STAGING")
76+ fi
77+
78+ if [ -z "$PREFIX" ]; then
79+ missing+=("Variable: REVIEW_APP_PREFIX")
80+ fi
81+
82+ if [ ${#missing[@]} -ne 0 ]; then
83+ echo "Required secrets/variables are not set: ${missing[*]}"
84+ exit 1
85+ fi
7486
7587 - name : Get PR HEAD Ref
7688 id : getRef
@@ -288,33 +300,12 @@ jobs:
288300
289301 return deployment.data.id;
290302
291- build :
292- needs : process-deployment
293- if : needs.process-deployment.outputs.do_deploy != 'false'
294- runs-on : ubuntu-latest
295- outputs :
296- image_tag : ${{ steps.build.outputs.image_tag }}
297- comment_id : ${{ needs.process-deployment.outputs.comment_id }}
298- pr_number : ${{ needs.process-deployment.outputs.pr_number }}
299- do_deploy : ${{ needs.process-deployment.outputs.do_deploy }}
300- steps :
301- - name : Checkout code
302- uses : actions/checkout@v4
303- with :
304- ref : ${{ needs.process-deployment.outputs.pr_ref }}
305- 306- - name : Setup Environment
307- uses : ./.github/actions/setup-environment
308- with :
309- token : ${{ secrets.CPLN_TOKEN_STAGING }}
310- org : ${{ vars.CPLN_ORG_STAGING }}
311- 312303 - name : Update Status - Building
313304 uses : actions/github-script@v7
314305 with :
315306 script : |
316307 const buildingMessage = [
317- '🏗️ Building Docker image for PR #${{ needs.process-deployment.outputs.pr_number }}, commit ${{ needs.process-deployment.outputs.pr_sha }}',
308+ '🏗️ Building Docker image for PR #${{ env.PR_NUMBER }}, commit ${{ env.PR_SHA }}',
318309 '',
319310 '📝 [View Build Logs](${{ env.WORKFLOW_URL }})',
320311 '',
@@ -324,7 +315,7 @@ jobs:
324315 await github.rest.issues.updateComment({
325316 owner: context.repo.owner,
326317 repo: context.repo.repo,
327- comment_id: ${{ needs.process-deployment .outputs.comment_id }},
318+ comment_id: ${{ steps.create-comment .outputs.comment-id }},
328319 body: buildingMessage
329320 });
330321
@@ -334,22 +325,8 @@ jobs:
334325 with :
335326 app_name : ${{ env.APP_NAME }}
336327 org : ${{ vars.CPLN_ORG_STAGING }}
337- commit : ${{ needs.process-deployment.outputs.pr_sha }}
338- PR_NUMBER : ${{ needs.process-deployment.outputs.pr_number }}
339- 340- deploy :
341- needs : build
342- if : needs.build.outputs.do_deploy != 'false'
343- runs-on : ubuntu-latest
344- steps :
345- - name : Checkout code
346- uses : actions/checkout@v4
347- 348- - name : Setup Environment
349- uses : ./.github/actions/setup-environment
350- with :
351- token : ${{ secrets.CPLN_TOKEN_STAGING }}
352- org : ${{ vars.CPLN_ORG_STAGING }}
328+ commit : ${{ env.PR_SHA }}
329+ PR_NUMBER : ${{ env.PR_NUMBER }}
353330
354331 - name : Update Status - Deploying
355332 uses : actions/github-script@v7
@@ -374,22 +351,19 @@ jobs:
374351
375352 - name : Deploy to Control Plane
376353 if : env.DO_DEPLOY != 'false'
377- uses : ./.github/actions/deploy-to-control-plane
378- with :
379- app_name : ${{ env.APP_NAME }}
380- org : ${{ vars.CPLN_ORG_STAGING }}
381- github_token : ${{ secrets.GITHUB_TOKEN }}
382- wait_timeout : ${{ vars.WAIT_TIMEOUT || 900 }}
383- cpln_token : ${{ secrets.CPLN_TOKEN_STAGING }}
384- pr_number : ${{ env.PR_NUMBER }}
354+ run : cpflow deploy-image -a ${{ env.APP_NAME }} --run-release-phase --org ${{ vars.CPLN_ORG_STAGING }} --verbose
355+ 356+ - name : Retrieve App URL
357+ id : workload
358+ run : echo "WORKLOAD_URL=$(cpln workload get rails --gvc ${{ env.APP_NAME }} | tee | grep -oP 'https://[^[:space:]]*\.cpln\.app(?=\s|$)' | head -n1)" >> "$GITHUB_OUTPUT"
385359
386360 - name : Update Status - Deployment Complete
387361 if : env.DO_DEPLOY != 'false'
388362 uses : actions/github-script@v7
389363 with :
390364 script : |
391365 const prNumber = process.env.PR_NUMBER;
392- const appUrl = process.env.APP_URL ;
366+ const appUrl = '${{ steps.workload.outputs.WORKLOAD_URL }}' ;
393367 const workflowUrl = process.env.WORKFLOW_URL;
394368 const isSuccess = '${{ job.status }}' === 'success';
395369
0 commit comments