Github Actions Promote #97
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Help Command | |
on: | |
issue_comment: | |
types: [created] | |
workflow_dispatch: | |
inputs: | |
pr_number: | |
description: 'Pull Request number to post help comment on' | |
required: true | |
type: string | |
permissions: | |
issues: write | |
pull-requests: write | |
jobs: | |
help: | |
if: ${{ (github.event.issue.pull_request && github.event.comment.body == '/help') || github.event_name == 'workflow_dispatch' }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Show Available Commands | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const sections = { | |
commands: { | |
deploy: { | |
title: '## `/deploy`', | |
purpose: '**Purpose:** Deploy a review app for your pull request', | |
details: [ | |
'**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: { | |
title: '## `/destroy`', | |
purpose: '**Purpose:** Remove the review app for your pull request', | |
details: [ | |
'**What it does:**', | |
'- Deletes the review app from Control Plane', | |
'- Cleans up associated resources', | |
'- Updates PR with deletion status' | |
] | |
} | |
}, | |
setup: { | |
title: '## Environment Setup', | |
sections: [ | |
{ | |
title: '**Required Environment Secrets:**', | |
items: [ | |
'- `CPLN_TOKEN_STAGING`: Control Plane authentication token', | |
'- `CPLN_TOKEN_PRODUCTION`: Control Plane authentication token' | |
] | |
}, | |
{ | |
title: '**Required GitHub Actions Variables:**', | |
items: [ | |
'- `CPLN_ORG_STAGING`: Control Plane authentication token', | |
'- `CPLN_ORG_PRODUCTION`: Control Plane authentication token' | |
] | |
}, | |
{ | |
title: '**Required GitHub Actions Variables (these need to match your control_plane.yml file:**', | |
items: [ | |
'- `PRODUCTION_APP_NAME`: Control Plane production app name', | |
'- `STAGING_APP_NAME`: Control Plane staging app name', | |
'- `REVIEW_APP_PREFIX`: Control Plane review app prefix' | |
] | |
} | |
], | |
note: 'Optional: Configure `WAIT_TIMEOUT` in GitHub Actions variables to customize deployment timeout' | |
}, | |
integration: { | |
title: '## Control Plane Integration', | |
details: [ | |
'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`' | |
] | |
}, | |
cleanup: { | |
title: '## Automatic Cleanup', | |
details: [ | |
'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)' | |
] | |
}, | |
help: { | |
title: '## Need Help?', | |
details: [ | |
'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' | |
] | |
} | |
}; | |
const generateHelpText = () => { | |
const parts = ['# Available Commands', '']; | |
// Add commands | |
Object.values(sections.commands).forEach(cmd => { | |
parts.push(cmd.title, cmd.purpose, '', ...cmd.details, ''); | |
}); | |
parts.push('---'); | |
// Add setup section | |
parts.push(sections.setup.title, ''); | |
sections.setup.sections.forEach(section => { | |
parts.push(section.title, ...section.items, ''); | |
}); | |
parts.push(sections.setup.note, ''); | |
// Add remaining sections | |
['integration', 'cleanup', 'help'].forEach(section => { | |
parts.push(sections[section].title, '', ...sections[section].details, ''); | |
}); | |
return parts.join('\n'); | |
}; | |
const helpText = generateHelpText(); | |
const prNumber = context.eventName === 'workflow_dispatch' | |
? parseInt(context.payload.inputs.pr_number) | |
: context.issue.number; | |
await github.rest.issues.createComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: prNumber, | |
body: helpText | |
}); | |