Skip to content

Commit 40f7244

Browse files
committed
Revert "Enhance GitHub Actions workflows for review app and staging deployments"
This reverts commit 586dac3.
1 parent 586dac3 commit 40f7244

File tree

10 files changed

+314
-334
lines changed

10 files changed

+314
-334
lines changed

.github/actions/build-docker-image/action.yml

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ inputs:
1313
required: true
1414
PR_NUMBER:
1515
description: 'PR number'
16-
required: false
16+
required: true
1717

1818
runs:
1919
using: "composite"
@@ -22,18 +22,11 @@ runs:
2222
id: build
2323
shell: bash
2424
run: |
25-
PR_INFO=""
26-
if [ -n "${PR_NUMBER}" ]; then
27-
PR_INFO=" for PR #${PR_NUMBER}"
28-
fi
29-
30-
echo "🏗️ Building Docker image${PR_INFO} (commit ${{ inputs.commit }})..."
25+
echo "🏗️ Building Docker image for PR #${PR_NUMBER} (commit ${{ inputs.commit }})..."
3126
3227
if cpflow build-image -a "${{ inputs.app_name }}" --commit="${{ inputs.commit }}" --org="${{ inputs.org }}"; then
33-
image_tag="${{ inputs.org }}/${{ inputs.app_name }}:${{ inputs.commit }}"
34-
echo "image_tag=${image_tag}" >> $GITHUB_OUTPUT
35-
echo "✅ Docker image build successful${PR_INFO} (commit ${{ inputs.commit }})"
28+
echo "✅ Docker image build successful for PR #${PR_NUMBER} (commit ${{ inputs.commit }})"
3629
else
37-
echo "❌ Docker image build failed${PR_INFO} (commit ${{ inputs.commit }})"
30+
echo "❌ Docker image build failed for PR #${PR_NUMBER} (commit ${{ inputs.commit }})"
3831
exit 1
3932
fi
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Delete Control Plane App
2+
description: 'Deletes a Control Plane application and all its resources'
3+
4+
inputs:
5+
app_name:
6+
description: 'Name of the application to delete'
7+
required: true
8+
org:
9+
description: 'Organization name'
10+
required: true
11+
12+
runs:
13+
using: "composite"
14+
steps:
15+
- name: Delete Application
16+
shell: bash
17+
run: ${{ github.action_path }}/scripts/delete-app.sh
18+
env:
19+
APP_NAME: ${{ inputs.app_name }}
20+
CPLN_ORG: ${{ inputs.org }}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
# Script to delete a Control Plane application
4+
# Required environment variables:
5+
# - APP_NAME: Name of the application to delete
6+
# - CPLN_ORG: Organization name
7+
8+
set -e
9+
10+
# Validate required environment variables
11+
: "${APP_NAME:?APP_NAME environment variable is required}"
12+
: "${CPLN_ORG:?CPLN_ORG environment variable is required}"
13+
14+
# Safety check: prevent deletion of production or staging apps
15+
if echo "$APP_NAME" | grep -iqE '(production|staging)'; then
16+
echo "❌ ERROR: Cannot delete apps containing 'production' or 'staging' in their name" >&2
17+
echo "🛑 This is a safety measure to prevent accidental deletion of production or staging environments" >&2
18+
echo " App name: $APP_NAME" >&2
19+
exit 1
20+
fi
21+
22+
# Check if app exists before attempting to delete
23+
echo "🔍 Checking if application exists: $APP_NAME"
24+
if ! cpflow exists -a "$APP_NAME"; then
25+
echo "⚠️ Application does not exist: $APP_NAME"
26+
exit 0
27+
fi
28+
29+
# Delete the application
30+
echo "🗑️ Deleting application: $APP_NAME"
31+
if ! cpflow delete -a "$APP_NAME" --force; then
32+
echo "❌ Failed to delete application: $APP_NAME" >&2
33+
exit 1
34+
fi
35+
36+
echo "✅ Successfully deleted application: $APP_NAME"
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: 'Show Help Command'
2+
description: 'Displays help information for available commands in PR comments'
3+
4+
inputs:
5+
github-token:
6+
description: 'GitHub token for posting comments'
7+
required: true
8+
issue-number:
9+
description: 'PR/Issue number to post the comment to (optional, defaults to event context)'
10+
required: false
11+
12+
runs:
13+
using: "composite"
14+
steps:
15+
- name: Show Available Commands
16+
uses: actions/github-script@v7
17+
with:
18+
github-token: ${{ inputs.github-token }}
19+
script: |
20+
const helpText = [
21+
'# Available Commands',
22+
'',
23+
'## `/deploy`',
24+
'**Purpose:** Deploy a review app for your pull request',
25+
'',
26+
'**What it does:**',
27+
'- Creates a new review app in Control Plane',
28+
'- Deploys your changes to the review environment',
29+
'- Provides a unique URL to preview your changes',
30+
'- Shows build and deployment progress in real-time',
31+
'',
32+
'**Optional Configuration:**',
33+
'- `WAIT_TIMEOUT`: Deployment timeout in seconds (default: 900)',
34+
' - Must be a positive integer',
35+
' - Example: `/deploy timeout=1800`',
36+
'',
37+
'## `/destroy`',
38+
'**Purpose:** Remove the review app for your pull request',
39+
'',
40+
'**What it does:**',
41+
'- Deletes the review app from Control Plane',
42+
'- Cleans up associated resources',
43+
'- Updates PR with deletion status',
44+
'',
45+
'---',
46+
'## Environment Setup',
47+
'',
48+
'**Required Environment Secrets:**',
49+
'- `CPLN_TOKEN_STAGING`: Control Plane authentication token',
50+
'- `CPLN_TOKEN_PRODUCTION`: Control Plane authentication token',
51+
'',
52+
'**Required GitHub Actions Variables:**',
53+
'- `CPLN_ORG_STAGING`: Control Plane authentication token',
54+
'- `CPLN_ORG_PRODUCTION`: Control Plane authentication token',
55+
'',
56+
'**Required GitHub Actions Variables (these need to match your control_plane.yml file:**',
57+
'- `PRODUCTION_APP_NAME`: Control Plane production app name',
58+
'- `STAGING_APP_NAME`: Control Plane staging app name',
59+
'- `REVIEW_APP_PREFIX`: Control Plane review app prefix',
60+
'',
61+
'Optional: Configure `WAIT_TIMEOUT` in GitHub Actions variables to customize deployment timeout',
62+
'',
63+
'## Control Plane Integration',
64+
'',
65+
'1. Review app naming convention:',
66+
' ```',
67+
' ${{ vars.REVIEW_APP_PREFIX }}-<pr-number>',
68+
' ```',
69+
'2. Console URL: `https://console.cpln.io/console/org/{CPLN_ORG}/gvc/{APP_NAME}/-info`',
70+
'',
71+
'## Automatic Cleanup',
72+
'',
73+
'Review apps are automatically destroyed when:',
74+
'1. The pull request is closed',
75+
'2. The `/destroy` command is used',
76+
'3. A new deployment is requested (old one is cleaned up first)',
77+
'',
78+
'## Need Help?',
79+
'',
80+
'For additional assistance:',
81+
'1. Check the [Control Plane documentation](https://docs.controlplane.com/)',
82+
'2. Contact the infrastructure team',
83+
'3. Open an issue in this repository',
84+
].join('\n');
85+
86+
const issueNumber = inputs['issue-number'] ||
87+
(context.eventName === 'issue_comment' ? context.payload.issue.number : null);
88+
89+
if (issueNumber) {
90+
await github.rest.issues.createComment({
91+
owner: context.repo.owner,
92+
repo: context.repo.repo,
93+
issue_number: issueNumber,
94+
body: helpText
95+
});
96+
} else {
97+
console.log(helpText);
98+
}

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

