Skip to content

Handle PRE env deployment commands in PR Comments #3

Handle PRE env deployment commands in PR Comments

Handle PRE env deployment commands in PR Comments #3

name: Handle Deployment Commands in PR Comments
on:
issue_comment:
types:
- created
jobs:
handle-slash-command:
runs-on: ubuntu-latest
steps:
# Step 1: Verify Command in Comment
- name: Check for `/deploy-pre` Command
id: check_command
uses: actions/github-script@v6
with:
script: |
const comment = context.payload.comment.body;
if (comment.trim() === '/deploy-pre') {
return { valid: true };
}
return { valid: false };
result-encoding: json
# Step 2: Get Branch from PR
- name: Extract PR Branch
if: steps.check_command.outputs.valid == 'true'
id: pr_details
uses: actions/github-script@v6
with:
script: |
const pr = context.payload.issue.pull_request;
if (!pr) {
throw new Error("This command can only be used on a pull request.");
}
return pr.head.ref;
result-encoding: string
# Step 3: Trigger Deploy Workflow
- name: Trigger Deploy Workflow
if: steps.check_command.outputs.valid == 'true'
uses: actions/github-script@v6
with:
script: |
github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: "deploy-pre.yml",
ref: "${{ steps.pr_details.outputs.result }}"
})