Skip to content

Commit b27783e

Browse files
committed
added promotion and other fixes
1 parent e0cf883 commit b27783e

File tree

3 files changed

+73
-40
lines changed

3 files changed

+73
-40
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Control Plane GitHub Action
22

3-
name: Deploy-To-Control-Plane-Staging
3+
name: Deploy Main Branch to Control Plane Staging
44

55
# Controls when the workflow will run
66
on:

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

Lines changed: 16 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Deploy to Control Plane
1+
name: Deploy Review App to Control Plane
22

33
run-name: ${{ (github.event_name == 'pull_request' || (github.event_name == 'issue_comment' && github.event.issue.pull_request)) && 'Deploying Review App' || format('Deploying {0} to Staging App', github.ref_name) }}
44

@@ -116,32 +116,11 @@ jobs:
116116
uses: actions/github-script@v7
117117
with:
118118
script: |
119-
async function getWorkflowUrl(runId) {
120-
// Get the current job ID
121-
const jobs = await github.rest.actions.listJobsForWorkflowRun({
122-
owner: context.repo.owner,
123-
repo: context.repo.repo,
124-
run_id: runId
125-
});
126-
127-
const currentJob = jobs.data.jobs.find(job => job.status === 'in_progress');
128-
const jobId = currentJob?.id;
129-
130-
if (!jobId) {
131-
console.log('Warning: Could not find current job ID');
132-
return `${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`;
133-
}
134-
135-
return `${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}/job/${jobId}`;
136-
}
137-
138-
const prNumber = process.env.PR_NUMBER;
139-
140119
// Create initial deployment comment
141120
const comment = await github.rest.issues.createComment({
142121
owner: context.repo.owner,
143122
repo: context.repo.repo,
144-
issue_number: prNumber,
123+
issue_number: process.env.PR_NUMBER,
145124
body: '⏳ Initializing deployment...'
146125
});
147126
@@ -155,14 +134,15 @@ jobs:
155134
required_contexts: []
156135
});
157136
158-
const workflowUrl = await getWorkflowUrl(context.runId);
159-
160137
return {
161138
deploymentId: deployment.data.id,
162-
commentId: comment.data.id,
163-
workflowUrl
139+
commentId: comment.data.id
164140
};
165141
142+
- name: Set comment ID
143+
if: steps.determine_action.outputs.action == 'deploy'
144+
run: echo "COMMENT_ID=${{ fromJSON(steps.init-deployment.outputs.result).commentId }}" >> $GITHUB_ENV
145+
166146
- name: Set commit hash
167147
if: steps.determine_action.outputs.action == 'deploy'
168148
run: |
@@ -180,7 +160,7 @@ jobs:
180160
const buildingMessage = [
181161
'🏗️ Building Docker image for PR #' + process.env.PR_NUMBER + ', commit ' + '${{ env.COMMIT_HASH }}',
182162
'',
183-
'[View Build Logs](' + result.workflowUrl + ')'
163+
'[View Build Logs](' + `${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}/job/${context.job.id}` + ')'
184164
].join('\n');
185165
186166
await github.rest.issues.updateComment({
@@ -212,7 +192,7 @@ jobs:
212192
'',
213193
'⏳ Waiting for deployment to be ready...',
214194
'',
215-
'[View Deploy Logs](' + result.workflowUrl + ')'
195+
'[View Deploy Logs](' + `${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}/job/${context.job.id}` + ')'
216196
].join('\n');
217197
218198
await github.rest.issues.updateComment({
@@ -236,10 +216,10 @@ jobs:
236216
uses: actions/github-script@v7
237217
with:
238218
script: |
239-
const comment = await github.rest.issues.updateComment({
219+
await github.rest.issues.updateComment({
240220
owner: context.repo.owner,
241221
repo: context.repo.repo,
242-
comment_id: steps.init-deployment.outputs.commentId,
222+
comment_id: process.env.COMMENT_ID,
243223
body: `🚀 Review App for PR #${process.env.PR_NUMBER}: [\`${process.env.REVIEW_APP_URL}\`](${process.env.REVIEW_APP_URL})`
244224
});
245225
@@ -250,17 +230,14 @@ jobs:
250230
script: |
251231
const prNumber = process.env.PR_NUMBER;
252232
const appUrl = process.env.REVIEW_APP_URL;
253-
const workflowUrl = steps.init-deployment.outputs.workflowUrl;
233+
const workflowUrl = `${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}/job/${context.job.id}`;
254234
const isSuccess = '${{ job.status }}' === 'success';
255-
const result = ${{ steps.init-deployment.outputs.result }};
256-
const deploymentId = result.deploymentId;
257-
const commentId = result.commentId;
258235
259-
// Update deployment status
236+
// Create GitHub deployment status
260237
const deploymentStatus = {
261238
owner: context.repo.owner,
262239
repo: context.repo.repo,
263-
deployment_id: deploymentId,
240+
deployment_id: ${{ fromJSON(steps.init-deployment.outputs.result).deploymentId }},
264241
state: isSuccess ? 'success' : 'failure',
265242
environment_url: isSuccess ? appUrl : undefined,
266243
log_url: workflowUrl,
@@ -284,10 +261,10 @@ jobs:
284261
'[View Workflow Status](' + workflowUrl + ')'
285262
].join('\n');
286263
287-
// Update the comment with appropriate message
264+
// Update the existing comment
288265
await github.rest.issues.updateComment({
289266
owner: context.repo.owner,
290267
repo: context.repo.repo,
291-
comment_id: commentId,
268+
comment_id: process.env.COMMENT_ID,
292269
body: isSuccess ? successMessage : failureMessage
293270
});
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Promote Staging to Production
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
confirm_promotion:
7+
description: 'Type "promote" to confirm promotion of staging to production'
8+
required: true
9+
type: string
10+
11+
jobs:
12+
promote-to-production:
13+
runs-on: ubuntu-latest
14+
if: github.event.inputs.confirm_promotion == 'promote'
15+
16+
env:
17+
APP_NAME: react-webpack-rails-tutorial
18+
CPLN_ORG: ${{ secrets.CPLN_ORG }}
19+
UPSTREAM_TOKEN: ${{ secrets.STAGING_TOKEN }}
20+
21+
steps:
22+
- name: Checkout code
23+
uses: actions/checkout@v4
24+
25+
- name: Setup Environment
26+
uses: ./.github/actions/setup-environment
27+
env:
28+
CPLN_TOKEN: ${{ secrets.CPLN_TOKEN }}
29+
30+
- name: Promote Staging to Production
31+
id: promote
32+
run: |
33+
echo "🚀 Starting promotion from staging to production..."
34+
35+
if ! cpflow promote-app-from-upstream -a "${APP_NAME}" -t "${UPSTREAM_TOKEN}" --org "${CPLN_ORG}"; then
36+
echo "❌ Failed to promote staging to production"
37+
exit 1
38+
fi
39+
40+
echo "✅ Successfully promoted staging to production"
41+
42+
- name: Create GitHub Release
43+
if: success()
44+
env:
45+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46+
run: |
47+
# Get the current date in YYYY-MM-DD format
48+
RELEASE_DATE=$(date '+%Y-%m-%d')
49+
50+
# Create a release tag
51+
RELEASE_TAG="production-${RELEASE_DATE}"
52+
53+
# Create GitHub release
54+
gh release create "${RELEASE_TAG}" \
55+
--title "Production Release ${RELEASE_DATE}" \
56+
--notes "🚀 Production deployment on ${RELEASE_DATE}"

0 commit comments

Comments
 (0)