|
| 1 | +name: On Command |
| 2 | + |
| 3 | +on: |
| 4 | + issue_comment: |
| 5 | + types: [created] |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: read |
| 9 | + actions: write |
| 10 | + pull-requests: write |
| 11 | + |
| 12 | +jobs: |
| 13 | + parse: |
| 14 | + name: Check Permissions and Parse Command β¨οΈ |
| 15 | + runs-on: ubuntu-latest |
| 16 | + outputs: |
| 17 | + command: ${{ steps.command.outputs.command }} |
| 18 | + steps: |
| 19 | + - name: Get actor permissions |
| 20 | + id: check-permissions |
| 21 | + continue-on-error: true |
| 22 | + uses: prince-chrismc/check-actor-permissions-action@v3.0.2 |
| 23 | + with: |
| 24 | + permission: write |
| 25 | + |
| 26 | + - name: Log actor permissions |
| 27 | + run: | |
| 28 | + echo Actor has permission: ${{ steps.check-permissions.outputs.permitted && ' true' || 'false' }} |
| 29 | + echo Actor is bot user: ${{ github.actor == 'nixos-wsl-bot' && ' true' || 'false' }} |
| 30 | +
|
| 31 | + - name: Post error message if not permitted |
| 32 | + if: ${{ !steps.check-permissions.outputs.permitted && github.actor != 'nixos-wsl-bot' }} |
| 33 | + uses: thollander/actions-comment-pull-request@v3.0.1 |
| 34 | + with: |
| 35 | + pr-number: ${{ inputs.pr_number || github.event.issue.number }} |
| 36 | + message: | |
| 37 | + You do not have permission to run this command @${{ github.actor }}. |
| 38 | +
|
| 39 | + - name: Stop if not permitted |
| 40 | + if: ${{ !steps.check-permissions.outputs.permitted && github.actor != 'nixos-wsl-bot' }} |
| 41 | + run: | |
| 42 | + exit 1 |
| 43 | +
|
| 44 | + - name: Parse command |
| 45 | + id: command |
| 46 | + if: steps.check-permissions.outputs.permitted || github.actor == 'nixos-wsl-bot' |
| 47 | + run: | |
| 48 | + echo ${{ github.event.comment.body }} | sed -nE 's|^/([a-z0-9\-]+)|command=\1|p' >> $GITHUB_OUTPUT |
| 49 | +
|
| 50 | + trigger-on-push: |
| 51 | + name: Trigger Push Workflow π |
| 52 | + needs: parse |
| 53 | + if: needs.parse.outputs.command == 'run-ci' && github.event.issue.pull_request |
| 54 | + runs-on: ubuntu-latest |
| 55 | + steps: |
| 56 | + - name: Checkout |
| 57 | + uses: actions/checkout@v4.2.2 |
| 58 | + |
| 59 | + - name: Get PR branch |
| 60 | + id: branch |
| 61 | + env: |
| 62 | + GH_TOKEN: ${{ github.token }} |
| 63 | + run: | |
| 64 | + echo "branch=$(gh pr view ${{ github.event.issue.number }} --json headRefName -q .headRefName)" >> $GITHUB_OUTPUT |
| 65 | +
|
| 66 | + - name: Dispatch workflow |
| 67 | + uses: actions/github-script@v7.0.1 |
| 68 | + with: |
| 69 | + script: | |
| 70 | + github.rest.actions.createWorkflowDispatch({ |
| 71 | + owner: context.repo.owner, |
| 72 | + repo: context.repo.repo, |
| 73 | + workflow_id: 'on_push.yml', |
| 74 | + ref: '${{ steps.branch.outputs.branch }}', |
| 75 | + inputs: { |
| 76 | + pr_number: '${{ github.event.issue.number }}', |
| 77 | + post_result: 'true' |
| 78 | + } |
| 79 | + }) |
0 commit comments