How to Use slash-command-dispatch in GitHub Actions
slash-command-dispatch reads a comment, validates the command, and re-emits it as a repository_dispatch event that a separate command workflow handles.
Run peter-evans/slash-command-dispatch in a command dispatcher workflow. It parses /command comments, enforces a permission floor, reacts to the comment, and dispatches to a handler workflow.
Steps
- Add a dispatcher workflow on
issue_comment. - List allowed commands and set a
permissionfloor. - The action fires a
repository_dispatchper command. - Handle each command in a
repository_dispatchworkflow.
Dispatcher workflow
.github/workflows/ci.yml
on:
issue_comment:
types: [created]
jobs:
dispatch:
runs-on: ubuntu-latest
steps:
- uses: peter-evans/slash-command-dispatch@v4
with:
token: ${{ secrets.PAT }}
permission: write
commands: |
deploy
retest
issue-type: pull-requestGotchas
- The
permissioninput rejects users below the floor automatically, but keep it explicit atwriteor higher for deploys. - A PAT (not GITHUB_TOKEN) is required so the dispatched event can start a new workflow.
- Only commands you list are dispatched; unknown commands are ignored.
Related guides
How to Handle a Slash Command With repository_dispatch in GitHub ActionsHandle a dispatched slash command in GitHub Actions with an on.repository_dispatch workflow that filters on t…
How to Use Dispatch Types and Named Args in slash-command-dispatchConfigure dispatch types and named arguments in peter-evans/slash-command-dispatch so a slash command carries…