fix: Update deploy-pre-chatbot.yml #7
This file contains hidden or 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: 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; | ||
| 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 | ||
| # Debug: Log the output of check_command | ||
| - name: Debug Command Check | ||
| run: | | ||
| echo "Valid command: ${{ steps.check_command.outputs.valid }}" | ||
| # 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."); | ||
| } | ||
| console.log("PR branch:", pr.head.ref); | ||
| return pr.head.ref; | ||
| result-encoding: string | ||
| # Debug: Log PR branch | ||
| - name: Debug PR Branch | ||
| if: steps.check_command.outputs.valid == 'true' | ||
| run: echo "Branch: ${{ steps.pr_details.outputs.result }}" | ||
| # 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", # 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 4: 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); | ||