@@ -2,14 +2,12 @@ name: Deploy PR Review App to Control Plane
2
2
3
3
run-name : Deploy PR Review App - PR # ${{ github.event.pull_request.number || github.event.issue.number || github.event.inputs.pr_number }}
4
4
5
+
5
6
on :
6
- pull_request :
7
- types : [opened, synchronize, reopened]
8
7
push :
9
- branches :
10
- - ' **' # Any branch
11
- - ' !main' # Except main
12
- - ' !master' # Except master
8
+ branches : [ "master" ]
9
+ pull_request :
10
+ branches : [ "master" ]
13
11
issue_comment :
14
12
types : [created]
15
13
workflow_dispatch :
@@ -24,6 +22,7 @@ concurrency:
24
22
cancel-in-progress : true
25
23
26
24
env :
25
+ PREFIX : ${{ vars.REVIEW_APP_PREFIX }}
27
26
APP_NAME : ${{ vars.REVIEW_APP_PREFIX }}-pr-${{ github.event.pull_request.number || github.event.issue.number || github.event.inputs.pr_number }}
28
27
CPLN_TOKEN : ${{ secrets.CPLN_TOKEN_STAGING }}
29
28
CPLN_ORG : ${{ vars.CPLN_ORG_STAGING }}
35
34
with :
36
35
debug_enabled : false
37
36
38
- process-deployment :
39
- needs : debug
37
+ deploy :
40
38
if : |
41
39
(github.event_name == 'pull_request') ||
42
40
(github.event_name == 'push') ||
45
43
github.event.issue.pull_request &&
46
44
contains(github.event.comment.body, '/deploy-review-app'))
47
45
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 }}
55
46
steps :
56
47
# Initial checkout only for pull_request and push events
57
48
- name : Checkout code
70
61
fetch-depth : 0
71
62
72
63
- 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
74
86
75
87
- name : Get PR HEAD Ref
76
88
id : getRef
@@ -288,33 +300,12 @@ jobs:
288
300
289
301
return deployment.data.id;
290
302
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
-
312
303
- name : Update Status - Building
313
304
uses : actions/github-script@v7
314
305
with :
315
306
script : |
316
307
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 }}',
318
309
'',
319
310
'📝 [View Build Logs](${{ env.WORKFLOW_URL }})',
320
311
'',
@@ -324,7 +315,7 @@ jobs:
324
315
await github.rest.issues.updateComment({
325
316
owner: context.repo.owner,
326
317
repo: context.repo.repo,
327
- comment_id: ${{ needs.process-deployment .outputs.comment_id }},
318
+ comment_id: ${{ steps.create-comment .outputs.comment-id }},
328
319
body: buildingMessage
329
320
});
330
321
@@ -334,22 +325,8 @@ jobs:
334
325
with :
335
326
app_name : ${{ env.APP_NAME }}
336
327
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 }}
353
330
354
331
- name : Update Status - Deploying
355
332
uses : actions/github-script@v7
@@ -374,22 +351,19 @@ jobs:
374
351
375
352
- name : Deploy to Control Plane
376
353
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"
385
359
386
360
- name : Update Status - Deployment Complete
387
361
if : env.DO_DEPLOY != 'false'
388
362
uses : actions/github-script@v7
389
363
with :
390
364
script : |
391
365
const prNumber = process.env.PR_NUMBER;
392
- const appUrl = process.env.APP_URL ;
366
+ const appUrl = '${{ steps.workload.outputs.WORKLOAD_URL }}' ;
393
367
const workflowUrl = process.env.WORKFLOW_URL;
394
368
const isSuccess = '${{ job.status }}' === 'success';
395
369
0 commit comments