Skip to content

Commit 7d6eeb7

Browse files
authored
Merge 938e5ca into 586dac3
2 parents 586dac3 + 938e5ca commit 7d6eeb7

File tree

6 files changed

+131
-79
lines changed

6 files changed

+131
-79
lines changed

.controlplane/controlplane.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,24 @@ aliases:
3939

4040
apps:
4141
react-webpack-rails-tutorial-production:
42-
# Simulate Production Version
42+
# Simulate Production Version. Create with this command:
43+
# cpflow apply-template app postgres redis daily-task rails -a react-webpack-rails-tutorial-production -o shakacode-open-source-examples-production
4344
<<: *common
4445
# Don't allow overriding the org and app by ENV vars b/c production is sensitive!
4546
allow_org_override_by_env: false
4647
allow_app_override_by_env: false
4748

48-
# Use a different organization for production.
49-
cpln_org: shakacode-open-source-examples
49+
# Use a different organization only for production.
50+
cpln_org: shakacode-open-source-examples-production
5051

5152
upstream: react-webpack-rails-tutorial-staging
5253

5354
react-webpack-rails-tutorial-staging:
5455
<<: *common
55-
# QA Apps are like Heroku review apps, but the use `prefix` so you can run a commmand like
56-
# this to create a QA app for the tutorial app.
57-
# `cpflow setup gvc postgres redis rails -a qa-react-webpack-rails-tutorial-pr-1234`
5856
qa-react-webpack-rails-tutorial:
57+
# Review Apps are like Heroku review apps, but the use `prefix` so you can run a command like
58+
# this to create a QA app for the tutorial app.
59+
# `cpflow setup-app -a qa-react-webpack-rails-tutorial-pr-1234`
5960
<<: *common
6061
# Order matters!
6162
setup_app_templates:
Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,29 @@
11
name: 'Validate Required Variables'
22
description: 'Validates that all required secrets and variables for Control Plane operations'
33

