Skip to content

Updates for Github Actions for Staging and Production #619

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 14 commits into from
6 changes: 3 additions & 3 deletions .github/workflows/delete-review-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ permissions:

env:
CPLN_ORG: ${{ secrets.CPLN_ORG }}
CPLN_TOKEN: ${{ secrets.CPLN_TOKEN }}
CPLN_TOKEN: ${{ secrets.CPLN_TOKEN_STAGING }}
APP_NAME: qa-react-webpack-rails-tutorial-pr-${{ github.event.pull_request.number || github.event.issue.number }}
PR_NUMBER: ${{ github.event.pull_request.number || github.event.issue.number }}

Expand All @@ -34,7 +34,7 @@ jobs:
- name: Validate Required Secrets
run: |
missing_secrets=()
for secret in "CPLN_TOKEN" "CPLN_ORG"; do
for secret in "CPLN_TOKEN_STAGING" "CPLN_ORG_STAGING"; do
if [ -z "${!secret}" ]; then
missing_secrets+=("$secret")
fi
Expand Down Expand Up @@ -122,7 +122,7 @@ jobs:
org: ${{ env.CPLN_ORG }}
github_token: ${{ secrets.GITHUB_TOKEN }}
env:
CPLN_TOKEN: ${{ secrets.CPLN_TOKEN }}
CPLN_TOKEN: ${{ secrets.CPLN_TOKEN_STAGING }}

- name: Update Delete Status
if: always()
Expand Down
94 changes: 47 additions & 47 deletions .github/workflows/deploy-to-control-plane.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ concurrency:
cancel-in-progress: true

env:
CPLN_ORG: ${{ secrets.CPLN_ORG }}
CPLN_TOKEN: ${{ secrets.CPLN_TOKEN }}
CPLN_ORG: ${{ secrets.CPLN_ORG_STAGING }}
CPLN_TOKEN: ${{ secrets.CPLN_TOKEN_STAGING }}

jobs:
Process-Deployment-Command:
Expand All @@ -43,32 +43,30 @@ jobs:
- name: Setup Environment
uses: ./.github/actions/setup-environment

- name: Get PR Number for Push Event
if: github.event_name == 'push'
id: get-pr
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Set PR Number for Comment Event
if: |
(github.event_name == 'issue_comment' &&
github.event.issue.pull_request &&
github.event.comment.body == '/deploy-review-app') ||
github.event_name == 'push'
run: |
# Get PR number from branch
PR_NUMBER=$(gh pr list --head ${{ github.ref_name }} --json number --jq '.[0].number')
if [ -n "$PR_NUMBER" ]; then
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
echo "APP_NAME=qa-react-webpack-rails-tutorial-pr-$PR_NUMBER" >> $GITHUB_ENV
echo "has_pr=true" >> $GITHUB_OUTPUT
if [ "${{ github.event_name }}" = "issue_comment" ]; then
echo "PR_NUMBER=${{ github.event.issue.number }}" >> $GITHUB_ENV
echo "APP_NAME=qa-react-webpack-rails-tutorial-pr-${{ github.event.issue.number }}" >> $GITHUB_ENV
else
echo "No PR found for this branch"
exit 0
# For push events, get PR number from branch
PR_NUMBER=$(gh pr list --head ${{ github.ref_name }} --json number --jq '.[0].number')
if [ -n "$PR_NUMBER" ]; then
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
echo "APP_NAME=qa-react-webpack-rails-tutorial-pr-$PR_NUMBER" >> $GITHUB_ENV
fi
fi

