1- name : Handle Deploy Commands in PR Comments
1+ name : Handle Deployment Commands in PR Comments
22
33on :
44 issue_comment :
@@ -10,37 +10,42 @@ jobs:
1010 runs-on : ubuntu-latest
1111
1212 steps :
13- # Step 1: Check if the command is `/deploy-pre`
13+ # Step 1: Verify Command in Comment
1414 - name : Check for `/deploy-pre` Command
1515 id : check_command
16- uses : peter-evans/slash-command-action@v4
16+ uses : actions/github-script@v6
1717 with :
18- token : ${{ secrets.GITHUB_TOKEN }}
19- command : /deploy-pre
18+ script : |
19+ const comment = context.payload.comment.body;
20+ if (comment.trim() === '/deploy-pre') {
21+ return { valid: true };
22+ }
23+ return { valid: false };
24+ result-encoding : json
2025
21- # Step 2: Extract Branch Reference from PR
22- - name : Get Pull Request Details
23- if : steps.check_command.outputs.command == 'true'
26+ # Step 2: Get Branch from PR
27+ - name : Extract PR Branch
28+ if : steps.check_command.outputs.valid == 'true'
2429 id : pr_details
2530 uses : actions/github-script@v6
2631 with :
2732 script : |
2833 const pr = context.payload.issue.pull_request;
2934 if (!pr) {
30- throw new Error("The /deploy-pre command must be used in a pull request comment .");
35+ throw new Error("This command can only be used on a pull request.");
3136 }
3237 return pr.head.ref;
3338 result-encoding : string
3439
35- # Step 3: Trigger Deploy Workflow for the PR Branch
40+ # Step 3: Trigger Deploy Workflow
3641 - name : Trigger Deploy Workflow
37- if : steps.check_command.outputs.command == 'true'
42+ if : steps.check_command.outputs.valid == 'true'
3843 uses : actions/github-script@v6
3944 with :
4045 script : |
4146 github.rest.actions.createWorkflowDispatch({
4247 owner: context.repo.owner,
4348 repo: context.repo.repo,
44- workflow_id: "deploy-pre.yml", # Replace with your workflow filename
49+ workflow_id: "deploy-pre.yml",
4550 ref: "${{ steps.pr_details.outputs.result }}"
4651 })
0 commit comments