4+
inputs:
5+
CPLN_TOKEN_STAGING:
6+
required: true
7+
description: 'Control Plane Staging Token'
8+
CPLN_TOKEN_PRODUCTION:
9+
required: true
10+
description: 'Control Plane Production Token'
11+
CPLN_ORG_STAGING:
12+
required: true
13+
description: 'Control Plane Staging Organization'
14+
CPLN_ORG_PRODUCTION:
15+
required: true
16+
description: 'Control Plane Production Organization'
17+
REVIEW_APP_PREFIX:
18+
required: true
19+
description: 'Review App Prefix'
20+
PRODUCTION_APP_NAME:
21+
required: true
22+
description: 'Production App Name'
23+
STAGING_APP_NAME:
24+
required: true
25+
description: 'Staging App Name'
26+
427
runs:
528
using: 'composite'
629
steps:
@@ -10,19 +33,37 @@ runs:
1033
missing=()
1134
1235
# Check required secrets
13-
if [ -z "$CPLN_TOKEN_STAGING" ]; then
36+
if [ -z "${{ inputs.CPLN_TOKEN_STAGING }}" ]; then
1437
missing+=("Secret: CPLN_TOKEN_STAGING")
1538
fi
39+
40+
if [ -z "${{ inputs.CPLN_TOKEN_PRODUCTION }}" ]; then
41+
missing+=("Secret: CPLN_TOKEN_PRODUCTION")
42+
fi
1643
1744
# Check required variables
18-
if [ -z "$CPLN_ORG_STAGING" ]; then
45+
if [ -z "${{ inputs.CPLN_ORG_STAGING }}" ]; then
1946
missing+=("Variable: CPLN_ORG_STAGING")
2047
fi
21-
if [ -z "$REVIEW_APP_PREFIX" ]; then
48+
49+
if [ -z "${{ inputs.CPLN_ORG_PRODUCTION }}" ]; then
50+
missing+=("Variable: CPLN_ORG_PRODUCTION")
51+
fi
52+
53+
if [ -z "${{ inputs.REVIEW_APP_PREFIX }}" ]; then
2254
missing+=("Variable: REVIEW_APP_PREFIX")
2355
fi
56+
57+
if [ -z "${{ inputs.PRODUCTION_APP_NAME }}" ]; then
58+
missing+=("Variable: PRODUCTION_APP_NAME")
59+
fi
60+
61+
if [ -z "${{ inputs.STAGING_APP_NAME }}" ]; then
62+
missing+=("Variable: STAGING_APP_NAME")
63+
fi
2464
2565
if [ ${#missing[@]} -ne 0 ]; then
26-
echo "Required secrets/variables are not set: ${missing[*]}"
66+
echo "Missing required secrets/variables:"
67+
printf '%s\n' "${missing[@]}"
2768
exit 1
2869
fi

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

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ jobs:
4444

4545
- name: Validate Required Secrets and Variables
4646
uses: ./.github/actions/validate-required-vars
47+
with:
48+
CPLN_TOKEN_STAGING: ${{ secrets.CPLN_TOKEN_STAGING }}
49+
CPLN_TOKEN_PRODUCTION: ${{ secrets.CPLN_TOKEN_PRODUCTION }}
50+
CPLN_ORG_STAGING: ${{ vars.CPLN_ORG_STAGING }}
51+
CPLN_ORG_PRODUCTION: ${{ vars.CPLN_ORG_PRODUCTION }}
52+
REVIEW_APP_PREFIX: ${{ vars.REVIEW_APP_PREFIX }}
53+
PRODUCTION_APP_NAME: ${{ vars.PRODUCTION_APP_NAME }}
54+
STAGING_APP_NAME: ${{ vars.STAGING_APP_NAME }}
4755

4856
- name: Setup Environment
4957
uses: ./.github/actions/setup-environment
@@ -108,7 +116,6 @@ jobs:
108116
issue_number: process.env.PR_NUMBER,
109117
owner: context.repo.owner,
110118
repo: context.repo.repo,
111-
body: '🗑️ Starting app deletion...'
112119
body: [
113120
message,
114121
'',
@@ -125,10 +132,6 @@ jobs:
125132
app_name: ${{ env.APP_NAME }}
126133
org: ${{ env.CPLN_ORG }}
127134
github_token: ${{ secrets.GITHUB_TOKEN }}
128-
env:
129-
APP_NAME: ${{ env.APP_NAME }}
130-
CPLN_ORG: ${{ secrets.CPLN_ORG }}
131-
CPLN_TOKEN: ${{ secrets.CPLN_TOKEN }}
132135

133136
- name: Update Delete Status
134137
if: always()
@@ -163,3 +166,15 @@ jobs:
163166
comment_id: ${{ fromJSON(steps.create-delete-comment.outputs.result).commentId }},
164167
body: success ? successMessage : failureMessage
165168
});
169+
170+
- name: Debug Environment
171+
run: |
172+
echo "Organization: ${{ env.CPLN_ORG }}"
173+
echo "App Name: ${{ env.APP_NAME }}"
174+
echo "PR Number: ${{ env.PR_NUMBER }}"
175+
# Don't echo the actual token, but verify it exists
176+
if [ -n "${{ env.CPLN_TOKEN }}" ]; then
177+
echo "CPLN_TOKEN is set"
178+
else
179+
echo "CPLN_TOKEN is empty"
180+
fi

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

Lines changed: 30 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ jobs:
7171

7272
- name: Validate Required Secrets and Variables
7373
uses: ./.github/actions/validate-required-vars
74+
with:
75+
CPLN_TOKEN_STAGING: ${{ secrets.CPLN_TOKEN_STAGING }}
76+
CPLN_TOKEN_PRODUCTION: ${{ secrets.CPLN_TOKEN_PRODUCTION }}
77+
CPLN_ORG_STAGING: ${{ vars.CPLN_ORG_STAGING }}
78+
CPLN_ORG_PRODUCTION: ${{ vars.CPLN_ORG_PRODUCTION }}
79+
REVIEW_APP_PREFIX: ${{ vars.REVIEW_APP_PREFIX }}
80+
PRODUCTION_APP_NAME: ${{ vars.PRODUCTION_APP_NAME }}
81+
STAGING_APP_NAME: ${{ vars.STAGING_APP_NAME }}
7482

7583
- name: Get PR HEAD Ref
7684
id: getRef
@@ -131,9 +139,9 @@ jobs:
131139
fi
132140
fi
133141
134-
# Extract and set PR data
142+
# Set PR_NUMBER and override APP_NAME with validated PR number
135143
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
136-
echo "APP_NAME=${{ vars.REVIEW_APP_PREFIX }}-$PR_NUMBER" >> $GITHUB_ENV
144+
echo "APP_NAME=${{ vars.REVIEW_APP_PREFIX }}-pr-$PR_NUMBER" >> $GITHUB_ENV
137145
echo "PR_REF=$(echo $PR_DATA | jq -r .headRefName)" >> $GITHUB_OUTPUT
138146
echo "PR_SHA=$(echo $PR_DATA | jq -r .headRefOid)" >> $GITHUB_ENV
139147
@@ -205,7 +213,7 @@ jobs:
205213
fi
206214
207215
- name: Setup Control Plane App if Not Existing
208-
if: env.DO_DEPLOY == 'true' && env.APP_EXISTS == 'false'
216+
if: env.DO_DEPLOY != 'false' && env.APP_EXISTS == 'false'
209217
env:
210218
CPLN_TOKEN: ${{ secrets.CPLN_TOKEN_STAGING }}
211219
run: |
@@ -222,7 +230,17 @@ jobs:
222230
owner: context.repo.owner,
223231
repo: context.repo.repo,
224232
issue_number: process.env.PR_NUMBER,
225-
body: '🚀 Starting deployment process...\n\n' + process.env.CONSOLE_LINK
233+
body: [
234+
`🏗️ Building Docker image for PR [#${process.env.PR_NUMBER}](${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/pull/${process.env.PR_NUMBER}), commit [${context.sha.substring(0, 7)}](${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/commit/${context.sha})`,
235+
'',
236+
'🚀 Deploying to Control Plane...',
237+
'',
238+
'⏳ Waiting for deployment to be ready...',
239+
'',
240+
`📝 [View Build and Deploy Logs](${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}/job/${context.job})`,
241+
'',
242+
process.env.CONSOLE_LINK
243+
].join('\n')
226244
});
227245
core.setOutput('comment-id', result.data.id);
228246
@@ -309,25 +327,6 @@ jobs:
309327
token: ${{ secrets.CPLN_TOKEN_STAGING }}
310328
org: ${{ vars.CPLN_ORG_STAGING }}
311329

