Skip to content

Commit b7a7229

Browse files
committed
fixes
1 parent 8db0511 commit b7a7229

File tree

3 files changed

+121
-238
lines changed

3 files changed

+121
-238
lines changed
Lines changed: 19 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,114 +1,58 @@
11
# Control Plane GitHub Action
22

3-
name: Deploy-To-Control-Plane
4-
description: 'Deploys both to staging and to review apps'
3+
name: Deploy to Control Plane
4+
description: 'Deploys the application to Control Plane'
55

66
inputs:
77
app_name:
8-
description: 'The name of the app to deploy'
8+
description: 'Name of the application'
99
required: true
1010
org:
11-
description: 'The org of the app to deploy'
11+
description: 'Organization name'
1212
required: true
1313
github_token:
14-
description: 'The GitHub token for authentication'
14+
description: 'GitHub token'
1515
required: true
1616

1717
outputs:
1818
rails_url:
19-
description: 'The URL of the deployed Rails application'
19+
description: 'URL of the deployed Rails application'
2020
value: ${{ steps.deploy.outputs.rails_url }}
2121

2222
runs:
23-
using: 'composite'
23+
using: "composite"
2424
steps:
25-
- name: Setup Environment
26-
uses: ./.github/actions/setup-environment
27-
28-
- name: Get correct commit SHA
25+
- name: Get commit SHA
2926
id: get_sha
3027
shell: bash
3128
run: |
32-
if [[ "$GITHUB_EVENT_NAME" == "issue_comment" ]]; then
33-
PR_SHA=$(gh pr view ${{ env.PR_NUMBER }} --json headRefOid --jq '.headRefOid')
34-
echo "sha=$PR_SHA" >> $GITHUB_OUTPUT
35-
echo "sha_short=${PR_SHA:0:7}" >> $GITHUB_OUTPUT
36-
else
37-
echo "sha=$GITHUB_SHA" >> $GITHUB_OUTPUT
38-
echo "sha_short=${GITHUB_SHA:0:7}" >> $GITHUB_OUTPUT
39-
fi
40-
env:
41-
GITHUB_TOKEN: ${{ inputs.github_token }}
42-
PR_NUMBER: ${{ env.PR_NUMBER }}
43-
44-
# Updated caching step to v3
45-
- uses: actions/cache@v3
46-
with:
47-
path: /tmp/.docker-cache
48-
key: ${{ runner.os }}-docker-${{ hashFiles('**/Dockerfile', '**/package.json', '**/yarn.lock') }}-${{ github.sha }}
49-
restore-keys: |
50-
${{ runner.os }}-docker-${{ hashFiles('**/Dockerfile', '**/package.json', '**/yarn.lock') }}
51-
${{ runner.os }}-docker-
52-
53-
- name: cpflow setup-app
54-
shell: bash
55-
run: |
56-
if ! cpflow exists -a ${{ inputs.app_name }} ; then
57-
cpflow setup-app -a ${{ inputs.app_name }}
58-
fi
59-
60-
# Provision all infrastructure on Control Plane.
61-
# app react-webpack-rails-tutorial will be created per definition in .controlplane/controlplane.yml
62-
- name: Build and deploy
63-
shell: bash
64-
run: |
65-
cpln image docker-login
66-
# Use BUILDKIT_PROGRESS=plain to get more verbose logging of the build
67-
# BUILDKIT_PROGRESS=plain cpflow build-image -a ${{ inputs.app_name }} --commit ${{steps.get_sha.outputs.sha_short}} --org ${{inputs.org}}
68-
cpflow build-image -a ${{ inputs.app_name }} --commit=${{steps.get_sha.outputs.sha_short}} --org=${{inputs.org}}
29+
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
30+
echo "Using commit SHA: $(git rev-parse --short HEAD)"
6931
7032
- name: Deploy to Control Plane
7133
id: deploy
7234
shell: bash
7335
run: |
74-
# Debug git commit information
75-
echo "🔍 Debugging git commit information:"
76-
echo "Current directory: $(pwd)"
77-
echo "Git status:"
78-
git status
79-
echo "Git log (last 5 commits):"
80-
git log -n 5 --oneline
81-
echo "steps.get_sha.outputs.sha_short: ${{steps.get_sha.outputs.sha_short}}"
82-
echo "Full SHA from git rev-parse HEAD: $(git rev-parse HEAD)"
83-
echo "Short SHA from git rev-parse --short HEAD: $(git rev-parse --short HEAD)"
84-
85-
# Deploy rails workload
86-
echo "🚀 Starting deployment process..."
87-
echo "📦 Building image with commit SHA: ${{steps.get_sha.outputs.sha_short}}"
88-
89-
# Create a temporary file for the output
36+
# Create temp file for output
9037
TEMP_OUTPUT=$(mktemp)
9138
92-
# Run the command and tee output to both stdout and temp file
93-
set -o pipefail # Make sure we get the correct exit code from the cpln command
39+
echo "🚀 Deploying with commit: ${{steps.get_sha.outputs.sha_short}}"
9440
95-
echo "🔄 Building and deploying with cpflow..."
41+
# Build and deploy
9642
if cpflow build-image -a ${{ inputs.app_name }} --commit=${{steps.get_sha.outputs.sha_short}} --org=${{inputs.org}} | tee "$TEMP_OUTPUT" && \
9743
cpflow deploy-image -a ${{ inputs.app_name }} --run-release-phase --org ${{inputs.org}} --verbose | tee -a "$TEMP_OUTPUT"; then
9844
99-
# Extract the URL from the deployment output
100-
RAILS_URL=$(grep -o 'https://rails-[^[:space:]]*\.cpln\.app' "$TEMP_OUTPUT" || true)
45+
# Extract Rails URL
46+
RAILS_URL=$(grep -o 'https://rails-[^[:space:]]*\.cpln\.app' "$TEMP_OUTPUT")
10147
if [ -n "$RAILS_URL" ]; then
102-
echo "🌐 Found Rails deployment URL: $RAILS_URL"
10348
echo "rails_url=$RAILS_URL" >> $GITHUB_OUTPUT
104-
rm "$TEMP_OUTPUT"
49+
echo "✅ Deployment successful: $RAILS_URL"
10550
else
106-
rm "$TEMP_OUTPUT"
107-
echo "❌ Failed to extract Rails URL from deployment output"
51+
echo "❌ Failed to extract Rails URL"
10852
exit 1
10953
fi
11054
else
111-
rm "$TEMP_OUTPUT"
112-
echo "❌ Deployment command failed"
55+
echo "❌ Deployment failed"
11356
exit 1
11457
fi
58+
rm -f "$TEMP_OUTPUT"
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: 'Post Deployment Status'
2+
description: 'Posts deployment status updates to PR comments'
3+
inputs:
4+
status:
5+
description: 'Status of deployment (success/failure)'
6+
required: true
7+
rails-url:
8+
description: 'URL of the Rails app'
9+
required: false
10+
github-token:
11+
description: 'GitHub token'
12+
required: true
13+
deployment-id:
14+
description: 'Deployment ID'
15+
required: false
16+
default: 'unknown'
17+
comment-id:
18+
description: 'Comment ID to update'
19+
required: false
20+
workflow-url:
21+
description: 'Workflow URL'
22+
required: true
23+
24+
runs:
25+
using: "composite"
26+
steps:
27+
- name: Post status
28+
uses: actions/github-script@v7
29+
env:
30+
RAILS_URL: ${{ inputs.rails-url }}
31+
COMMENT_ID: ${{ inputs.comment-id }}
32+
DEPLOYMENT_ID: ${{ inputs.deployment-id }}
33+
STATUS_URL: ${{ inputs.workflow-url }}
34+
with:
35+
github-token: ${{ inputs.github-token }}
36+
script: |
37+
const isSuccess = '${{ inputs.status }}' === 'success';
38+
39+
// Create appropriate message based on status
40+
const message = isSuccess
41+
? `✅ Deployment [${process.env.DEPLOYMENT_ID}] successful!\n\n🚀 Rails app: ${process.env.RAILS_URL}\n📊 Status: ${process.env.STATUS_URL}`
42+
: `❌ Deployment [${process.env.DEPLOYMENT_ID}] failed\n\nCommit: ${context.sha.substring(0, 7)}\nWorkflow Status: ${process.env.STATUS_URL}`;
43+
44+
// Update or create comment
45+
const commentParams = {
46+
owner: context.repo.owner,
47+
repo: context.repo.repo,
48+
body: message
49+
};
50+
51+
try {
52+
if (process.env.COMMENT_ID) {
53+
await github.rest.issues.updateComment({
54+
...commentParams,
55+
comment_id: process.env.COMMENT_ID
56+
});
57+
} else {
58+
await github.rest.issues.createComment({
59+
...commentParams,
60+
issue_number: context.issue.number || context.payload.pull_request.number
61+
});
62+
}
63+
} catch (error) {
64+
console.error('Failed to update/create comment:', error);
65+
// Create a new comment if update fails
66+
await github.rest.issues.createComment({
67+
...commentParams,
68+
issue_number: context.issue.number || context.payload.pull_request.number
69+
});
70+
}

0 commit comments

Comments
 (0)