Skip to content

Commit 735e7f6

Browse files
committed
clean up duplicates
1 parent ebbc8d8 commit 735e7f6

File tree

3 files changed

+81
-124
lines changed

3 files changed

+81
-124
lines changed

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

+5-69
Original file line numberDiff line numberDiff line change
@@ -32,80 +32,16 @@ outputs:
3232
runs:
3333
using: "composite"
3434
steps:
35-
- name: Validate Required Secrets
36-
shell: bash
37-
run: |
38-
missing_secrets=()
39-
for secret in "CPLN_TOKEN" "CPLN_ORG"; do
40-
if [ -z "${!secret}" ]; then
41-
missing_secrets+=("$secret")
42-
fi
43-
done
44-
45-
if [ ${#missing_secrets[@]} -ne 0 ]; then
46-
echo "Required secrets are not set: ${missing_secrets[*]}"
47-
exit 1
48-
fi
49-
50-
- name: Setup Environment
51-
uses: ./.github/actions/setup-environment
52-
53-
- name: Get Commit SHA
54-
id: get_sha
55-
shell: bash
56-
run: ${{ github.action_path }}/scripts/get-commit-sha.sh
57-
env:
58-
GITHUB_TOKEN: ${{ inputs.github_token }}
59-
PR_NUMBER: ${{ inputs.pr_number }}
60-
6135
- name: Deploy to Control Plane
6236
id: deploy
6337
shell: bash
6438
env:
39+
APP_NAME: ${{ inputs.app_name }}
40+
CPLN_ORG: ${{ inputs.org }}
6541
CPLN_TOKEN: ${{ inputs.cpln_token }}
66-
PR_NUMBER: ${{ inputs.pr_number }}
42+
WAIT_TIMEOUT: ${{ inputs.wait_timeout }}
6743
run: |
68-
echo "🚀 Deploying app for PR #${PR_NUMBER}..."
69-
70-
# Create temp file for output
71-
TEMP_OUTPUT=$(mktemp)
72-
trap 'rm -f "${TEMP_OUTPUT}"' EXIT
73-
74-
# Deploy the application and show output in real-time while capturing it
75-
if ! cpflow deploy-image -a "${{ inputs.app_name }}" --run-release-phase --org "${{ inputs.org }}" 2>&1 | tee "${TEMP_OUTPUT}"; then
76-
echo "❌ Deployment failed for PR #${PR_NUMBER}"
77-
echo "Error output:"
78-
cat "${TEMP_OUTPUT}"
79-
exit 1
80-
fi
81-
82-
# Extract app URL from captured output
83-
REVIEW_APP_URL=$(grep -oP 'https://rails-[^[:space:]]*\.cpln\.app(?=\s|$)' "${TEMP_OUTPUT}" | head -n1)
84-
if [ -z "${REVIEW_APP_URL}" ]; then
85-
echo "❌ Failed to get app URL from deployment output"
86-
echo "Deployment output:"
87-
cat "${TEMP_OUTPUT}"
88-
exit 1
89-
fi
90-
91-
# Wait for all workloads to be ready
92-
WAIT_TIMEOUT=${WAIT_TIMEOUT:-${{ inputs.wait_timeout }}}
93-
echo "⏳ Waiting for all workloads to be ready (timeout: ${WAIT_TIMEOUT}s)..."
94-
95-
# Use timeout command with ps:wait and show output in real-time
96-
if ! timeout "${WAIT_TIMEOUT}" bash -c "cpflow ps:wait -a \"${{ inputs.app_name }}\"" 2>&1 | tee -a "${TEMP_OUTPUT}"; then
97-
TIMEOUT_EXIT=$?
98-
if [ ${TIMEOUT_EXIT} -eq 124 ]; then
99-
echo "❌ Timed out waiting for workloads after ${WAIT_TIMEOUT} seconds"
100-
else
101-
echo "❌ Workloads did not become ready for PR #${PR_NUMBER} (exit code: ${TIMEOUT_EXIT})"
102-
fi
103-
echo "Full output:"
104-
cat "${TEMP_OUTPUT}"
44+
# Run the deployment script
45+
if ! ${{ github.action_path }}/scripts/deploy.sh; then
10546
exit 1
10647
fi
107-
108-
echo "✅ Deployment successful for PR #${PR_NUMBER}"
109-
echo "🌐 App URL: ${REVIEW_APP_URL}"
110-
echo "review_app_url=${REVIEW_APP_URL}" >> $GITHUB_OUTPUT
111-
echo "REVIEW_APP_URL=${REVIEW_APP_URL}" >> $GITHUB_ENV

.github/actions/deploy-to-control-plane/scripts/get-commit-sha.sh

-34
This file was deleted.

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

+76-21
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ concurrency:
2424
cancel-in-progress: true
2525

2626
env:
27-
APP_NAME: qa-react-webpack-rails-tutorial-pr-${{ github.event.pull_request.number || github.event.issue.number || github.event.inputs.pr_number }}
27+
APP_NAME: ${{ vars.REVIEW_APP_PREFIX }}-${{ github.event.pull_request.number || github.event.issue.number || github.event.inputs.pr_number }}
2828
CPLN_TOKEN: ${{ secrets.CPLN_TOKEN_STAGING }}
2929
CPLN_ORG: ${{ vars.CPLN_ORG_STAGING }}
3030
PR_NUMBER: ${{ github.event.pull_request.number || github.event.issue.number || github.event.inputs.pr_number }}
@@ -62,27 +62,61 @@ jobs:
6262
with:
6363
fetch-depth: 0
6464

65+
- name: Validate Required Secrets and Variables
66+
shell: bash
67+
run: |
68+
missing=()
69+
70+
# Check secrets
71+
if [ -z "${{ secrets.CPLN_TOKEN_STAGING }}" ]; then
72+
missing+=("Secret: CPLN_TOKEN_STAGING")
73+
fi
74+
75+
# Check variables
76+
if [ -z "${{ vars.CPLN_ORG_STAGING }}" ]; then
77+
missing+=("Variable: CPLN_ORG_STAGING")
78+
fi
79+
80+
if [ -z "${{ vars.REVIEW_APP_PREFIX }}" ]; then
81+
missing+=("Variable: REVIEW_APP_PREFIX")
82+
fi
83+
84+
if [ ${#missing[@]} -ne 0 ]; then
85+
echo "Required secrets/variables are not set: ${missing[*]}"
86+
exit 1
87+
fi
88+
6589
- name: Get PR HEAD Ref
6690
id: getRef
6791
env:
6892
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6993
run: |
70-
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
71-
PR_NUMBER="${{ github.event.inputs.pr }}"
72-
elif [[ "${{ github.event_name }}" == "issue_comment" ]]; then
73-
PR_NUMBER="${{ github.event.issue.number }}"
74-
elif [[ "${{ github.event_name }}" == "pull_request" ]]; then
75-
PR_NUMBER="${{ github.event.pull_request.number }}"
76-
elif [[ "${{ github.event_name }}" == "push" ]]; then
77-
# For push events, find associated PR
78-
PR_DATA=$(gh pr list --head "${{ github.ref_name }}" --json number --jq '.[0].number')
79-
if [[ -n "$PR_DATA" ]]; then
80-
PR_NUMBER="$PR_DATA"
81-
else
82-
echo "Error: No PR found for branch ${{ github.ref_name }}"
94+
# Get PR number based on event type
95+
case "${{ github.event_name }}" in
96+
"workflow_dispatch")
97+
PR_NUMBER="${{ github.event.inputs.pr_number }}"
98+
;;
99+
"issue_comment")
100+
PR_NUMBER="${{ github.event.issue.number }}"
101+
;;
102+
"pull_request")
103+
PR_NUMBER="${{ github.event.pull_request.number }}"
104+
;;
105+
"push")
106+
# For push events, find associated PR
107+
PR_DATA=$(gh pr list --head "${{ github.ref_name }}" --json number --jq '.[0].number')
108+
if [[ -n "$PR_DATA" ]]; then
109+
PR_NUMBER="$PR_DATA"
110+
else
111+
echo "Error: No PR found for branch ${{ github.ref_name }}"
112+
exit 1
113+
fi
114+
;;
115+
*)
116+
echo "Error: Unsupported event type ${{ github.event_name }}"
83117
exit 1
84-
fi
85-
fi
118+
;;
119+
esac
86120
87121
if [[ -z "$PR_NUMBER" ]]; then
88122
echo "Error: Could not determine PR number"
@@ -91,7 +125,7 @@ jobs:
91125
92126
# Set environment variables
93127
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
94-
echo "APP_NAME=qa-react-webpack-rails-tutorial-pr-$PR_NUMBER" >> $GITHUB_ENV
128+
echo "APP_NAME=${{ vars.REVIEW_APP_PREFIX }}-$PR_NUMBER" >> $GITHUB_ENV
95129
96130
# Get PR data using GitHub CLI
97131
PR_DATA=$(gh pr view $PR_NUMBER --repo shakacode/react-webpack-rails-tutorial --json headRefName,headRefOid)
@@ -150,6 +184,7 @@ jobs:
150184
- name: Create Initial Comment
151185
if: env.DO_DEPLOY != 'false'
152186
uses: actions/github-script@v7
187+
id: create-comment
153188
with:
154189
script: |
155190
const result = await github.rest.issues.createComment({
@@ -160,6 +195,26 @@ jobs:
160195
});
161196
core.setOutput('comment-id', result.data.id);
162197
198+
- name: Update Comment - Building
199+
if: env.DO_DEPLOY != 'false'
200+
uses: actions/github-script@v7
201+
with:
202+
script: |
203+
const buildingMessage = [
204+
`🏗️ Building Docker image for PR #${process.env.PR_NUMBER}, commit ${process.env.PR_SHA}`,
205+
'',
206+
`📝 [View Build Logs](${process.env.WORKFLOW_URL})`,
207+
'',
208+
process.env.CONSOLE_LINK
209+
].join('\n');
210+
211+
await github.rest.issues.updateComment({
212+
owner: context.repo.owner,
213+
repo: context.repo.repo,
214+
comment_id: ${{ steps.create-comment.outputs.comment-id }},
215+
body: buildingMessage
216+
});
217+
163218
- name: Set Deployment URLs
164219
id: set-urls
165220
if: env.DO_DEPLOY != 'false'
@@ -189,7 +244,7 @@ jobs:
189244
with:
190245
script: |
191246
const buildingMessage = [
192-
'🏗️ Building Docker image for PR #' + process.env.PR_NUMBER + ', commit ' + '${{ env.COMMIT_HASH }}',
247+
'🏗️ Building Docker image for PR #' + process.env.PR_NUMBER + ', commit ' + process.env.PR_SHA,
193248
'',
194249
'📝 [View Build Logs](' + process.env.WORKFLOW_URL + ')',
195250
'',
@@ -213,7 +268,7 @@ jobs:
213268
with:
214269
app_name: ${{ env.APP_NAME }}
215270
org: ${{ env.CPLN_ORG_STAGING }}
216-
commit: ${{ env.COMMIT_HASH }}
271+
commit: ${{ env.PR_SHA }}
217272
PR_NUMBER: ${{ env.PR_NUMBER }}
218273

219274
- name: Update Status - Deploying
@@ -276,7 +331,7 @@ jobs:
276331
277332
// Define messages based on deployment status
278333
const successMessage = [
279-
'✅ Deployment complete for PR #' + prNumber + ', commit ' + '${{ env.COMMIT_HASH }}',
334+
'✅ Deployment complete for PR #' + prNumber + ', commit ' + '${{ env.PR_SHA }}',
280335
'',
281336
'🚀 [Review App for PR #' + prNumber + '](' + appUrl + ')',
282337
consoleLink,
@@ -285,7 +340,7 @@ jobs:
285340
].join('\n');
286341
287342
const failureMessage = [
288-
'❌ Deployment failed for PR #' + prNumber + ', commit ' + '${{ env.COMMIT_HASH }}',
343+
'❌ Deployment failed for PR #' + prNumber + ', commit ' + '${{ env.PR_SHA }}',
289344
'',
290345
consoleLink,
291346
'',

0 commit comments

Comments
 (0)