Lines changed: 0 additions & 28 deletions
This file was deleted.

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

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@ on:
55
types: [closed]
66
issue_comment:
77
types: [created]
8-
workflow_dispatch:
9-
inputs:
10-
pr_number:
11-
description: 'PR number to delete review app for'
12-
required: true
13-
type: string
148

159
permissions:
1610
contents: read
@@ -21,8 +15,8 @@ permissions:
2115
env:
2216
CPLN_ORG: ${{ vars.CPLN_ORG_STAGING }}
2317
CPLN_TOKEN: ${{ secrets.CPLN_TOKEN_STAGING }}
24-
APP_NAME: ${{ vars.REVIEW_APP_PREFIX }}-pr-${{ github.event.pull_request.number || github.event.issue.number || inputs.pr_number }}
25-
PR_NUMBER: ${{ github.event.pull_request.number || github.event.issue.number || inputs.pr_number }}
18+
APP_NAME: qa-react-webpack-rails-tutorial-pr-${{ github.event.pull_request.number || github.event.issue.number }}
19+
PR_NUMBER: ${{ github.event.pull_request.number || github.event.issue.number }}
2620

2721
jobs:
2822
debug:
@@ -35,15 +29,37 @@ jobs:
3529
github.event.issue.pull_request &&
3630
github.event.comment.body == '/delete-review-app') ||
3731
(github.event_name == 'pull_request' &&
38-
github.event.action == 'closed') ||
39-
github.event_name == 'workflow_dispatch'
32+
github.event.action == 'closed')
4033
runs-on: ubuntu-latest
4134