- name: Set PR Number for Comment Event
if: github.event_name == 'issue_comment'
run: |
echo "PR_NUMBER=${{ github.event.issue.number }}" >> $GITHUB_ENV
echo "APP_NAME=qa-react-webpack-rails-tutorial-pr-${{ github.event.issue.number }}" >> $GITHUB_ENV
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Check if Review App Exists
id: check-app
if: github.event_name == 'push' && steps.get-pr.outputs.has_pr == 'true'
if: github.event_name == 'push' && github.event_name != 'issue_comment'
env:
CPLN_TOKEN: ${{ secrets.CPLN_TOKEN }}
run: |
Expand All @@ -84,7 +82,7 @@ jobs:
(github.event_name == 'issue_comment' &&
github.event.issue.pull_request &&
github.event.comment.body == '/deploy-review-app') ||
(steps.get-pr.outputs.has_pr == 'true' && steps.check-app.outputs.app_exists == 'true')
(github.event_name == 'push' && steps.check-app.outputs.app_exists == 'true')
run: |
PR_DATA=$(gh pr view ${{ env.PR_NUMBER }} --repo ${{ github.repository }} --json headRefName,headRefOid)
echo "PR_REF=$(echo "$PR_DATA" | jq -r '.headRefName')" >> $GITHUB_OUTPUT
Expand All @@ -97,7 +95,7 @@ jobs:
(github.event_name == 'issue_comment' &&
github.event.issue.pull_request &&
github.event.comment.body == '/deploy-review-app') ||
(steps.get-pr.outputs.has_pr == 'true' && steps.check-app.outputs.app_exists == 'true')
(github.event_name == 'push' && steps.check-app.outputs.app_exists == 'true')
id: create-comment
uses: actions/github-script@v7
with:
Expand All @@ -116,15 +114,15 @@ jobs:
(github.event_name == 'issue_comment' &&
github.event.issue.pull_request &&
github.event.comment.body == '/deploy-review-app') ||
(steps.get-pr.outputs.has_pr == 'true' && steps.check-app.outputs.app_exists == 'true')
(github.event_name == 'push' && steps.check-app.outputs.app_exists == 'true')
run: echo "COMMENT_ID=${{ fromJSON(steps.create-comment.outputs.result).commentId }}" >> $GITHUB_ENV

- name: Set Workflow URL
if: |
(github.event_name == 'issue_comment' &&
github.event.issue.pull_request &&
github.event.comment.body == '/deploy-review-app') ||
(steps.get-pr.outputs.has_pr == 'true' && steps.check-app.outputs.app_exists == 'true')
(github.event_name == 'push' && steps.check-app.outputs.app_exists == 'true')
id: workflow-url
uses: actions/github-script@v7
with:
Expand All @@ -148,30 +146,35 @@ jobs:

const workflowUrl = await getWorkflowUrl(context.runId);
core.exportVariable('WORKFLOW_URL', workflowUrl);
core.exportVariable('GET_CONSOLE_LINK', `
function getConsoleLink(prNumber) {
return '🎮 [Control Plane Console](' +
'https://console.cpln.io/console/org/' + process.env.CPLN_ORG + '/gvc/' + process.env.APP_NAME + '/-info)';
}
`);

- name: Update Status - Building
- name: Set Console Link
if: |
(github.event_name == 'issue_comment' &&
github.event.issue.pull_request &&
github.event.comment.body == '/deploy-review-app') ||
(steps.get-pr.outputs.has_pr == 'true' && steps.check-app.outputs.app_exists == 'true')
(github.event_name == 'push' && steps.check-app.outputs.app_exists == 'true')
uses: actions/github-script@v7
with:
script: |
eval(process.env.GET_CONSOLE_LINK);
const consoleLink = '🎮 [Control Plane Console](https://console.cpln.io/console/org/' +
process.env.CPLN_ORG + '/gvc/' + process.env.APP_NAME + '/-info)';
core.exportVariable('CONSOLE_LINK', consoleLink);

- name: Update Status - Building
if: |
(github.event_name == 'issue_comment' &&
github.event.issue.pull_request &&
github.event.comment.body == '/deploy-review-app') ||
(github.event_name == 'push' && steps.check-app.outputs.app_exists == 'true')
uses: actions/github-script@v7
with:
script: |
const buildingMessage = [
'🏗️ Building Docker image...',
'',
'📝 [View Build Logs](' + process.env.WORKFLOW_URL + ')',
'',
getConsoleLink(process.env.PR_NUMBER)
process.env.CONSOLE_LINK
].join('\n');

