Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Github Action / Control Plane Pipeline #626

Merged
merged 19 commits into from
Mar 19, 2025
Merged
47 changes: 0 additions & 47 deletions .github/actions/deploy-to-control-plane/action.yml

This file was deleted.

64 changes: 0 additions & 64 deletions .github/actions/deploy-to-control-plane/scripts/deploy.sh

This file was deleted.

2 changes: 1 addition & 1 deletion .github/actions/setup-environment/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ runs:
run: |
sudo npm install -g @controlplane/[email protected]
cpln --version
gem install cpflow -v 4.1.0
gem install cpflow -v 4.1.1
cpflow --version

- name: Setup Control Plane Profile
Expand Down
28 changes: 0 additions & 28 deletions .github/actions/validate-required-vars/action.yml

This file was deleted.

24 changes: 23 additions & 1 deletion .github/workflows/delete-review-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ permissions:
issues: write

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

- name: Validate Required Secrets and Variables
uses: ./.github/actions/validate-required-vars
shell: bash
run: |
missing=()

# Check required secrets
if [ -z "$CPLN_TOKEN" ]; then
missing+=("Secret: CPLN_TOKEN_STAGING")
fi

# Check required variables
if [ -z "$CPLN_ORG" ]; then
missing+=("Variable: CPLN_ORG_STAGING")
fi

