Skip to content

Commit

Permalink
added promotion and other fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
justin808 committed Jan 26, 2025
1 parent e0cf883 commit b27783e
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy-to-control-plane-staging.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Control Plane GitHub Action

name: Deploy-To-Control-Plane-Staging
name: Deploy Main Branch to Control Plane Staging

# Controls when the workflow will run
on:
Expand Down
55 changes: 16 additions & 39 deletions .github/workflows/deploy-to-control-plane.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Deploy to Control Plane
name: Deploy Review App to Control Plane

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) }}

Expand Down Expand Up @@ -116,32 +116,11 @@ jobs:
uses: actions/github-script@v7
with:
script: |
async function getWorkflowUrl(runId) {
// Get the current job ID
const jobs = await github.rest.actions.listJobsForWorkflowRun({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: runId
});
const currentJob = jobs.data.jobs.find(job => job.status === 'in_progress');
const jobId = currentJob?.id;
if (!jobId) {
console.log('Warning: Could not find current job ID');
return `${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`;
}
return `${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}/job/${jobId}`;
}
const prNumber = process.env.PR_NUMBER;
// Create initial deployment comment
const comment = await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
issue_number: process.env.PR_NUMBER,
body: '⏳ Initializing deployment...'
});
Expand All @@ -155,14 +134,15 @@ jobs:
required_contexts: []
});
const workflowUrl = await getWorkflowUrl(context.runId);
return {
deploymentId: deployment.data.id,
commentId: comment.data.id,
workflowUrl
commentId: comment.data.id
};
- name: Set comment ID
if: steps.determine_action.outputs.action == 'deploy'
run: echo "COMMENT_ID=${{ fromJSON(steps.init-deployment.outputs.result).commentId }}" >> $GITHUB_ENV

- name: Set commit hash
if: steps.determine_action.outputs.action == 'deploy'
run: |
Expand All @@ -180,7 +160,7 @@ jobs:
const buildingMessage = [
'🏗️ Building Docker image for PR #' + process.env.PR_NUMBER + ', commit ' + '${{ env.COMMIT_HASH }}',
'',
'[View Build Logs](' + result.workflowUrl + ')'
'[View Build Logs](' + `${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}/job/${context.job.id}` + ')'
].join('\n');
await github.rest.issues.updateComment({
Expand Down Expand Up @@ -212,7 +192,7 @@ jobs:
'',
'⏳ Waiting for deployment to be ready...',
'',
'[View Deploy Logs](' + result.workflowUrl + ')'
'[View Deploy Logs](' + `${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}/job/${context.job.id}` + ')'
].join('\n');
await github.rest.issues.updateComment({
Expand All @@ -236,10 +216,10 @@ jobs:
uses: actions/github-script@v7
with:
script: |
const comment = await github.rest.issues.updateComment({
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: steps.init-deployment.outputs.commentId,
comment_id: process.env.COMMENT_ID,
body: `🚀 Review App for PR #${process.env.PR_NUMBER}: [\`${process.env.REVIEW_APP_URL}\`](${process.env.REVIEW_APP_URL})`
});
Expand All @@ -250,17 +230,14 @@ jobs:
script: |
const prNumber = process.env.PR_NUMBER;
const appUrl = process.env.REVIEW_APP_URL;
const workflowUrl = steps.init-deployment.outputs.workflowUrl;
const workflowUrl = `${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}/job/${context.job.id}`;
const isSuccess = '${{ job.status }}' === 'success';
const result = ${{ steps.init-deployment.outputs.result }};
const deploymentId = result.deploymentId;
const commentId = result.commentId;
// Update deployment status
// Create GitHub deployment status
const deploymentStatus = {
owner: context.repo.owner,
repo: context.repo.repo,
deployment_id: deploymentId,
deployment_id: ${{ fromJSON(steps.init-deployment.outputs.result).deploymentId }},
state: isSuccess ? 'success' : 'failure',
environment_url: isSuccess ? appUrl : undefined,
log_url: workflowUrl,
Expand All @@ -284,10 +261,10 @@ jobs:
'[View Workflow Status](' + workflowUrl + ')'
].join('\n');
// Update the comment with appropriate message
// Update the existing comment
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: commentId,
comment_id: process.env.COMMENT_ID,
body: isSuccess ? successMessage : failureMessage
});
56 changes: 56 additions & 0 deletions .github/workflows/promote-staging-to-production.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Promote Staging to Production

on:
workflow_dispatch:
inputs:
confirm_promotion:
description: 'Type "promote" to confirm promotion of staging to production'
required: true
type: string

jobs:
promote-to-production:
runs-on: ubuntu-latest
if: github.event.inputs.confirm_promotion == 'promote'

env:
APP_NAME: react-webpack-rails-tutorial
CPLN_ORG: ${{ secrets.CPLN_ORG }}
UPSTREAM_TOKEN: ${{ secrets.STAGING_TOKEN }}

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Environment
uses: ./.github/actions/setup-environment
env:
CPLN_TOKEN: ${{ secrets.CPLN_TOKEN }}

- name: Promote Staging to Production
id: promote
run: |
echo "🚀 Starting promotion from staging to production..."
if ! cpflow promote-app-from-upstream -a "${APP_NAME}" -t "${UPSTREAM_TOKEN}" --org "${CPLN_ORG}"; then
echo "❌ Failed to promote staging to production"
exit 1
fi
echo "✅ Successfully promoted staging to production"
- name: Create GitHub Release
if: success()
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Get the current date in YYYY-MM-DD format
RELEASE_DATE=$(date '+%Y-%m-%d')
# Create a release tag
RELEASE_TAG="production-${RELEASE_DATE}"
# Create GitHub release
gh release create "${RELEASE_TAG}" \
--title "Production Release ${RELEASE_DATE}" \
--notes "🚀 Production deployment on ${RELEASE_DATE}"

0 comments on commit b27783e

Please sign in to comment.