debug-dispatch-action #10
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: debug-dispatch-action | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| pr_number: | |
| description: 'PR to run the workflow on' | |
| required: true | |
| jobs: | |
| run-command-and-comment: | |
| permissions: # https://docs.github.com/en/rest/issues/comments?apiVersion=2022-11-28#create-an-issue-comment | |
| contents: 'read' | |
| issues: 'write' | |
| pull-requests: 'write' | |
| runs-on: ubuntu-latest | |
| steps: | |
| # We need to checkout the code first so we can use actions defined on it | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: main | |
| - name: Commment workflow started | |
| uses: ./.github/actions/comment-on-pr | |
| with: | |
| pr_number: ${{ inputs.pr_number }} | |
| message: "🔄 [Workflow](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) started." | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Get PRs source branch name | |
| id: pr_src_branch | |
| uses: actions/github-script@v7 | |
| env: | |
| PR_NUMBER: ${{ inputs.pr_number }} | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| # https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#get-a-pull-request | |
| script: | | |
| const pr_number = process.env.PR_NUMBER; | |
| const pr = await github.rest.pulls.get({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| pull_number: pr_number | |
| }); | |
| console.log("PR:", pr); | |
| const branchName = pr.data.head.ref; | |
| console.log("Branch name is:", branchName); | |
| return branchName; | |
| - name: Checkout branch | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ steps.pr_src_branch.outputs.result }} | |
| - name: Run some command | |
| run: | | |
| echo "Running command on branch: ${{ steps.pr_src_branch.outputs.result }}" | |
| - name: Commment workflow succeeeded | |
| uses: ./.github/actions/comment-on-pr | |
| with: | |
| pr_number: ${{ inputs.pr_number }} | |
| message: "✅ [Workflow](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) completed successfully!" | |
| github-token: ${{ secrets.GITHUB_TOKEN }} |