Skip to content

Commit 304e642

Browse files
committed
fixes
1 parent c25211f commit 304e642

File tree

5 files changed

+118
-39
lines changed

5 files changed

+118
-39
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Build Docker Image
2+
description: 'Builds a Docker image for the application'
3+
4+
inputs:
5+
app_name:
6+
description: 'Name of the application'
7+
required: true
8+
org:
9+
description: 'Organization name'
10+
required: true
11+
commit:
12+
description: 'Commit SHA to tag the image with'
13+
required: true
14+
15+
runs:
16+
using: "composite"
17+
steps:
18+
- name: Build Docker Image
19+
id: build
20+
shell: bash
21+
run: |
22+
# Redirect build output to a log file to keep Actions log clean
23+
LOG_FILE=$(mktemp)
24+
echo "🏗️ Building Docker image... (detailed logs will be shown at the end if there's an error)"
25+
26+
if cpflow build-image -a ${{ inputs.app_name }} --commit=${{ inputs.commit }} --org=${{ inputs.org }} > "$LOG_FILE" 2>&1; then
27+
echo "✅ Docker image build successful"
28+
else
29+
BUILD_EXIT_CODE=$?
30+
echo "❌ Docker image build failed"
31+
echo "==== Build Logs ===="
32+
cat "$LOG_FILE"
33+
rm -f "$LOG_FILE"
34+
exit $BUILD_EXIT_CODE
35+
fi
36+
rm -f "$LOG_FILE"

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

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -29,49 +29,25 @@ runs:
2929
id: get_sha
3030
shell: bash
3131
run: |
32-
if [ -n "$PR_NUMBER" ]; then
33-
# If PR_NUMBER is set, get the PR's head SHA
34-
PR_SHA=$(gh pr view $PR_NUMBER --json headRefOid --jq '.headRefOid')
35-
echo "sha=$PR_SHA" >> $GITHUB_OUTPUT
36-
echo "sha_short=${PR_SHA:0:7}" >> $GITHUB_OUTPUT
37-
echo "Using PR head commit SHA: ${PR_SHA:0:7}"
38-
else
39-
# For direct branch deployments, use the current commit SHA
40-
CURRENT_SHA=$(git rev-parse HEAD)
41-
echo "sha=$CURRENT_SHA" >> $GITHUB_OUTPUT
42-
echo "sha_short=${CURRENT_SHA:0:7}" >> $GITHUB_OUTPUT
43-
echo "Using branch commit SHA: ${CURRENT_SHA:0:7}"
44-
fi
32+
chmod +x ${{ github.action_path }}/scripts/get-commit-sha.sh
33+
${{ github.action_path }}/scripts/get-commit-sha.sh
4534
env:
4635
GITHUB_TOKEN: ${{ inputs.github_token }}
4736
PR_NUMBER: ${{ env.PR_NUMBER }}
4837

4938
- name: Build Docker Image
50-
id: build
51-
shell: bash
52-
run: |
53-
echo "🏗️ Building Docker image..."
54-
cpflow build-image -a ${{ inputs.app_name }} --commit=${{ github.sha }} --org=${{ inputs.org }}
39+
uses: ./.github/actions/build-docker-image
40+
with:
41+
app_name: ${{ inputs.app_name }}
42+
org: ${{ inputs.org }}
43+
commit: ${{ github.sha }}
5544

