Skip to content
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

More work on github actions #621

Merged
merged 3 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions .github/actions/help-command/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: 'Show Help Command'
description: 'Displays help information for available commands in PR comments'

inputs:
github-token:
description: 'GitHub token for posting comments'
required: true

runs:
using: "composite"
steps:
- name: Show Available Commands
uses: actions/github-script
with:
github-token: ${{ inputs.github-token }}
script: |
const helpText = [
'# Available Commands',
'',
'## `/deploy`',
'**Purpose:** Deploy a review app for your pull request',
'',
'**What it does:**',
'- Creates a new review app in Control Plane',
'- Deploys your changes to the review environment',
'- Provides a unique URL to preview your changes',
'- Shows build and deployment progress in real-time',
'',
'**Optional Configuration:**',
'- `WAIT_TIMEOUT`: Deployment timeout in seconds (default: 900)',
' - Must be a positive integer',
' - Example: `/deploy timeout=1800`',
'',
'## `/destroy`',
'**Purpose:** Remove the review app for your pull request',
'',
'**What it does:**',
'- Deletes the review app from Control Plane',
'- Cleans up associated resources',
'- Updates PR with deletion status',
'',
'---',
'## Environment Setup',
'',
'**Required Environment Secrets:**',
'- `CPLN_TOKEN_STAGING`: Control Plane authentication token',
'- `CPLN_TOKEN_PRODUCTION`: Control Plane authentication token',
'',
'**Required GitHub Actions Variables:**',
'- `CPLN_ORG_STAGING`: Control Plane authentication token',
'- `CPLN_ORG_PRODUCTION`: Control Plane authentication token',
'',
'**Required GitHub Actions Variables (these need to match your control_plane.yml file:**',
'- `PRODUCTION_APP_NAME`: Control Plane production app name',
'- `STAGING_APP_NAME`: Control Plane staging app name',
'- `REVIEW_APP_PREFIX`: Control Plane review app prefix',
'',
'Optional: Configure `WAIT_TIMEOUT` in GitHub Actions variables to customize deployment timeout',
'',
'## Control Plane Integration',
'',
'1. Review app naming convention:',
' ```',
' ${{ vars.REVIEW_APP_PREFIX }}-<pr-number>',
' ```',
'2. Console URL: `https://console.cpln.io/console/org/{CPLN_ORG}/gvc/{APP_NAME}/-info`',
'',
'## Automatic Cleanup',
'',
'Review apps are automatically destroyed when:',
'1. The pull request is closed',
'2. The `/destroy` command is used',
'3. A new deployment is requested (old one is cleaned up first)',
'',
'## Need Help?',
'',
'For additional assistance:',
'1. Check the [Control Plane documentation](https://docs.controlplane.com/)',
'2. Contact the infrastructure team',
'3. Open an issue in this repository',
].join('\n');

const context = github.context;
if (context.eventName === 'issue_comment') {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.issue.number,
body: helpText
});
} else {
console.log(helpText);
}
4 changes: 2 additions & 2 deletions .github/workflows/delete-review-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
fi

- name: Setup Environment
uses: ./.github/actions/setup-environment@justin808-working-for-deploys
uses: ./.github/actions/setup-environment
with:
org: ${{ env.CPLN_ORG }}
token: ${{ env.CPLN_TOKEN }}
Expand Down Expand Up @@ -132,7 +132,7 @@ jobs:
return { commentId: comment.data.id };

- name: Delete Review App
uses: ./.github/actions/delete-control-plane-app@justin808-working-for-deploys
uses: ./.github/actions/delete-control-plane-app
with:
app_name: ${{ env.APP_NAME }}
org: ${{ env.CPLN_ORG }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-to-control-plane-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
fetch-depth: 0 # Fetch all history for proper SHA handling
ref: master # Explicitly checkout master branch

- uses: ./.github/actions/deploy-to-control-plane@justin808-working-for-deploys
- uses: ./.github/actions/deploy-to-control-plane
with:
app_name: ${{ vars.STAGING_APP_NAME }}
org: ${{ vars.CPLN_ORG_STAGING }}
6 changes: 3 additions & 3 deletions .github/workflows/deploy-to-control-plane.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || steps.getRef.outputs.PR_REF || github.ref }}