if [ -z "$"PREFIX" }} ]; then
missing+=("Variable: REVIEW_APP_PREFIX")
fi

if [ ${#missing[@]} -ne 0 ]; then
echo "Required secrets/variables are not set: ${missing[*]}"
exit 1
fi

Comment on lines 46 to 69
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Validation Script: Critical Syntax Issue in Variable Check.
In the validation step (line 61), the condition

if [ -z "$"PREFIX" }} ]; then

is syntactically incorrect. Please change it to:

if [ -z "$PREFIX" ]; then

to correctly validate if PREFIX is set.

🧰 Tools
🪛 YAMLlint (1.35.1)

[error] 50-50: trailing spaces

(trailing-spaces)


[error] 55-55: trailing spaces

(trailing-spaces)


[error] 64-64: trailing spaces

(trailing-spaces)


[error] 68-68: trailing spaces

(trailing-spaces)

- name: Setup Environment
uses: ./.github/actions/setup-environment
Expand Down
102 changes: 38 additions & 64 deletions .github/workflows/deploy-to-control-plane-review-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ name: Deploy PR Review App to Control Plane

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


on:
pull_request:
types: [opened, synchronize, reopened]
push:
branches:
- '**' # Any branch
- '!main' # Except main
- '!master' # Except master
branches: [ "master" ]
pull_request:
branches: [ "master" ]
issue_comment:
types: [created]
workflow_dispatch:
Expand All @@ -24,6 +22,7 @@ concurrency:
cancel-in-progress: true

env:
PREFIX: ${{ vars.REVIEW_APP_PREFIX }}
APP_NAME: ${{ vars.REVIEW_APP_PREFIX }}-pr-${{ github.event.pull_request.number || github.event.issue.number || github.event.inputs.pr_number }}
CPLN_TOKEN: ${{ secrets.CPLN_TOKEN_STAGING }}
CPLN_ORG: ${{ vars.CPLN_ORG_STAGING }}
Expand All @@ -35,8 +34,7 @@ jobs:
with:
debug_enabled: false

process-deployment:
needs: debug
deploy:
if: |
(github.event_name == 'pull_request') ||
(github.event_name == 'push') ||
Expand All @@ -45,13 +43,6 @@ jobs:
github.event.issue.pull_request &&
contains(github.event.comment.body, '/deploy-review-app'))
runs-on: ubuntu-latest
outputs:
pr_number: ${{ env.PR_NUMBER }}
pr_sha: ${{ env.PR_SHA }}
pr_ref: ${{ steps.getRef.outputs.PR_REF }}
do_deploy: ${{ env.DO_DEPLOY }}
comment_id: ${{ steps.create-comment.outputs.comment-id }}
deployment_id: ${{ steps.init-deployment.outputs.result }}
steps:
# Initial checkout only for pull_request and push events
- name: Checkout code
Expand All @@ -70,7 +61,28 @@ jobs:
fetch-depth: 0

- name: Validate Required Secrets and Variables
uses: ./.github/actions/validate-required-vars
shell: bash
run: |
missing=()

# Check required secrets
if [ -z "$CPLN_TOKEN" ]; then
missing+=("Secret: CPLN_TOKEN_STAGING")
fi

# Check required variables
if [ -z "$CPLN_ORG" ]; then
missing+=("Variable: CPLN_ORG_STAGING")
fi

if [ -z "$PREFIX" ]; then
missing+=("Variable: REVIEW_APP_PREFIX")
fi

if [ ${#missing[@]} -ne 0 ]; then
echo "Required secrets/variables are not set: ${missing[*]}"
exit 1
fi

- name: Get PR HEAD Ref
id: getRef
Expand Down Expand Up @@ -288,33 +300,12 @@ jobs:

return deployment.data.id;

build:
needs: process-deployment
if: needs.process-deployment.outputs.do_deploy != 'false'
runs-on: ubuntu-latest
outputs:
image_tag: ${{ steps.build.outputs.image_tag }}
comment_id: ${{ needs.process-deployment.outputs.comment_id }}
pr_number: ${{ needs.process-deployment.outputs.pr_number }}
do_deploy: ${{ needs.process-deployment.outputs.do_deploy }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ needs.process-deployment.outputs.pr_ref }}

- name: Setup Environment
uses: ./.github/actions/setup-environment
with:
token: ${{ secrets.CPLN_TOKEN_STAGING }}
org: ${{ vars.CPLN_ORG_STAGING }}

- name: Update Status - Building
uses: actions/github-script@v7
with:
script: |
const buildingMessage = [
'🏗️ Building Docker image for PR #${{ needs.process-deployment.outputs.pr_number }}, commit ${{ needs.process-deployment.outputs.pr_sha }}',
'🏗️ Building Docker image for PR #${{ env.PR_NUMBER }}, commit ${{ env.PR_SHA }}',
'',
'📝 [View Build Logs](${{ env.WORKFLOW_URL }})',
'',
Expand All @@ -324,7 +315,7 @@ jobs:
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: ${{ needs.process-deployment.outputs.comment_id }},
comment_id: ${{ steps.create-comment.outputs.comment-id }},
body: buildingMessage
});

Expand All @@ -334,22 +325,8 @@ jobs:
with:
app_name: ${{ env.APP_NAME }}
org: ${{ vars.CPLN_ORG_STAGING }}
commit: ${{ needs.process-deployment.outputs.pr_sha }}
PR_NUMBER: ${{ needs.process-deployment.outputs.pr_number }}

deploy:
needs: build
if: needs.build.outputs.do_deploy != 'false'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Environment
uses: ./.github/actions/setup-environment
with:
token: ${{ secrets.CPLN_TOKEN_STAGING }}
org: ${{ vars.CPLN_ORG_STAGING }}
commit: ${{ env.PR_SHA }}
PR_NUMBER: ${{ env.PR_NUMBER }}

- name: Update Status - Deploying
uses: actions/github-script@v7
Expand All @@ -374,22 +351,19 @@ jobs:

- name: Deploy to Control Plane
if: env.DO_DEPLOY != 'false'
uses: ./.github/actions/deploy-to-control-plane
with:
app_name: ${{ env.APP_NAME }}
org: ${{ vars.CPLN_ORG_STAGING }}
github_token: ${{ secrets.GITHUB_TOKEN }}
wait_timeout: ${{ vars.WAIT_TIMEOUT || 900 }}
cpln_token: ${{ secrets.CPLN_TOKEN_STAGING }}
pr_number: ${{ env.PR_NUMBER }}
run: cpflow deploy-image -a ${{ env.APP_NAME }} --run-release-phase --org ${{ vars.CPLN_ORG_STAGING }} --verbose

- name: Retrieve App URL
id: workload
run: echo "WORKLOAD_URL=${cpln workload get rails --gvc ${{ env.APP_NAME }} | tee | grep -oP 'https://[^[:space:]]*\.cpln\.app(?=\s|$)' | head -n1}" >> "$GITHUB_OUTPUT"

- name: Update Status - Deployment Complete
if: env.DO_DEPLOY != 'false'
uses: actions/github-script@v7
with:
script: |
const prNumber = process.env.PR_NUMBER;
const appUrl = process.env.APP_URL;
const appUrl = ${{ steps.workload.outputs.WORKLOAD_URL }};
const workflowUrl = process.env.WORKFLOW_URL;
const isSuccess = '${{ job.status }}' === 'success';

Expand Down
Loading