Skip to content

Commit e0cf883

Browse files
committed
fixes
1 parent 5f50639 commit e0cf883

File tree

4 files changed

+53
-39
lines changed

4 files changed

+53
-39
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ runs:
2222
id: build
2323
shell: bash
2424
run: |
25-
echo "🏗️ Building Docker image for PR #$PR_NUMBER (commit ${{ inputs.commit }})..."
25+
echo "🏗️ Building Docker image for PR #${PR_NUMBER} (commit ${{ inputs.commit }})..."
2626
27-
if cpflow build-image -a ${{ inputs.app_name }} --commit=${{ inputs.commit }} --org=${{ inputs.org }}; then
28-
echo "✅ Docker image build successful for PR #$PR_NUMBER (commit ${{ inputs.commit }})"
27+
if cpflow build-image -a "${{ inputs.app_name }}" --commit="${{ inputs.commit }}" --org="${{ inputs.org }}"; then
28+
echo "✅ Docker image build successful for PR #${PR_NUMBER} (commit ${{ inputs.commit }})"
2929
else
30-
echo "❌ Docker image build failed for PR #$PR_NUMBER (commit ${{ inputs.commit }})"
30+
echo "❌ Docker image build failed for PR #${PR_NUMBER} (commit ${{ inputs.commit }})"
3131
exit 1
3232
fi

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

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ inputs:
1919
default: 600
2020

2121
outputs:
22-
rails_url:
23-
description: 'URL of the deployed Rails application'
24-
value: ${{ steps.deploy.outputs.rails_url }}
22+
review_app_url:
23+
description: 'URL of the deployed application'
24+
value: ${{ steps.deploy.outputs.review_app_url }}
2525

2626
runs:
2727
using: "composite"
@@ -43,40 +43,45 @@ runs:
4343
run: |
4444
echo "🚀 Deploying app for PR #${PR_NUMBER}..."
4545
46-
# Deploy the application and capture the Rails URL
47-
if ! DEPLOY_OUTPUT=$(cpflow deploy-image -a "${{ inputs.app_name }}" --run-release-phase --org "${{ inputs.org }}" 2>&1); then
46+
# Create temp file for output
47+
TEMP_OUTPUT=$(mktemp)
48+
trap 'rm -f "${TEMP_OUTPUT}"' EXIT
49+
50+
# Deploy the application and show output in real-time while capturing it
51+
if ! cpflow deploy-image -a "${{ inputs.app_name }}" --run-release-phase --org "${{ inputs.org }}" 2>&1 | tee "${TEMP_OUTPUT}"; then
4852
echo "❌ Deployment failed for PR #${PR_NUMBER}"
4953
echo "Error output:"
50-
echo "${DEPLOY_OUTPUT}"
54+
cat "${TEMP_OUTPUT}"
5155
exit 1
5256
fi
5357
54-
# Extract Rails URL from deployment output
55-
RAILS_URL=$(echo "${DEPLOY_OUTPUT}" | grep -oP 'https://rails-[^[:space:]]*\.cpln\.app(?=\s|$)' | head -n1)
56-
if [ -z "${RAILS_URL}" ]; then
57-
echo "❌ Failed to get Rails URL from deployment output"
58+
# Extract app URL from captured output
59+
REVIEW_APP_URL=$(grep -oP 'https://rails-[^[:space:]]*\.cpln\.app(?=\s|$)' "${TEMP_OUTPUT}" | head -n1)
60+
if [ -z "${REVIEW_APP_URL}" ]; then
61+
echo "❌ Failed to get app URL from deployment output"
5862
echo "Deployment output:"
59-
echo "${DEPLOY_OUTPUT}"
63+
cat "${TEMP_OUTPUT}"
6064
exit 1
6165
fi
6266
6367
# Wait for all workloads to be ready
6468
WAIT_TIMEOUT=${WAIT_TIMEOUT:-${{ inputs.wait_timeout }}}
6569
echo "⏳ Waiting for all workloads to be ready (timeout: ${WAIT_TIMEOUT}s)..."
6670
67-
# Use timeout command with ps:wait
68-
if ! timeout "${WAIT_TIMEOUT}" bash -c "cpflow ps:wait -a \"${{ inputs.app_name }}\"" 2>&1; then
71+
# Use timeout command with ps:wait and show output in real-time
72+
if ! timeout "${WAIT_TIMEOUT}" bash -c "cpflow ps:wait -a \"${{ inputs.app_name }}\"" 2>&1 | tee -a "${TEMP_OUTPUT}"; then
6973
TIMEOUT_EXIT=$?
7074
if [ ${TIMEOUT_EXIT} -eq 124 ]; then
7175
echo "❌ Timed out waiting for workloads after ${WAIT_TIMEOUT} seconds"
7276
else
7377
echo "❌ Workloads did not become ready for PR #${PR_NUMBER} (exit code: ${TIMEOUT_EXIT})"
7478
fi
75-
echo "Last deployment output:"
76-
echo "${DEPLOY_OUTPUT}"
79+
echo "Full output:"
80+
cat "${TEMP_OUTPUT}"
7781
exit 1
7882
fi
7983
8084
echo "✅ Deployment successful for PR #${PR_NUMBER}"
81-
echo "🌐 Rails URL: ${RAILS_URL}"
82-
echo "rails_url=${RAILS_URL}" >> $GITHUB_OUTPUT
85+
echo "🌐 App URL: ${REVIEW_APP_URL}"
86+
echo "review_app_url=${REVIEW_APP_URL}" >> $GITHUB_OUTPUT
87+
echo "REVIEW_APP_URL=${REVIEW_APP_URL}" >> $GITHUB_ENV

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313

