diff --git a/.github/workflows/deploy-to-control-plane-staging.yml b/.github/workflows/deploy-to-control-plane-staging.yml index 2a6a5e80..095c635a 100644 --- a/.github/workflows/deploy-to-control-plane-staging.yml +++ b/.github/workflows/deploy-to-control-plane-staging.yml @@ -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: diff --git a/.github/workflows/deploy-to-control-plane.yml b/.github/workflows/deploy-to-control-plane.yml index 5471fc26..b0f4f74b 100644 --- a/.github/workflows/deploy-to-control-plane.yml +++ b/.github/workflows/deploy-to-control-plane.yml @@ -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) }} @@ -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...' }); @@ -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: | @@ -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({ @@ -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({ @@ -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})` }); @@ -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, @@ -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 }); diff --git a/.github/workflows/promote-staging-to-production.yml b/.github/workflows/promote-staging-to-production.yml new file mode 100644 index 00000000..04148067 --- /dev/null +++ b/.github/workflows/promote-staging-to-production.yml @@ -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}"