4235
steps:
36+
- name: Get PR number
37+
id: pr
38+
uses: actions/github-script@v7
39+
with:
40+
script: |
41+
const prNumber = context.payload.issue.number;
42+
core.setOutput('pr_number', prNumber);
43+
core.exportVariable('PR_NUMBER', prNumber);
44+
45+
- name: Set App Name
46+
run: echo "APP_NAME=qa-react-webpack-rails-tutorial-pr-${{ env.PR_NUMBER }}" >> $GITHUB_ENV
47+
4348
- uses: actions/checkout@v4
4449

45-
- name: Validate Required Secrets and Variables
46-
uses: ./.github/actions/validate-required-vars
50+
- name: Validate Required Secrets
51+
run: |
52+
missing_secrets=()
53+
for secret in "CPLN_TOKEN" "CPLN_ORG"; do
54+
if [ -z "${!secret}" ]; then
55+
missing_secrets+=("$secret")
56+
fi
57+
done
58+
59+
if [ ${#missing_secrets[@]} -ne 0 ]; then
60+
echo "Required secrets are not set: ${missing_secrets[*]}"
61+
exit 1
62+
fi
4763
4864
- name: Setup Environment
4965
uses: ./.github/actions/setup-environment
Lines changed: 11 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,32 @@
11
# Control Plane GitHub Action
22

3-
name: Deploy to Control Plane Staging
4-
run-name: Deploy Control Plane Staging App
3+
name: Deploy Main Branch to Control Plane Staging
54

65
# Controls when the workflow will run
76
on:
7+
# Uncomment the lines you want actions that will cause the workflow to Triggers the workflow on push or pull request events but only for the main branch
88
push:
9-
branches:
10-
- '*'
9+
branches: [master]
10+
11+
# Allows you to run this workflow manually from the Actions tab
1112
workflow_dispatch:
1213

1314
# Convert the GitHub secret variables to environment variables for use by the Control Plane CLI
1415
env:
15-
APP_NAME: ${{ vars.STAGING_APP_NAME }}
16-
CPLN_TOKEN: ${{ secrets.CPLN_TOKEN_STAGING }}
1716
CPLN_ORG: ${{ vars.CPLN_ORG_STAGING }}
18-
STAGING_APP_BRANCH: ${{ vars.STAGING_APP_BRANCH }}
19-
20-
concurrency:
21-
group: deploy-staging
22-
cancel-in-progress: true
17+
CPLN_TOKEN: ${{ secrets.CPLN_TOKEN_STAGING }}
2318

2419
jobs:
25-
debug:
26-
uses: ./.github/workflows/debug-workflow.yml
27-
with:
28-
debug_enabled: false
29-
30-
validate-branch:
20+
deploy-to-control-plane-staging:
3121
runs-on: ubuntu-latest
32-
outputs:
33-
is_deployable: ${{ steps.check_branch.outputs.is_deployable }}
34-
steps:
35-
- name: Check if allowed branch
36-
id: check_branch
37-
run: |
38-
if [[ -n "${STAGING_APP_BRANCH}" ]]; then
39-
if [[ "${GITHUB_REF#refs/heads/}" == "${STAGING_APP_BRANCH}" ]]; then
40-
echo "is_deployable=true" >> $GITHUB_OUTPUT
41-
else
42-
echo "Branch '${GITHUB_REF#refs/heads/}' is not the configured deployment branch '${STAGING_APP_BRANCH}'"
43-
echo "is_deployable=false" >> $GITHUB_OUTPUT
44-
fi
45-
elif [[ "${GITHUB_REF}" == "refs/heads/main" || "${GITHUB_REF}" == "refs/heads/master" ]]; then
46-
echo "is_deployable=true" >> $GITHUB_OUTPUT
47-
else
48-
echo "Branch '${GITHUB_REF#refs/heads/}' is not main/master (no STAGING_APP_BRANCH configured)"
49-
echo "is_deployable=false" >> $GITHUB_OUTPUT
50-
fi
5122

52-
build:
53-
needs: validate-branch
54-
if: needs.validate-branch.outputs.is_deployable == 'true'
55-
runs-on: ubuntu-latest
5623
steps:
57-
- name: Checkout code
58-
uses: actions/checkout@v4
24+
- uses: actions/checkout@v4
5925
with:
60-
fetch-depth: 0
61-
62-
- name: Setup Environment
63-
uses: ./.github/actions/setup-environment
64-
with:
65-
token: ${{ secrets.CPLN_TOKEN_STAGING }}
66-
org: ${{ vars.CPLN_ORG_STAGING }}
67-
68-
- name: Build Docker Image
69-
id: build
70-
uses: ./.github/actions/build-docker-image
71-
with:
72-
app_name: ${{ env.APP_NAME }}
73-
org: ${{ vars.CPLN_ORG_STAGING }}
74-
commit: ${{ github.sha }}
75-
76-
deploy:
77-
needs: build
78-
runs-on: ubuntu-latest
79-
steps:
80-
- name: Checkout code
81-
uses: actions/checkout@v4
82-
83-
- name: Setup Environment
84-
uses: ./.github/actions/setup-environment
85-
with:
86-
token: ${{ secrets.CPLN_TOKEN_STAGING }}
87-
org: ${{ vars.CPLN_ORG_STAGING }}
26+
fetch-depth: 0 # Fetch all history for proper SHA handling
27+
ref: master # Explicitly checkout master branch
8828

89-
- name: Deploy to Control Plane
90-
uses: ./.github/actions/deploy-to-control-plane
29+
- uses: ./.github/actions/deploy-to-control-plane
9130
with:
9231
app_name: ${{ vars.STAGING_APP_NAME }}
9332
org: ${{ vars.CPLN_ORG_STAGING }}
94-
github_token: ${{ secrets.GITHUB_TOKEN }}
95-
wait_timeout: ${{ vars.WAIT_TIMEOUT || 900 }}
96-
cpln_token: ${{ secrets.CPLN_TOKEN_STAGING }}

0 commit comments

Comments
 (0)