From 8f7c6386a11f908a977233adc79e0d6c61be15db Mon Sep 17 00:00:00 2001 From: Judah Meek Date: Thu, 13 Mar 2025 18:15:51 -0500 Subject: [PATCH 01/19] initial attempt --- .github/actions/validate-required-vars/action.yml | 13 +++++++++++++ .../deploy-to-control-plane-review-app.yml | 3 +++ 2 files changed, 16 insertions(+) diff --git a/.github/actions/validate-required-vars/action.yml b/.github/actions/validate-required-vars/action.yml index c370039d0..d07d17f67 100644 --- a/.github/actions/validate-required-vars/action.yml +++ b/.github/actions/validate-required-vars/action.yml @@ -1,11 +1,23 @@ name: 'Validate Required Variables' description: 'Validates that all required secrets and variables for Control Plane operations' +inputs: + org: + description: 'Organization name' + required: true + prefix: + description: 'Review App Prefix' + required: true + runs: using: 'composite' steps: - name: Validate Required Secrets and Variables shell: bash + env: + REVIEW_APP_PREFIX: ${{ inputs.prefix }} + CPLN_ORG_STAGING: ${{ inputs.org }} + CPLN_TOKEN_STAGING: ${{ secrets.CPLN_TOKEN_STAGING }} run: | missing=() @@ -18,6 +30,7 @@ runs: if [ -z "$CPLN_ORG_STAGING" ]; then missing+=("Variable: CPLN_ORG_STAGING") fi + if [ -z "$REVIEW_APP_PREFIX" ]; then missing+=("Variable: REVIEW_APP_PREFIX") fi diff --git a/.github/workflows/deploy-to-control-plane-review-app.yml b/.github/workflows/deploy-to-control-plane-review-app.yml index ea05f98b0..1f748abd3 100644 --- a/.github/workflows/deploy-to-control-plane-review-app.yml +++ b/.github/workflows/deploy-to-control-plane-review-app.yml @@ -71,6 +71,9 @@ jobs: - name: Validate Required Secrets and Variables uses: ./.github/actions/validate-required-vars + with: + prefix: ${{ vars.REVIEW_APP_PREFIX }} + org: ${{ vars.CPLN_ORG_STAGING }} - name: Get PR HEAD Ref id: getRef From 1454772766f43ea54399061a7d6c7056bb853a6e Mon Sep 17 00:00:00 2001 From: Judah Meek Date: Thu, 13 Mar 2025 18:57:16 -0500 Subject: [PATCH 02/19] composite actions cant use secrets --- .../deploy-to-control-plane/action.yml | 7 ---- .../actions/validate-required-vars/action.yml | 41 ------------------- .github/workflows/delete-review-app.yml | 24 ++++++++++- .../deploy-to-control-plane-review-app.yml | 27 ++++++++++-- 4 files changed, 46 insertions(+), 53 deletions(-) delete mode 100644 .github/actions/validate-required-vars/action.yml diff --git a/.github/actions/deploy-to-control-plane/action.yml b/.github/actions/deploy-to-control-plane/action.yml index fcb684396..869333a58 100644 --- a/.github/actions/deploy-to-control-plane/action.yml +++ b/.github/actions/deploy-to-control-plane/action.yml @@ -10,16 +10,10 @@ inputs: org: description: 'Organization name' required: true - github_token: - description: 'GitHub token' - required: true wait_timeout: description: 'Timeout in seconds for waiting for workloads to be ready' required: false default: '900' - cpln_token: - description: 'Control Plane token' - required: true pr_number: description: 'Pull Request number' required: true @@ -38,7 +32,6 @@ runs: env: APP_NAME: ${{ inputs.app_name }} CPLN_ORG: ${{ inputs.org }} - CPLN_TOKEN: ${{ inputs.cpln_token }} WAIT_TIMEOUT: ${{ inputs.wait_timeout }} run: | # Run the deployment script diff --git a/.github/actions/validate-required-vars/action.yml b/.github/actions/validate-required-vars/action.yml deleted file mode 100644 index d07d17f67..000000000 --- a/.github/actions/validate-required-vars/action.yml +++ /dev/null @@ -1,41 +0,0 @@ -name: 'Validate Required Variables' -description: 'Validates that all required secrets and variables for Control Plane operations' - -inputs: - org: - description: 'Organization name' - required: true - prefix: - description: 'Review App Prefix' - required: true - -runs: - using: 'composite' - steps: - - name: Validate Required Secrets and Variables - shell: bash - env: - REVIEW_APP_PREFIX: ${{ inputs.prefix }} - CPLN_ORG_STAGING: ${{ inputs.org }} - CPLN_TOKEN_STAGING: ${{ secrets.CPLN_TOKEN_STAGING }} - run: | - missing=() - - # Check required secrets - if [ -z "$CPLN_TOKEN_STAGING" ]; then - missing+=("Secret: CPLN_TOKEN_STAGING") - fi - - # Check required variables - if [ -z "$CPLN_ORG_STAGING" ]; then - missing+=("Variable: CPLN_ORG_STAGING") - fi - - if [ -z "$REVIEW_APP_PREFIX" ]; then - missing+=("Variable: REVIEW_APP_PREFIX") - fi - - if [ ${#missing[@]} -ne 0 ]; then - echo "Required secrets/variables are not set: ${missing[*]}" - exit 1 - fi diff --git a/.github/workflows/delete-review-app.yml b/.github/workflows/delete-review-app.yml index a0b3611a8..3f1451bc5 100644 --- a/.github/workflows/delete-review-app.yml +++ b/.github/workflows/delete-review-app.yml @@ -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 }} @@ -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 - name: Setup Environment uses: ./.github/actions/setup-environment diff --git a/.github/workflows/deploy-to-control-plane-review-app.yml b/.github/workflows/deploy-to-control-plane-review-app.yml index 1f748abd3..501105793 100644 --- a/.github/workflows/deploy-to-control-plane-review-app.yml +++ b/.github/workflows/deploy-to-control-plane-review-app.yml @@ -24,6 +24,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 }} @@ -70,10 +71,28 @@ jobs: fetch-depth: 0 - name: Validate Required Secrets and Variables - uses: ./.github/actions/validate-required-vars - with: - prefix: ${{ vars.REVIEW_APP_PREFIX }} - org: ${{ vars.CPLN_ORG_STAGING }} + 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 From d70b5464d20b4574f273cd1f0ee97bbdd6d463a8 Mon Sep 17 00:00:00 2001 From: Judah Meek Date: Fri, 14 Mar 2025 16:36:08 -0500 Subject: [PATCH 03/19] try again --- .../workflows/deploy-to-control-plane-review-app.yml | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/.github/workflows/deploy-to-control-plane-review-app.yml b/.github/workflows/deploy-to-control-plane-review-app.yml index 501105793..8997d4c74 100644 --- a/.github/workflows/deploy-to-control-plane-review-app.yml +++ b/.github/workflows/deploy-to-control-plane-review-app.yml @@ -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: @@ -85,7 +83,7 @@ jobs: missing+=("Variable: CPLN_ORG_STAGING") fi - if [ -z "$"PREFIX" ]; then + if [ -z "$PREFIX" ]; then missing+=("Variable: REVIEW_APP_PREFIX") fi From 0562a28efe8d30c93355ccd705681152b08f1cca Mon Sep 17 00:00:00 2001 From: Judah Meek Date: Fri, 14 Mar 2025 17:10:53 -0500 Subject: [PATCH 04/19] try adding quotes --- .github/workflows/deploy-to-control-plane-review-app.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-to-control-plane-review-app.yml b/.github/workflows/deploy-to-control-plane-review-app.yml index 8997d4c74..db81fd778 100644 --- a/.github/workflows/deploy-to-control-plane-review-app.yml +++ b/.github/workflows/deploy-to-control-plane-review-app.yml @@ -388,7 +388,7 @@ jobs: await github.rest.issues.updateComment({ owner: context.repo.owner, repo: context.repo.repo, - comment_id: ${{ steps.create-comment.outputs.comment-id }}, + comment_id: '${{ steps.create-comment.outputs.comment-id }}', body: deployingMessage }); From d17ca4e8ecbe68c0f8e3014016f19025d804bff5 Mon Sep 17 00:00:00 2001 From: Judah Meek Date: Mon, 17 Mar 2025 15:29:45 -0500 Subject: [PATCH 05/19] fix references to output from other jobs --- .github/workflows/deploy-to-control-plane-review-app.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/deploy-to-control-plane-review-app.yml b/.github/workflows/deploy-to-control-plane-review-app.yml index db81fd778..dd5435fa4 100644 --- a/.github/workflows/deploy-to-control-plane-review-app.yml +++ b/.github/workflows/deploy-to-control-plane-review-app.yml @@ -314,9 +314,6 @@ jobs: 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 @@ -388,7 +385,7 @@ jobs: await github.rest.issues.updateComment({ owner: context.repo.owner, repo: context.repo.repo, - comment_id: '${{ steps.create-comment.outputs.comment-id }}', + comment_id: '${{ needs.process-deployment.outputs.comment_id }}', body: deployingMessage }); @@ -419,7 +416,7 @@ jobs: const deploymentStatus = { owner: context.repo.owner, repo: context.repo.repo, - deployment_id: ${{ steps.init-deployment.outputs.result }}, + deployment_id: ${{ needs.process-deployment.outputs.deployment_id }}, state: isSuccess ? 'success' : 'failure', environment_url: isSuccess ? appUrl : undefined, log_url: workflowUrl, From 1039020a50176e2373ae11f2485a3e6c59d3b3e9 Mon Sep 17 00:00:00 2001 From: Judah Meek Date: Mon, 17 Mar 2025 15:46:50 -0500 Subject: [PATCH 06/19] add debug steps --- .../workflows/deploy-to-control-plane-review-app.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy-to-control-plane-review-app.yml b/.github/workflows/deploy-to-control-plane-review-app.yml index dd5435fa4..b0b275f8e 100644 --- a/.github/workflows/deploy-to-control-plane-review-app.yml +++ b/.github/workflows/deploy-to-control-plane-review-app.yml @@ -358,6 +358,8 @@ jobs: needs: build if: needs.build.outputs.do_deploy != 'false' runs-on: ubuntu-latest + env: + COMMENT_ID: ${{ needs.process-deployment.outputs.comment_id }} steps: - name: Checkout code uses: actions/checkout@v4 @@ -368,6 +370,12 @@ jobs: token: ${{ secrets.CPLN_TOKEN_STAGING }} org: ${{ vars.CPLN_ORG_STAGING }} + - name: Print Comment id as job output + run: echo '${{ needs.process-deployment.outputs.comment_id }}' + + - name: Print Comment id as env var + run: echo '${process.env.COMMENT_ID}' + - name: Update Status - Deploying uses: actions/github-script@v7 with: @@ -385,7 +393,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: '${process.env.COMMENT_ID}', body: deployingMessage }); From a6fe0a35439ae62c763e430b6034732bdc38d7bf Mon Sep 17 00:00:00 2001 From: Judah Meek Date: Mon, 17 Mar 2025 16:03:05 -0500 Subject: [PATCH 07/19] debug --- .github/workflows/deploy-to-control-plane-review-app.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy-to-control-plane-review-app.yml b/.github/workflows/deploy-to-control-plane-review-app.yml index b0b275f8e..ec828bc35 100644 --- a/.github/workflows/deploy-to-control-plane-review-app.yml +++ b/.github/workflows/deploy-to-control-plane-review-app.yml @@ -244,6 +244,7 @@ jobs: issue_number: process.env.PR_NUMBER, body: '🚀 Starting deployment process...\n\n' + process.env.CONSOLE_LINK }); + // console.log(result); core.setOutput('comment-id', result.data.id); - name: Set Deployment URLs @@ -374,7 +375,7 @@ jobs: run: echo '${{ needs.process-deployment.outputs.comment_id }}' - name: Print Comment id as env var - run: echo '${process.env.COMMENT_ID}' + run: echo $COMMENT_ID - name: Update Status - Deploying uses: actions/github-script@v7 @@ -455,6 +456,6 @@ jobs: await github.rest.issues.updateComment({ owner: context.repo.owner, repo: context.repo.repo, - comment_id: ${{ steps.create-comment.outputs.comment-id }}, + comment_id: ${{ needs.process-deployment.outputs.comment_id }}, body: isSuccess ? successMessage : failureMessage }); From ee5c4f43eff11b2ea433caa4376a1e2392aa8176 Mon Sep 17 00:00:00 2001 From: Judah Meek Date: Mon, 17 Mar 2025 16:43:27 -0500 Subject: [PATCH 08/19] fix deploy job's dependencies --- .../deploy-to-control-plane-review-app.yml | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/.github/workflows/deploy-to-control-plane-review-app.yml b/.github/workflows/deploy-to-control-plane-review-app.yml index ec828bc35..d06a6380e 100644 --- a/.github/workflows/deploy-to-control-plane-review-app.yml +++ b/.github/workflows/deploy-to-control-plane-review-app.yml @@ -244,7 +244,6 @@ jobs: issue_number: process.env.PR_NUMBER, body: '🚀 Starting deployment process...\n\n' + process.env.CONSOLE_LINK }); - // console.log(result); core.setOutput('comment-id', result.data.id); - name: Set Deployment URLs @@ -356,11 +355,9 @@ jobs: PR_NUMBER: ${{ needs.process-deployment.outputs.pr_number }} deploy: - needs: build + needs: [build, process-deployment] if: needs.build.outputs.do_deploy != 'false' runs-on: ubuntu-latest - env: - COMMENT_ID: ${{ needs.process-deployment.outputs.comment_id }} steps: - name: Checkout code uses: actions/checkout@v4 @@ -371,12 +368,6 @@ jobs: token: ${{ secrets.CPLN_TOKEN_STAGING }} org: ${{ vars.CPLN_ORG_STAGING }} - - name: Print Comment id as job output - run: echo '${{ needs.process-deployment.outputs.comment_id }}' - - - name: Print Comment id as env var - run: echo $COMMENT_ID - - name: Update Status - Deploying uses: actions/github-script@v7 with: @@ -394,7 +385,7 @@ jobs: await github.rest.issues.updateComment({ owner: context.repo.owner, repo: context.repo.repo, - comment_id: '${process.env.COMMENT_ID}', + comment_id: ${{ needs.process-deployment.outputs.comment_id }}, body: deployingMessage }); From c334031d78ca1eaffa15a2169316c89c484c9e99 Mon Sep 17 00:00:00 2001 From: Judah Meek Date: Mon, 17 Mar 2025 20:02:48 -0500 Subject: [PATCH 09/19] attempt --- .../deploy-to-control-plane/scripts/deploy.sh | 14 +++++++------- .github/actions/setup-environment/action.yml | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/actions/deploy-to-control-plane/scripts/deploy.sh b/.github/actions/deploy-to-control-plane/scripts/deploy.sh index f90ede239..9f5c49dea 100755 --- a/.github/actions/deploy-to-control-plane/scripts/deploy.sh +++ b/.github/actions/deploy-to-control-plane/scripts/deploy.sh @@ -38,13 +38,6 @@ if ! timeout "${WAIT_TIMEOUT}" cpflow deploy-image -a "$APP_NAME" --run-release- exit 1 fi -# Extract app URL from deployment output -APP_URL=$(grep -oP 'https://[^[:space:]]*\.cpln\.app(?=\s|$)' "$TEMP_OUTPUT" | head -n1) -if [ -z "$APP_URL" ]; then - echo "❌ Error: Could not find app URL in deployment output" - exit 1 -fi - # Wait for all workloads to be ready echo "⏳ Waiting for all workloads to be ready (timeout: ${WAIT_TIMEOUT}s)" if ! timeout "${WAIT_TIMEOUT}" bash -c "cpflow ps:wait -a \"$APP_NAME\"" 2>&1 | tee -a "$TEMP_OUTPUT"; then @@ -59,6 +52,13 @@ if ! timeout "${WAIT_TIMEOUT}" bash -c "cpflow ps:wait -a \"$APP_NAME\"" 2>&1 | exit 1 fi +# Extract app URL from deployment output +APP_URL=$(grep -oP 'https://[^[:space:]]*\.cpln\.app(?=\s|$)' "$TEMP_OUTPUT" | head -n1) +if [ -z "$APP_URL" ]; then + echo "❌ Error: Could not find app URL in deployment output" + exit 1 +fi + echo "✅ Deployment successful" echo "🌐 App URL: $APP_URL" echo "APP_URL=$APP_URL" >> "$GITHUB_OUTPUT" diff --git a/.github/actions/setup-environment/action.yml b/.github/actions/setup-environment/action.yml index 710b6c71e..e9212d6e0 100644 --- a/.github/actions/setup-environment/action.yml +++ b/.github/actions/setup-environment/action.yml @@ -24,7 +24,7 @@ runs: run: | sudo npm install -g @controlplane/cli@3.3.1 cpln --version - gem install cpflow -v 4.1.0 + gem install cpflow -v 4.1.1 cpflow --version - name: Setup Control Plane Profile From 5f30098515a7510641ef220968dc4494ea7cb4d1 Mon Sep 17 00:00:00 2001 From: Judah Meek Date: Tue, 18 Mar 2025 14:08:14 -0500 Subject: [PATCH 10/19] add debug statement --- .github/actions/deploy-to-control-plane/scripts/deploy.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/actions/deploy-to-control-plane/scripts/deploy.sh b/.github/actions/deploy-to-control-plane/scripts/deploy.sh index 9f5c49dea..46e36f184 100755 --- a/.github/actions/deploy-to-control-plane/scripts/deploy.sh +++ b/.github/actions/deploy-to-control-plane/scripts/deploy.sh @@ -56,6 +56,8 @@ fi APP_URL=$(grep -oP 'https://[^[:space:]]*\.cpln\.app(?=\s|$)' "$TEMP_OUTPUT" | head -n1) if [ -z "$APP_URL" ]; then echo "❌ Error: Could not find app URL in deployment output" + echo "Full output:" + cat "$TEMP_OUTPUT" exit 1 fi From 328f25f7e10043997aa49241b23b798693f5230c Mon Sep 17 00:00:00 2001 From: Judah Meek Date: Tue, 18 Mar 2025 17:25:44 -0500 Subject: [PATCH 11/19] attempt --- .github/actions/deploy-to-control-plane/scripts/deploy.sh | 8 ++++++++ .github/workflows/deploy-to-control-plane-review-app.yml | 3 +++ 2 files changed, 11 insertions(+) diff --git a/.github/actions/deploy-to-control-plane/scripts/deploy.sh b/.github/actions/deploy-to-control-plane/scripts/deploy.sh index 46e36f184..a3369a420 100755 --- a/.github/actions/deploy-to-control-plane/scripts/deploy.sh +++ b/.github/actions/deploy-to-control-plane/scripts/deploy.sh @@ -19,6 +19,9 @@ set -e : "${APP_NAME:?APP_NAME environment variable is required}" : "${CPLN_ORG:?CPLN_ORG environment variable is required}" +auth_check=$(cpln profile get 2>&1) +echo "$auth_check" + # Set and validate deployment timeout WAIT_TIMEOUT=${WAIT_TIMEOUT:-900} if ! [[ "${WAIT_TIMEOUT}" =~ ^[0-9]+$ ]]; then @@ -38,6 +41,8 @@ if ! timeout "${WAIT_TIMEOUT}" cpflow deploy-image -a "$APP_NAME" --run-release- exit 1 fi +echo "🚀 Rocket launched!" + # Wait for all workloads to be ready echo "⏳ Waiting for all workloads to be ready (timeout: ${WAIT_TIMEOUT}s)" if ! timeout "${WAIT_TIMEOUT}" bash -c "cpflow ps:wait -a \"$APP_NAME\"" 2>&1 | tee -a "$TEMP_OUTPUT"; then @@ -52,7 +57,10 @@ if ! timeout "${WAIT_TIMEOUT}" bash -c "cpflow ps:wait -a \"$APP_NAME\"" 2>&1 | exit 1 fi +echo "⏳ Wait complete!" + # Extract app URL from deployment output +echo "🙏 Extracting app URL" APP_URL=$(grep -oP 'https://[^[:space:]]*\.cpln\.app(?=\s|$)' "$TEMP_OUTPUT" | head -n1) if [ -z "$APP_URL" ]; then echo "❌ Error: Could not find app URL in deployment output" diff --git a/.github/workflows/deploy-to-control-plane-review-app.yml b/.github/workflows/deploy-to-control-plane-review-app.yml index d06a6380e..d3a6073e0 100644 --- a/.github/workflows/deploy-to-control-plane-review-app.yml +++ b/.github/workflows/deploy-to-control-plane-review-app.yml @@ -367,6 +367,9 @@ jobs: with: token: ${{ secrets.CPLN_TOKEN_STAGING }} org: ${{ vars.CPLN_ORG_STAGING }} + + - name: Confirm Auth + run: cpln profile get - name: Update Status - Deploying uses: actions/github-script@v7 From dfc82c485677e1a0a05b4b54bc079bf95f4dd4b3 Mon Sep 17 00:00:00 2001 From: Judah Meek Date: Tue, 18 Mar 2025 18:25:25 -0500 Subject: [PATCH 12/19] revert changes to deploy script --- .../deploy-to-control-plane/scripts/deploy.sh | 61 ++++++------------- 1 file changed, 19 insertions(+), 42 deletions(-) diff --git a/.github/actions/deploy-to-control-plane/scripts/deploy.sh b/.github/actions/deploy-to-control-plane/scripts/deploy.sh index a3369a420..9d070b64a 100755 --- a/.github/actions/deploy-to-control-plane/scripts/deploy.sh +++ b/.github/actions/deploy-to-control-plane/scripts/deploy.sh @@ -1,7 +1,7 @@ #!/bin/bash # This script handles the deployment to Control Plane and extracts the Rails URL -# +# # Required environment variables: # - APP_NAME: Name of the application to deploy # - CPLN_ORG: Control Plane organization @@ -11,7 +11,7 @@ # Must be a positive integer # # Outputs: -# - ENV APP_URL: URL of the deployed application +# - rails_url: URL of the deployed Rails application set -e @@ -19,9 +19,6 @@ set -e : "${APP_NAME:?APP_NAME environment variable is required}" : "${CPLN_ORG:?CPLN_ORG environment variable is required}" -auth_check=$(cpln profile get 2>&1) -echo "$auth_check" - # Set and validate deployment timeout WAIT_TIMEOUT=${WAIT_TIMEOUT:-900} if ! [[ "${WAIT_TIMEOUT}" =~ ^[0-9]+$ ]]; then @@ -34,41 +31,21 @@ trap 'rm -f "$TEMP_OUTPUT"' EXIT # Deploy the application echo "🚀 Deploying to Control Plane (timeout: ${WAIT_TIMEOUT}s)" -if ! timeout "${WAIT_TIMEOUT}" cpflow deploy-image -a "$APP_NAME" --run-release-phase --org "$CPLN_ORG" --verbose 2>&1 | tee "$TEMP_OUTPUT"; then - echo "❌ Deployment failed" - echo "Full output:" - cat "$TEMP_OUTPUT" - exit 1 -fi - -echo "🚀 Rocket launched!" - -# Wait for all workloads to be ready -echo "⏳ Waiting for all workloads to be ready (timeout: ${WAIT_TIMEOUT}s)" -if ! timeout "${WAIT_TIMEOUT}" bash -c "cpflow ps:wait -a \"$APP_NAME\"" 2>&1 | tee -a "$TEMP_OUTPUT"; then - TIMEOUT_EXIT=$? - if [ ${TIMEOUT_EXIT} -eq 124 ]; then - echo "❌ Timed out waiting for workloads after ${WAIT_TIMEOUT} seconds" - else - echo "❌ Workloads did not become ready" - fi - echo "Full output:" - cat "$TEMP_OUTPUT" - exit 1 -fi - -echo "⏳ Wait complete!" - -# Extract app URL from deployment output -echo "🙏 Extracting app URL" -APP_URL=$(grep -oP 'https://[^[:space:]]*\.cpln\.app(?=\s|$)' "$TEMP_OUTPUT" | head -n1) -if [ -z "$APP_URL" ]; then - echo "❌ Error: Could not find app URL in deployment output" - echo "Full output:" - cat "$TEMP_OUTPUT" - exit 1 +if timeout "$WAIT_TIMEOUT" cpflow deploy-image -a "$APP_NAME" --run-release-phase --org "$CPLN_ORG" --verbose | tee "$TEMP_OUTPUT"; then + # Extract Rails URL from deployment output + RAILS_URL=$(grep -oP 'https://rails-[^[:space:]]*\.cpln\.app(?=\s|$)' "$TEMP_OUTPUT" | head -n1) + if [ -n "$RAILS_URL" ]; then + echo "rails_url=$RAILS_URL" >> "$GITHUB_OUTPUT" + echo "✅ Deployment successful" + echo "🚀 Rails URL: $RAILS_URL" + else + echo "❌ Failed to extract Rails URL from deployment output" + exit 1 + fi +elif [ $? -eq 124 ]; then + echo "❌ Deployment timed out after $WAIT_TIMEOUT seconds" + exit 1 +else + echo "❌ Deployment to Control Plane failed" + exit 1 fi - -echo "✅ Deployment successful" -echo "🌐 App URL: $APP_URL" -echo "APP_URL=$APP_URL" >> "$GITHUB_OUTPUT" From d63cfb9f9f6e35b14aaf94706b7cc048961060c6 Mon Sep 17 00:00:00 2001 From: Judah Meek Date: Tue, 18 Mar 2025 19:44:37 -0500 Subject: [PATCH 13/19] check-workflows --- .github/actions/deploy-to-control-plane/scripts/deploy.sh | 3 +++ .github/workflows/deploy-to-control-plane-review-app.yml | 2 ++ 2 files changed, 5 insertions(+) diff --git a/.github/actions/deploy-to-control-plane/scripts/deploy.sh b/.github/actions/deploy-to-control-plane/scripts/deploy.sh index 9d070b64a..bd9188fb4 100755 --- a/.github/actions/deploy-to-control-plane/scripts/deploy.sh +++ b/.github/actions/deploy-to-control-plane/scripts/deploy.sh @@ -29,6 +29,9 @@ fi TEMP_OUTPUT=$(mktemp) trap 'rm -f "$TEMP_OUTPUT"' EXIT +last_output=$(cpln workload get 2>&1) +echo "$last_output" + # Deploy the application echo "🚀 Deploying to Control Plane (timeout: ${WAIT_TIMEOUT}s)" if timeout "$WAIT_TIMEOUT" cpflow deploy-image -a "$APP_NAME" --run-release-phase --org "$CPLN_ORG" --verbose | tee "$TEMP_OUTPUT"; then diff --git a/.github/workflows/deploy-to-control-plane-review-app.yml b/.github/workflows/deploy-to-control-plane-review-app.yml index d3a6073e0..788dd5f71 100644 --- a/.github/workflows/deploy-to-control-plane-review-app.yml +++ b/.github/workflows/deploy-to-control-plane-review-app.yml @@ -178,6 +178,8 @@ jobs: if ! cpflow exists -a ${{ env.APP_NAME }}; then echo "APP_EXISTS=false" >> $GITHUB_ENV else + last_output=$(cpln workload get 2>&1) + echo "$last_output" echo "APP_EXISTS=true" >> $GITHUB_ENV fi From 95415c1513611eb80fef965444476274c548b2f3 Mon Sep 17 00:00:00 2001 From: Judah Meek Date: Tue, 18 Mar 2025 20:13:12 -0500 Subject: [PATCH 14/19] ditch-bash --- .github/workflows/deploy-to-control-plane-review-app.yml | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/.github/workflows/deploy-to-control-plane-review-app.yml b/.github/workflows/deploy-to-control-plane-review-app.yml index 788dd5f71..0dfed3f46 100644 --- a/.github/workflows/deploy-to-control-plane-review-app.yml +++ b/.github/workflows/deploy-to-control-plane-review-app.yml @@ -396,14 +396,7 @@ 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: Update Status - Deployment Complete if: env.DO_DEPLOY != 'false' From 1442b41fd6d976dc4756ddfeb3ae43b17c0f05ec Mon Sep 17 00:00:00 2001 From: Judah Meek Date: Tue, 18 Mar 2025 20:34:43 -0500 Subject: [PATCH 15/19] tee --- .github/actions/deploy-to-control-plane/scripts/deploy.sh | 3 +-- .github/workflows/deploy-to-control-plane-review-app.yml | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/actions/deploy-to-control-plane/scripts/deploy.sh b/.github/actions/deploy-to-control-plane/scripts/deploy.sh index bd9188fb4..ac4296649 100755 --- a/.github/actions/deploy-to-control-plane/scripts/deploy.sh +++ b/.github/actions/deploy-to-control-plane/scripts/deploy.sh @@ -29,8 +29,7 @@ fi TEMP_OUTPUT=$(mktemp) trap 'rm -f "$TEMP_OUTPUT"' EXIT -last_output=$(cpln workload get 2>&1) -echo "$last_output" +cpln workload get | tee # Deploy the application echo "🚀 Deploying to Control Plane (timeout: ${WAIT_TIMEOUT}s)" diff --git a/.github/workflows/deploy-to-control-plane-review-app.yml b/.github/workflows/deploy-to-control-plane-review-app.yml index 0dfed3f46..7f10ddb4d 100644 --- a/.github/workflows/deploy-to-control-plane-review-app.yml +++ b/.github/workflows/deploy-to-control-plane-review-app.yml @@ -178,8 +178,7 @@ jobs: if ! cpflow exists -a ${{ env.APP_NAME }}; then echo "APP_EXISTS=false" >> $GITHUB_ENV else - last_output=$(cpln workload get 2>&1) - echo "$last_output" + cpln workload get | tee echo "APP_EXISTS=true" >> $GITHUB_ENV fi From 62c6465362356fcebc45378a7f6f401a158cb7c3 Mon Sep 17 00:00:00 2001 From: Judah Meek Date: Tue, 18 Mar 2025 21:03:15 -0500 Subject: [PATCH 16/19] condense --- .../deploy-to-control-plane/action.yml | 40 ------------- .../deploy-to-control-plane/scripts/deploy.sh | 53 ---------------- .../deploy-to-control-plane-review-app.yml | 60 ++++--------------- 3 files changed, 11 insertions(+), 142 deletions(-) delete mode 100644 .github/actions/deploy-to-control-plane/action.yml delete mode 100755 .github/actions/deploy-to-control-plane/scripts/deploy.sh diff --git a/.github/actions/deploy-to-control-plane/action.yml b/.github/actions/deploy-to-control-plane/action.yml deleted file mode 100644 index 869333a58..000000000 --- a/.github/actions/deploy-to-control-plane/action.yml +++ /dev/null @@ -1,40 +0,0 @@ -# Control Plane GitHub Action - -name: Deploy to Control Plane -description: 'Deploys an application to Control Plane' - -inputs: - app_name: - description: 'Name of the application' - required: true - org: - description: 'Organization name' - required: true - wait_timeout: - description: 'Timeout in seconds for waiting for workloads to be ready' - required: false - default: '900' - pr_number: - description: 'Pull Request number' - required: true - -outputs: - review_app_url: - description: 'URL of the deployed application' - value: ${{ steps.deploy.outputs.review_app_url }} - -runs: - using: "composite" - steps: - - name: Deploy to Control Plane - id: deploy - shell: bash - env: - APP_NAME: ${{ inputs.app_name }} - CPLN_ORG: ${{ inputs.org }} - WAIT_TIMEOUT: ${{ inputs.wait_timeout }} - run: | - # Run the deployment script - if ! ${{ github.action_path }}/scripts/deploy.sh; then - exit 1 - fi diff --git a/.github/actions/deploy-to-control-plane/scripts/deploy.sh b/.github/actions/deploy-to-control-plane/scripts/deploy.sh deleted file mode 100755 index ac4296649..000000000 --- a/.github/actions/deploy-to-control-plane/scripts/deploy.sh +++ /dev/null @@ -1,53 +0,0 @@ -#!/bin/bash - -# This script handles the deployment to Control Plane and extracts the Rails URL -# -# Required environment variables: -# - APP_NAME: Name of the application to deploy -# - CPLN_ORG: Control Plane organization -# -# Optional environment variables: -# - WAIT_TIMEOUT: Timeout in seconds for deployment (default: 900) -# Must be a positive integer -# -# Outputs: -# - rails_url: URL of the deployed Rails application - -set -e - -# Validate required environment variables -: "${APP_NAME:?APP_NAME environment variable is required}" -: "${CPLN_ORG:?CPLN_ORG environment variable is required}" - -# Set and validate deployment timeout -WAIT_TIMEOUT=${WAIT_TIMEOUT:-900} -if ! [[ "${WAIT_TIMEOUT}" =~ ^[0-9]+$ ]]; then - echo "❌ Invalid timeout value: ${WAIT_TIMEOUT}" - exit 1 -fi - -TEMP_OUTPUT=$(mktemp) -trap 'rm -f "$TEMP_OUTPUT"' EXIT - -cpln workload get | tee - -# Deploy the application -echo "🚀 Deploying to Control Plane (timeout: ${WAIT_TIMEOUT}s)" -if timeout "$WAIT_TIMEOUT" cpflow deploy-image -a "$APP_NAME" --run-release-phase --org "$CPLN_ORG" --verbose | tee "$TEMP_OUTPUT"; then - # Extract Rails URL from deployment output - RAILS_URL=$(grep -oP 'https://rails-[^[:space:]]*\.cpln\.app(?=\s|$)' "$TEMP_OUTPUT" | head -n1) - if [ -n "$RAILS_URL" ]; then - echo "rails_url=$RAILS_URL" >> "$GITHUB_OUTPUT" - echo "✅ Deployment successful" - echo "🚀 Rails URL: $RAILS_URL" - else - echo "❌ Failed to extract Rails URL from deployment output" - exit 1 - fi -elif [ $? -eq 124 ]; then - echo "❌ Deployment timed out after $WAIT_TIMEOUT seconds" - exit 1 -else - echo "❌ Deployment to Control Plane failed" - exit 1 -fi diff --git a/.github/workflows/deploy-to-control-plane-review-app.yml b/.github/workflows/deploy-to-control-plane-review-app.yml index 7f10ddb4d..51a638c2b 100644 --- a/.github/workflows/deploy-to-control-plane-review-app.yml +++ b/.github/workflows/deploy-to-control-plane-review-app.yml @@ -34,8 +34,7 @@ jobs: with: debug_enabled: false - process-deployment: - needs: debug + deploy: if: | (github.event_name == 'pull_request') || (github.event_name == 'push') || @@ -44,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 @@ -178,7 +170,6 @@ jobs: if ! cpflow exists -a ${{ env.APP_NAME }}; then echo "APP_EXISTS=false" >> $GITHUB_ENV else - cpln workload get | tee echo "APP_EXISTS=true" >> $GITHUB_ENV fi @@ -309,30 +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 }} - 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 }})', '', @@ -342,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 }); @@ -352,26 +325,15 @@ 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, process-deployment] - 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: Confirm Auth run: cpln profile get + - name: Confirm Workloads + run: cpln workload get --gvc ${{ env.APP_NAME }} | tee + - name: Update Status - Deploying uses: actions/github-script@v7 with: @@ -389,7 +351,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: deployingMessage }); @@ -413,7 +375,7 @@ jobs: const deploymentStatus = { owner: context.repo.owner, repo: context.repo.repo, - deployment_id: ${{ needs.process-deployment.outputs.deployment_id }}, + deployment_id: ${{ steps.init-deployment.outputs.result }}, state: isSuccess ? 'success' : 'failure', environment_url: isSuccess ? appUrl : undefined, log_url: workflowUrl, @@ -444,6 +406,6 @@ 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: isSuccess ? successMessage : failureMessage }); From fd0037984344a8e313604edb72f3fd72b41cb014 Mon Sep 17 00:00:00 2001 From: Judah Meek Date: Tue, 18 Mar 2025 23:34:11 -0500 Subject: [PATCH 17/19] workload --- .../workflows/deploy-to-control-plane-review-app.yml | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/.github/workflows/deploy-to-control-plane-review-app.yml b/.github/workflows/deploy-to-control-plane-review-app.yml index 51a638c2b..1a520aa6f 100644 --- a/.github/workflows/deploy-to-control-plane-review-app.yml +++ b/.github/workflows/deploy-to-control-plane-review-app.yml @@ -327,12 +327,6 @@ jobs: org: ${{ vars.CPLN_ORG_STAGING }} commit: ${{ env.PR_SHA }} PR_NUMBER: ${{ env.PR_NUMBER }} - - - name: Confirm Auth - run: cpln profile get - - - name: Confirm Workloads - run: cpln workload get --gvc ${{ env.APP_NAME }} | tee - name: Update Status - Deploying uses: actions/github-script@v7 @@ -359,13 +353,17 @@ jobs: if: env.DO_DEPLOY != 'false' 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'; From 6f4ef1ea8d95a9367ac2bcfb5cdaea05f60d613c Mon Sep 17 00:00:00 2001 From: Judah Meek Date: Wed, 19 Mar 2025 15:08:03 -0500 Subject: [PATCH 18/19] braces to parentheses Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- .github/workflows/deploy-to-control-plane-review-app.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/deploy-to-control-plane-review-app.yml b/.github/workflows/deploy-to-control-plane-review-app.yml index 1a520aa6f..af4866a29 100644 --- a/.github/workflows/deploy-to-control-plane-review-app.yml +++ b/.github/workflows/deploy-to-control-plane-review-app.yml @@ -355,8 +355,7 @@ jobs: - 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" - + 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 From 99a6c33609a6ca7bbbe14df9ec6aa5d810fd4e98 Mon Sep 17 00:00:00 2001 From: Judah Meek Date: Wed, 19 Mar 2025 15:26:18 -0500 Subject: [PATCH 19/19] quotes --- .github/workflows/deploy-to-control-plane-review-app.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy-to-control-plane-review-app.yml b/.github/workflows/deploy-to-control-plane-review-app.yml index af4866a29..74a4468b9 100644 --- a/.github/workflows/deploy-to-control-plane-review-app.yml +++ b/.github/workflows/deploy-to-control-plane-review-app.yml @@ -356,13 +356,14 @@ jobs: - 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 = ${{ steps.workload.outputs.WORKLOAD_URL }}; + const appUrl = '${{ steps.workload.outputs.WORKLOAD_URL }}'; const workflowUrl = process.env.WORKFLOW_URL; const isSuccess = '${{ job.status }}' === 'success';