Skip to content

Commit 87662fa

Browse files
committed
Updates, fix crash
1 parent f77a610 commit 87662fa

File tree

2 files changed

+77
-21
lines changed

2 files changed

+77
-21
lines changed

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

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ inputs:
1414
description: 'The GitHub token for authentication'
1515
required: true
1616

17+
outputs:
18+
rails_url:
19+
description: 'The URL of the deployed Rails application'
20+
value: ${{ steps.deploy.outputs.rails_url }}
21+
1722
runs:
1823
using: 'composite'
1924
steps:
@@ -63,7 +68,42 @@ runs:
6368
cpflow build-image -a ${{ inputs.app_name }} --commit=${{steps.get_sha.outputs.sha_short}} --org=${{inputs.org}}
6469
6570
- name: Deploy to Control Plane
71+
id: deploy
6672
shell: bash
6773
run: |
68-
echo "Deploying to Control Plane"
69-
cpflow deploy-image -a ${{ inputs.app_name }} --run-release-phase --org ${{inputs.org}} --verbose
74+
# Deploy rails workload
75+
echo "🚀 Starting deployment process..."
76+
echo "📦 Building image with commit SHA: ${{steps.get_sha.outputs.sha_short}}"
77+
78+
# Create a temporary file for the output
79+
TEMP_OUTPUT=$(mktemp)
80+
81+
# Run the command and tee output to both stdout and temp file
82+
set -o pipefail # Make sure we get the correct exit code from the cpln command
83+
84+
echo "🔄 Updating Rails workload..."
85+
if cpln workload update rails --gvc ${{ inputs.app_name }} --org ${{ inputs.org }} --set spec.containers.rails.image=/org/${{ inputs.org }}/image/${{ inputs.app_name }}:${{steps.get_sha.outputs.sha_short}} | tee "$TEMP_OUTPUT"; then
86+
# Extract the URL from the deployment output
87+
RAILS_URL=$(grep -o 'https://rails-[^[:space:]]*\.cpln\.app' "$TEMP_OUTPUT" || true)
88+
if [ -n "$RAILS_URL" ]; then
89+
echo "🌐 Found Rails deployment URL: $RAILS_URL"
90+
echo "rails_url=$RAILS_URL" >> $GITHUB_OUTPUT
91+
92+
echo "🔄 Updating daily-task workload..."
93+
if cpln workload update daily-task --gvc ${{ inputs.app_name }} --org ${{ inputs.org }} --set spec.containers.daily-task.image=/org/${{ inputs.org }}/image/${{ inputs.app_name }}:${{steps.get_sha.outputs.sha_short}} | tee "$TEMP_OUTPUT"; then
94+
echo "✅ Both workloads updated successfully!"
95+
else
96+
echo "⚠️ Daily-task update failed, but Rails deployment was successful"
97+
fi
98+
99+
rm "$TEMP_OUTPUT"
100+
else
101+
rm "$TEMP_OUTPUT"
102+
echo "❌ Failed to extract Rails URL from deployment output"
103+
exit 1
104+
fi
105+
else
106+
rm "$TEMP_OUTPUT"
107+
echo "❌ Rails deployment failed"
108+
exit 1
109+
fi

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

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -141,35 +141,48 @@ jobs:
141141
org: ${{ env.CPLN_ORG }}
142142
github_token: ${{ secrets.GITHUB_TOKEN }}
143143

144-
- name: Extract deployment URL
145-
id: extract-url
146-
run: |
147-
RAILS_URL=$(echo "${{ steps.deploy.outputs.deployment_output }}" | grep -o 'https://rails-[^[:space:]]*\.cpln\.app')
148-
echo "RAILS_URL=$RAILS_URL" >> $GITHUB_ENV
149-
echo "rails_url=$RAILS_URL" >> $GITHUB_OUTPUT
150-
151144
- name: Update PR commit message
152145
if: success()
153146
env:
154147
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
148+
RAILS_URL: ${{ steps.deploy.outputs.rails_url }}
155149
run: |
156-
PR_SHA=$(gh pr view ${{ env.PR_NUMBER }} --json commits --jq '.commits[-1].oid')
157-
git config user.name "GitHub Actions"
158-
git config user.email "[email protected]"
159-
git pull --rebase
160-
git commit --amend -m "Rails review app deployed to ${{ env.RAILS_URL }}"
161-
git push --force-with-lease origin HEAD
150+
if [ -n "$RAILS_URL" ]; then
151+
echo "🔄 Updating PR commit message with deployment URL..."
152+
PR_SHA=$(gh pr view ${{ env.PR_NUMBER }} --json commits --jq '.commits[-1].oid')
153+
if [ -n "$PR_SHA" ]; then
154+
git config user.name "GitHub Actions"
155+
git config user.email "[email protected]"
156+
git pull --rebase
157+
git commit --amend -m "Rails review app deployed to $RAILS_URL"
158+
if git push --force-with-lease origin HEAD; then
159+
echo "✅ Successfully updated commit message"
160+
else
161+
echo "❌ Failed to push updated commit message"
162+
exit 1
163+
fi
164+
else
165+
echo "❌ Failed to get PR SHA"
166+
exit 1
167+
fi
168+
else
169+
echo "❌ No Rails URL found in deployment output"
170+
exit 1
171+
fi
162172
163173
- name: Update deployment status success
164174
if: success()
165175
uses: actions/github-script@v7
176+
env:
177+
RAILS_URL: ${{ steps.deploy.outputs.rails_url }}
166178
with:
167179
script: |
168180
const message = `✅ Deployment successful!
181+
169182
Environment: review-app
170183
Commit: ${context.sha.substring(0, 7)}
171-
URL: ${{ env.RAILS_URL }}
172-
Status: ${process.env.statusUrl}`;
184+
Rails URL: ${process.env.RAILS_URL}
185+
Workflow Status: ${process.env.statusUrl}`;
173186
174187
await github.rest.issues.createComment({
175188
issue_number: context.issue.number || context.payload.pull_request.number,
@@ -183,18 +196,21 @@ jobs:
183196
repo: context.repo.repo,
184197
deployment_id: ${{ steps.create-deployment.outputs.result }},
185198
state: 'success',
186-
environment_url: '${{ env.RAILS_URL }}',
187-
description: 'Deployment successful'
199+
environment_url: process.env.RAILS_URL,
200+
description: 'Deployment successful'
188201
});
189202
190203
- name: Update deployment status failure
191204
if: failure()
192205
uses: actions/github-script@v7
206+
env:
207+
RAILS_URL: ${{ steps.deploy.outputs.rails_url }}
193208
with:
194209
script: |
195210
const message = `❌ Deployment failed
211+
196212
Commit: ${context.sha.substring(0, 7)}
197-
Status: ${process.env.statusUrl}`;
213+
Workflow Status: ${process.env.statusUrl}`;
198214
199215
await github.rest.issues.createComment({
200216
issue_number: context.issue.number || context.payload.pull_request.number,
@@ -208,5 +224,5 @@ jobs:
208224
repo: context.repo.repo,
209225
deployment_id: ${{ steps.create-deployment.outputs.result }},
210226
state: 'failure',
211-
description: 'Deployment failed'
227+
description: 'Deployment failed'
212228
});

0 commit comments

Comments
 (0)