- name: Setup Environment
uses: ./.github/actions/setup-environment@justin808-working-for-deploys
uses: ./.github/actions/setup-environment
with:
token: ${{ env.CPLN_TOKEN }}
org: ${{ env.CPLN_ORG }}
Expand Down Expand Up @@ -228,7 +228,7 @@ jobs:
github.event.issue.pull_request &&
github.event.comment.body == '/deploy-review-app') ||
(steps.check-app.outputs.app_exists == 'true')
uses: ./.github/actions/build-docker-image@justin808-working-for-deploys
uses: ./.github/actions/build-docker-image
with:
app_name: ${{ env.APP_NAME }}
org: ${{ env.CPLN_ORG }}
Expand Down Expand Up @@ -269,7 +269,7 @@ jobs:
github.event.issue.pull_request &&
github.event.comment.body == '/deploy-review-app') ||
(steps.check-app.outputs.app_exists == 'true')
uses: ./.github/actions/deploy-to-control-plane@justin808-working-for-deploys
uses: ./.github/actions/deploy-to-control-plane
with:
app_name: ${{ env.APP_NAME }}
org: ${{ env.CPLN_ORG }}
Expand Down
95 changes: 5 additions & 90 deletions .github/workflows/help-command.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,95 +22,10 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Identify Workflow Branch
run: |
echo "Workflow branch ref: ${{ github.ref }}"
- name: Checkout
uses: actions/checkout

- name: Show Available Commands
uses: actions/github-script@v7
- name: Show Help Information
uses: ./.github/actions/help-command
with:
script: |
try {
console.log('Creating detailed help message...');
const helpMessage = [
'# 📚 Detailed Review App Commands Guide',
'',
'This is a detailed guide to using review app commands. For a quick reference, see the message posted when your PR was created.',
'',
'## Available Commands',
'',
'### `/deploy-review-app`',
'Deploys your PR branch to a review environment on Control Plane.',
'- Creates a new review app if one doesn\'t exist',
'- Updates the existing review app if it already exists',
'- Provides a unique URL to preview your changes',
'- Shows build and deployment progress in real-time',
'',
'**Required Environment Secrets:**',
'- `CPLN_TOKEN_STAGING`: Control Plane authentication token',
'- `CPLN_TOKEN_PRODUCTION`: Control Plane authentication token',
'',
'**Required GitHub Actions Variables:**',
'- `CPLN_ORG_STAGING`: Control Plane authentication token',
'- `CPLN_ORG_PRODUCTION`: Control Plane authentication token',
'',
'**Required GitHub Actions Variables (these need to match your control_plane.yml file:**',
'- `PRODUCTION_APP_NAME`: Control Plane production app name',
'- `STAGING_APP_NAME`: Control Plane staging app name',
'- `REVIEW_APP_PREFIX`: Control Plane review app prefix',
'',
'**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`',
'',
'2. Optional: Configure `WAIT_TIMEOUT` in GitHub Actions variables to customize deployment timeout',
'',
'## Control Plane Integration',
'',
'Review apps are deployed to Control Plane with the following configuration:',
'- App Name Format: `qa-react-webpack-rails-tutorial-pr-{PR_NUMBER}`',
'- Console URL: `https://console.cpln.io/console/org/{CPLN_ORG}/gvc/{APP_NAME}/-info`',
'',
'## Automatic Cleanup',
'',
'Review apps are automatically deleted when:',
'- The PR is closed (merged or not merged)',
'- The PR is stale (via nightly cleanup job)',
'',
'For more information, see the [React on Rails Tutorial documentation](https://github.com/shakacode/react-on-rails/tree/master/react-webpack-rails-tutorial)'
].join('\n');

await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: helpMessage
});

console.log('Help message posted successfully');
} catch (error) {
console.error('Error posting help message:', error);
core.setFailed(`Failed to post help message: ${error.message}`);
}
github-token: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/nightly-remove-stale-review-apps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
uses: actions/checkout@v4

- name: Setup Environment
uses: ./.github/actions/setup-environment@justin808-working-for-deploys
uses: ./.github/actions/setup-environment

- name: Get Stale PRs
id: stale_prs
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 @@ -23,7 +23,7 @@ jobs:
uses: actions/checkout@v4

- name: Setup Environment
uses: ./.github/actions/setup-environment@justin808-working-for-deploys
uses: ./.github/actions/setup-environment
env:
CPLN_TOKEN: ${{ secrets.CPLN_TOKEN }}

Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/review-app-help.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ jobs:
'Remove the review app when done',
'',
'### `/help`',
'Show detailed documentation',
'Show detailed instructions, environment setup, and configuration options.'
'',
'---',
'**Note:** Type `/help` for detailed instructions, environment setup, and configuration options.'
].join('\n');

await github.rest.issues.createComment({
Expand Down
Loading