await github.rest.issues.updateComment({
Expand All @@ -186,15 +189,15 @@ jobs:
(github.event_name == 'issue_comment' &&
github.event.issue.pull_request &&
github.event.comment.body == '/deploy-review-app') ||
(steps.get-pr.outputs.has_pr == 'true' && steps.check-app.outputs.app_exists == 'true')
(github.event_name == 'push' && steps.check-app.outputs.app_exists == 'true')
run: git checkout ${{ steps.getRef.outputs.PR_REF }}

- name: Build Docker Image
if: |
(github.event_name == 'issue_comment' &&
github.event.issue.pull_request &&
github.event.comment.body == '/deploy-review-app') ||
(steps.get-pr.outputs.has_pr == 'true' && steps.check-app.outputs.app_exists == 'true')
(github.event_name == 'push' && steps.check-app.outputs.app_exists == 'true')
uses: ./.github/actions/build-docker-image
with:
app_name: ${{ env.APP_NAME }}
Expand All @@ -207,20 +210,18 @@ jobs:
(github.event_name == 'issue_comment' &&
github.event.issue.pull_request &&
github.event.comment.body == '/deploy-review-app') ||
(steps.get-pr.outputs.has_pr == 'true' && steps.check-app.outputs.app_exists == 'true')
(github.event_name == 'push' && steps.check-app.outputs.app_exists == 'true')
uses: actions/github-script@v7
with:
script: |
eval(process.env.GET_CONSOLE_LINK);

const deployingMessage = [
'🚀 Deploying to Control Plane...',
'',
'⏳ Waiting for deployment to be ready...',
'',
'📝 [View Deploy Logs](' + process.env.WORKFLOW_URL + ')',
'',
getConsoleLink(process.env.PR_NUMBER)
process.env.CONSOLE_LINK
].join('\n');

await github.rest.issues.updateComment({
Expand All @@ -235,7 +236,8 @@ jobs:
(github.event_name == 'issue_comment' &&
github.event.issue.pull_request &&
github.event.comment.body == '/deploy-review-app') ||
(steps.get-pr.outputs.has_pr == 'true' && steps.check-app.outputs.app_exists == 'true')
(github.event_name == 'push' && steps.check-app.outputs.app_exists == 'true')
id: deploy
uses: ./.github/actions/deploy-to-control-plane
with:
app_name: ${{ env.APP_NAME }}
Expand All @@ -251,16 +253,14 @@ jobs:
uses: actions/github-script@v7
with:
script: |
eval(process.env.GET_CONSOLE_LINK);

const successMessage = [
'✅ Deployment successful!',
'',
'🌐 Review app is ready at: ${{ env.REVIEW_APP_URL }}',
'🌐 Review app is ready at: ${{ steps.deploy.outputs.review_app_url }}',
'',
'📝 [View App Logs](' + process.env.WORKFLOW_URL + ')',
'',
getConsoleLink(process.env.PR_NUMBER)
process.env.CONSOLE_LINK
].join('\n');

await github.rest.issues.updateComment({
Expand Down
18 changes: 2 additions & 16 deletions .github/workflows/help-command.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,35 +42,21 @@ jobs:
'- Provides a unique URL to preview your changes',
'- Shows build and deployment progress in real-time',
'',
'**Required Environment Variables:**',
'- `CPLN_TOKEN`: Control Plane authentication token',
'- `CPLN_ORG`: Control Plane organization name',
'',
'**Optional Configuration:**',
'- `WAIT_TIMEOUT`: Deployment timeout in seconds (default: 900)',
' - Must be a positive integer',
' - Can be set in GitHub Actions variables',
' - Applies to both deployment and workload readiness checks',
'',
'### `/delete-review-app`',
'Deletes the review app associated with this PR.',
'- Removes all resources from Control Plane',
'- Helpful for cleaning up when you\'re done testing',
'- Can be re-deployed later using `/deploy-review-app`',
'',
'**Required Environment Variables:**',
'- `CPLN_TOKEN`: Control Plane authentication token',
'- `CPLN_ORG`: Control Plane organization name',
'',
'### `/help`',
'Shows this detailed help message.',
'',
'---',
'## Environment Setup',
'',
'1. Set required secrets in your repository settings:',
' - `CPLN_TOKEN`',
' - `CPLN_ORG`',
' - `CPLN_TOKEN_STAGING`',
' - `CPLN_ORG_STAGING`',
'',
'2. Optional: Configure `WAIT_TIMEOUT` in GitHub Actions variables to customize deployment timeout',
'',
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/promote-staging-to-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Setup Environment
uses: ./.github/actions/setup-environment
env:
CPLN_TOKEN: ${{ secrets.CPLN_TOKEN }}
CPLN_TOKEN: ${{ secrets.CPLN_TOKEN_STAGING }}

- name: Promote Staging to Production
id: promote
Expand Down
Loading