312-
- name: Update Status - Building
313-
uses: actions/github-script@v7
314-
with:
315-
script: |
316-
const buildingMessage = [
317-
'🏗️ Building Docker image for PR #${{ needs.process-deployment.outputs.pr_number }}, commit ${{ needs.process-deployment.outputs.pr_sha }}',
318-
'',
319-
'📝 [View Build Logs](${{ env.WORKFLOW_URL }})',
320-
'',
321-
process.env.CONSOLE_LINK
322-
].join('\n');
323-
324-
await github.rest.issues.updateComment({
325-
owner: context.repo.owner,
326-
repo: context.repo.repo,
327-
comment_id: ${{ needs.process-deployment.outputs.comment_id }},
328-
body: buildingMessage
329-
});
330-
331330
- name: Build Docker Image
332331
id: build
333332
uses: ./.github/actions/build-docker-image
@@ -355,22 +354,7 @@ jobs:
355354
uses: actions/github-script@v7
356355
with:
357356
script: |
358-
const deployingMessage = [
359-
'🚀 Deploying to Control Plane...',
360-
'',
361-
'⏳ Waiting for deployment to be ready...',
362-
'',
363-
'📝 [View Deploy Logs](${{ env.WORKFLOW_URL }})',
364-
'',
365-
process.env.CONSOLE_LINK
366-
].join('\n');
367-
368-
await github.rest.issues.updateComment({
369-
owner: context.repo.owner,
370-
repo: context.repo.repo,
371-
comment_id: ${{ steps.create-comment.outputs.comment-id }},
372-
body: deployingMessage
373-
});
357+
// Remove this step since we're combining messages
374358
375359
- name: Deploy to Control Plane
376360
if: env.DO_DEPLOY != 'false'
@@ -415,21 +399,25 @@ jobs:
415399
'🚀 [Review App for PR #' + prNumber + '](' + appUrl + ')',
416400
consoleLink,
417401
'',
418-
'📋 [View Completed Action Build and Deploy Logs](' + workflowUrl + ')'
402+
'📝 [View Build and Deploy Logs](' + workflowUrl + ')',
403+
'',
404+
`📋 [View Completed Build and Deploy Logs](${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}/jobs/${context.job.id})`
419405
].join('\n');
420406
421407
const failureMessage = [
422408
'❌ Deployment failed for PR #' + prNumber + ', commit ' + '${{ env.PR_SHA }}',
423409
'',
424410
consoleLink,
425411
'',
426-
'📋 [View Deployment Logs with Errors](' + workflowUrl + ')'
412+
'📝 [View Build and Deploy Logs](' + workflowUrl + ')',
413+
'',
414+
`📋 [View Build and Deploy Logs with Errors](${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}/jobs/${context.job.id})`
427415
].join('\n');
428416
429417
// Update the existing comment
430418
await github.rest.issues.updateComment({
431419
owner: context.repo.owner,
432420
repo: context.repo.repo,
433-
comment_id: ${{ steps.create-comment.outputs.comment-id }},
421+
comment_id: ${{ needs.build.outputs.comment_id }},
434422
body: isSuccess ? successMessage : failureMessage
435423
});

