Skip to content

Commit 15691e7

Browse files
authored
Fix Github Action / Control Plane Pipeline (#626)
Fix whatever was broken
1 parent 586dac3 commit 15691e7

File tree

6 files changed

+62
-205
lines changed

6 files changed

+62
-205
lines changed

.github/actions/deploy-to-control-plane/action.yml

-47
This file was deleted.

.github/actions/deploy-to-control-plane/scripts/deploy.sh

-64
This file was deleted.

.github/actions/setup-environment/action.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ runs:
2424
run: |
2525
sudo npm install -g @controlplane/[email protected]
2626
cpln --version
27-
gem install cpflow -v 4.1.0
27+
gem install cpflow -v 4.1.1
2828
cpflow --version
2929
3030
- name: Setup Control Plane Profile

.github/actions/validate-required-vars/action.yml

-28
This file was deleted.

.github/workflows/delete-review-app.yml

+23-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ permissions:
1919
issues: write
2020

2121
env:
22+
PREFIX: ${{ vars.REVIEW_APP_PREFIX }}
2223
CPLN_ORG: ${{ vars.CPLN_ORG_STAGING }}
2324
CPLN_TOKEN: ${{ secrets.CPLN_TOKEN_STAGING }}
2425
APP_NAME: ${{ vars.REVIEW_APP_PREFIX }}-pr-${{ github.event.pull_request.number || github.event.issue.number || inputs.pr_number }}
@@ -43,7 +44,28 @@ jobs:
4344
- uses: actions/checkout@v4
4445

4546
- name: Validate Required Secrets and Variables
46-
uses: ./.github/actions/validate-required-vars
47+
shell: bash
48+
run: |
49+
missing=()
50+
51+
# Check required secrets
52+
if [ -z "$CPLN_TOKEN" ]; then
53+
missing+=("Secret: CPLN_TOKEN_STAGING")
54+
fi
55+
56+
# Check required variables
57+
if [ -z "$CPLN_ORG" ]; then
58+
missing+=("Variable: CPLN_ORG_STAGING")
59+
fi
60+
61+
if [ -z "$"PREFIX" }} ]; then
62+
missing+=("Variable: REVIEW_APP_PREFIX")
63+
fi
64+
65+
if [ ${#missing[@]} -ne 0 ]; then
66+
echo "Required secrets/variables are not set: ${missing[*]}"
67+
exit 1
68+
fi
4769
4870
- name: Setup Environment
4971
uses: ./.github/actions/setup-environment

.github/workflows/deploy-to-control-plane-review-app.yml

+38-64
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@ name: Deploy PR Review App to Control Plane
22

33
run-name: Deploy PR Review App - PR #${{ github.event.pull_request.number || github.event.issue.number || github.event.inputs.pr_number }}
44

5+
56
on:
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

2624
env:
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 }}
@@ -35,8 +34,7 @@ jobs:
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') ||
@@ -45,13 +43,6 @@ jobs:
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
@@ -70,7 +61,28 @@ jobs:
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

Comments
 (0)