5645
- name: Deploy to Control Plane
5746
id: deploy
5847
shell: bash
5948
run: |
60-
echo "🚀 Deploying to Control Plane..."
61-
TEMP_OUTPUT=$(mktemp)
62-
63-
if cpflow deploy-image -a ${{ inputs.app_name }} --run-release-phase --org ${{ inputs.org }} --verbose | tee "$TEMP_OUTPUT"; then
64-
# Extract Rails URL
65-
RAILS_URL=$(grep -o 'https://rails-[^[:space:]]*\.cpln\.app' "$TEMP_OUTPUT")
66-
if [ -n "$RAILS_URL" ]; then
67-
echo "rails_url=$RAILS_URL" >> $GITHUB_OUTPUT
68-
echo "✅ Deployment successful: $RAILS_URL"
69-
else
70-
echo "❌ Failed to extract Rails URL"
71-
exit 1
72-
fi
73-
else
74-
echo "❌ Deployment failed"
75-
exit 1
76-
fi
77-
rm -f "$TEMP_OUTPUT"
49+
chmod +x ${{ github.action_path }}/scripts/deploy.sh
50+
${{ github.action_path }}/scripts/deploy.sh
51+
env:
52+
APP_NAME: ${{ inputs.app_name }}
53+
CPLN_ORG: ${{ inputs.org }}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
3+
# This script handles the deployment to Control Plane and extracts the Rails URL
4+
#
5+
# Required environment variables:
6+
# - APP_NAME: Name of the application to deploy
7+
# - CPLN_ORG: Control Plane organization
8+
#
9+
# Outputs:
10+
# - rails_url: URL of the deployed Rails application
11+
12+
set -e
13+
14+
echo "🚀 Deploying to Control Plane..."
15+
TEMP_OUTPUT=$(mktemp)
16+
17+
# Deploy the application and capture output
18+
if cpflow deploy-image -a "$APP_NAME" --run-release-phase --org "$CPLN_ORG" --verbose | tee "$TEMP_OUTPUT"; then
19+
# Extract Rails URL from deployment output
20+
RAILS_URL=$(grep -o 'https://rails-[^[:space:]]*\.cpln\.app' "$TEMP_OUTPUT")
21+
if [ -n "$RAILS_URL" ]; then
22+
echo "rails_url=$RAILS_URL" >> $GITHUB_OUTPUT
23+
echo "✅ Deployment successful: $RAILS_URL"
24+
else
25+
echo "❌ Failed to extract Rails URL"
26+
exit 1
27+
fi
28+
else
29+
echo "❌ Deployment failed"
30+
exit 1
31+
fi
32+
33+
# Clean up temporary file
34+
rm -f "$TEMP_OUTPUT"
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
# This script retrieves the commit SHA for deployment
4+
# It handles both PR and direct branch deployments
5+
#
6+
# Required environment variables:
7+
# - PR_NUMBER: Pull request number (optional)
8+
# - GITHUB_TOKEN: GitHub token for API access
9+
#
10+
# Outputs:
11+
# - sha: Full commit SHA
12+
# - sha_short: Short (7 char) commit SHA
13+
14+
set -e
15+
16+
if [ -n "$PR_NUMBER" ]; then
17+
# If PR_NUMBER is set, get the PR's head SHA
18+
PR_SHA=$(gh pr view $PR_NUMBER --json headRefOid --jq '.headRefOid')
19+
echo "sha=$PR_SHA" >> $GITHUB_OUTPUT
20+
echo "sha_short=${PR_SHA:0:7}" >> $GITHUB_OUTPUT
21+
echo "Using PR head commit SHA: ${PR_SHA:0:7}"
22+
else
23+
# For direct branch deployments, use the current commit SHA
24+
CURRENT_SHA=$(git rev-parse HEAD)
25+
echo "sha=$CURRENT_SHA" >> $GITHUB_OUTPUT
26+
echo "sha_short=${CURRENT_SHA:0:7}" >> $GITHUB_OUTPUT
27+
echo "Using branch commit SHA: ${CURRENT_SHA:0:7}"
28+
fi

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,19 @@ jobs:
140140
const prNumber = process.env.PR_NUMBER;
141141
142142
// Update deployment status
143-
await github.rest.repos.createDeploymentStatus({
143+
const deploymentStatus = {
144144
owner: context.repo.owner,
145145
repo: context.repo.repo,
146146
deployment_id: deploymentId,
147147
state: isSuccess ? 'success' : 'failure',
148-
...(isSuccess && { environment_url: railsUrl }),
149148
description: isSuccess ? '✅ Deployment successful' : '❌ Deployment failed'
150-
});
149+
};
150+
151+
if (isSuccess) {
152+
deploymentStatus.environment_url = railsUrl;
153+
}
154+
155+
await github.rest.repos.createDeploymentStatus(deploymentStatus);
151156
152157
// Update the initial comment
153158
const message = isSuccess

0 commit comments

Comments
 (0)