.github/workflows/help-command.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ jobs:
1818
help:
1919
if: ${{ (github.event.issue.pull_request && github.event.comment.body == '/help') || github.event_name == 'workflow_dispatch' }}
2020
runs-on: ubuntu-latest
21-
21+
2222
steps:
2323
- name: Show Available Commands
2424
uses: actions/github-script@v7
2525
with:
2626
script: |
2727
const sections = {
2828
commands: {
29-
deploy: {
30-
title: '## `/deploy`',
29+
"deploy-review-app": {
30+
title: '## `/deploy-review-app`',
3131
purpose: '**Purpose:** Deploy a review app for your pull request',
3232
details: [
3333
'**What it does:**',
@@ -42,8 +42,8 @@ jobs:
4242
' - Example: `/deploy timeout=1800`'
4343
]
4444
},
45-
destroy: {
46-
title: '## `/destroy`',
45+
"delete-review-app: {
46+
title: '## `/delete-review-app`',
4747
purpose: '**Purpose:** Remove the review app for your pull request',
4848
details: [
4949
'**What it does:**',
@@ -96,17 +96,18 @@ jobs:
9696
details: [
9797
'Review apps are automatically destroyed when:',
9898
'1. The pull request is closed',
99-
'2. The `/destroy` command is used',
99+
'2. The `/delete-review-app` command is used',
100100
'3. A new deployment is requested (old one is cleaned up first)'
101101
]
102102
},
103103
help: {
104104
title: '## Need Help?',
105105
details: [
106-
'For additional assistance:',
107-
'1. Check the [Control Plane documentation](https://docs.controlplane.com/)',
106+
'For additional assistance, ',
107+
'1. Check the [Control Plane Flow documentation](https://www.shakacode.com/control-plane-flow/docs/)',
108108
'2. Contact the infrastructure team',
109-
'3. Open an issue in this repository'
109+
'3. [Open an issue in this repository](https://github.com/shakacode/control-plane-flow/issues/new)',
110+
'4. [Contact ShakaCode support](mailto:[email protected])'
110111
]
111112
}
112113
};
@@ -148,4 +149,3 @@ jobs:
148149
issue_number: prNumber,
149150
body: helpText
150151
});
151-

0 commit comments

Comments
 (0)