1414
set -e
1515

16-
if [ -n "$PR_NUMBER" ]; then
16+
if [ -n "${PR_NUMBER}" ]; then
1717
# If PR_NUMBER is set, get the PR's head SHA
18-
if ! PR_SHA=$(gh pr view $PR_NUMBER --json headRefOid --jq '.headRefOid'); then
18+
if ! PR_SHA=$(gh pr view "${PR_NUMBER}" --json headRefOid --jq '.headRefOid'); then
1919
echo "Failed to get PR head SHA" >&2
2020
exit 1
2121
fi
22-
echo "sha=$PR_SHA" >> "$GITHUB_OUTPUT"
22+
echo "sha=${PR_SHA}" >> "$GITHUB_OUTPUT"
2323
echo "sha_short=${PR_SHA:0:7}" >> "$GITHUB_OUTPUT"
2424
echo "Using PR head commit SHA: ${PR_SHA:0:7}"
2525
else
@@ -28,7 +28,7 @@ else
2828
echo "Failed to get current SHA" >&2
2929
exit 1
3030
fi
31-
echo "sha=$CURRENT_SHA" >> "$GITHUB_OUTPUT"
31+
echo "sha=${CURRENT_SHA}" >> "$GITHUB_OUTPUT"
3232
echo "sha_short=${CURRENT_SHA:0:7}" >> "$GITHUB_OUTPUT"
3333
echo "Using branch commit SHA: ${CURRENT_SHA:0:7}"
3434
fi

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

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -231,43 +231,51 @@ jobs:
231231
org: ${{ env.CPLN_ORG }}
232232
github_token: ${{ secrets.GITHUB_TOKEN }}
233233

234+
- name: Update Status - Success
235+
if: steps.determine_action.outputs.action == 'deploy' && success()
236+
uses: actions/github-script@v7
237+
with:
238+
script: |
239+
const comment = await github.rest.issues.updateComment({
240+
owner: context.repo.owner,
241+
repo: context.repo.repo,
242+
comment_id: steps.init-deployment.outputs.commentId,
243+
body: `🚀 Review App for PR #${process.env.PR_NUMBER}: [\`${process.env.REVIEW_APP_URL}\`](${process.env.REVIEW_APP_URL})`
244+
});
245+
234246
- name: Update Status - Deployment Complete
235247
if: steps.determine_action.outputs.action == 'deploy'
236248
uses: actions/github-script@v7
237249
with:
238250
script: |
251+
const prNumber = process.env.PR_NUMBER;
252+
const appUrl = process.env.REVIEW_APP_URL;
253+
const workflowUrl = steps.init-deployment.outputs.workflowUrl;
239254
const isSuccess = '${{ job.status }}' === 'success';
240255
const result = ${{ steps.init-deployment.outputs.result }};
241256
const deploymentId = result.deploymentId;
242257
const commentId = result.commentId;
243-
const workflowUrl = result.workflowUrl;
244-
const railsUrl = '${{ steps.deploy.outputs.rails_url }}';
245-
const prNumber = process.env.PR_NUMBER;
246258
247259
// Update deployment status
248260
const deploymentStatus = {
249261
owner: context.repo.owner,
250262
repo: context.repo.repo,
251263
deployment_id: deploymentId,
252264
state: isSuccess ? 'success' : 'failure',
253-
description: isSuccess ? '✅ Deployment successful' : '❌ Deployment failed'
265+
environment_url: isSuccess ? appUrl : undefined,
266+
log_url: workflowUrl,
267+
environment: 'review'
254268
};
255269
256-
if (isSuccess) {
257-
deploymentStatus.environment_url = railsUrl;
258-
}
259-
260270
await github.rest.repos.createDeploymentStatus(deploymentStatus);
261271
262-
// Update the initial comment
272+
// Define messages based on deployment status
263273
const successMessage = [
264-
'✅ Deployment successful for PR #' + prNumber + ', commit ' + '${{ env.COMMIT_HASH }}',
265-
'',
266-
'🚀 Rails App: [' + railsUrl + '](' + railsUrl + ')',
274+
'✅ Deployment complete for PR #' + prNumber + ', commit ' + '${{ env.COMMIT_HASH }}',
267275
'',
268-
'⚡ [Control Plane Console](https://console.cpln.io/console/org/' + process.env.CPLN_ORG + '/gvc/' + process.env.APP_NAME + '/workload)',
276+
'🚀 Review App for PR #' + prNumber + ': [`' + appUrl + '`](' + appUrl + ')',
269277
'',
270-
'[View Completed Action Build and Deploy Logs](' + workflowUrl + ')'
278+
'📋 [View Completed Action Build and Deploy Logs](' + workflowUrl + ')'
271279
].join('\n');
272280
273281
const failureMessage = [
@@ -276,6 +284,7 @@ jobs:
276284
'[View Workflow Status](' + workflowUrl + ')'
277285
].join('\n');
278286
287+
// Update the comment with appropriate message
279288
await github.rest.issues.updateComment({
280289
owner: context.repo.owner,
281290
repo: context.repo.repo,

0 commit comments

Comments
 (0)