Skip to content

First deployment on PRE via GitHub actions triggered by a chat command on PR #10

First deployment on PRE via GitHub actions triggered by a chat command on PR

First deployment on PRE via GitHub actions triggered by a chat command on PR #10

name: Handle Slash 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;
console.log("Comment received:", comment);
if (comment.trim() === '/deploy-pre') {
console.log("Command `/deploy-pre` found.");
return { valid: true };
}
console.log("No valid command found.");
return { valid: false };
result-encoding: json
result: 'steps.check_command.outputs.valid'
# Step 2: Debug Command Check
- name: Debug Command Check
run: |
echo "Valid command: ${{ steps.check_command.outputs.valid }}"
# Step 3: Extract PR Branch
- 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.");
}
console.log("PR branch:", pr.head.ref);
return pr.head.ref;
result-encoding: string
# Step 4: Debug PR Branch
- name: Debug PR Branch
if: steps.check_command.outputs.valid == 'true'
run: |
echo "Branch: ${{ steps.pr_details.outputs.result }}"
# Step 5: 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", # Replace with your deployment workflow filename
ref: "${{ steps.pr_details.outputs.result }}"
})
console.log("Triggered deploy-pre workflow for branch:", "${{ steps.pr_details.outputs.result }}");
# Step 6: Post Confirmation Comment
- name: Post Comment to PR
if: steps.check_command.outputs.valid == 'true'
uses: actions/github-script@v6
with:
script: |
const issue_number = context.payload.issue.number;
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
body: `✅ Workflow \`deploy-pre.yml\` has been triggered for branch \`${{ steps.pr_details.outputs.result }}\`.`
});
console.log("Commented back to PR:", issue_number);