How to Run a Workflow on Issue Comment Commands in GitHub Actions
ChatOps lets reviewers trigger deploys or tests by commenting, but you must parse the command and check who sent it.
Trigger on issue_comment, gate on the comment body and author association, then run the action the command requested.
Steps
- Trigger on issue_comment with type created.
- Gate the job with an if that matches the command prefix in the comment body.
- Check github.event.comment.author_association so only collaborators can run it.
- Acknowledge with a reaction or reply so the author sees it was picked up.
Workflow
.github/workflows/comment-command.yml
name: Comment Command
on:
issue_comment:
types: [created]
jobs:
deploy:
if: ${{ startsWith(github.event.comment.body, '/deploy') && github.event.comment.author_association == 'MEMBER' }}
runs-on: ubuntu-latest
steps:
- run: echo "running deploy requested by ${{ github.event.comment.user.login }}"Notes
- issue_comment fires for both issues and PRs, so check github.event.issue.pull_request if you only want PRs.
- Latchkey managed runners run these on-demand command jobs cheaper and self-heal on runner failure.
Frequently asked questions
How do I run a Workflow on Issue Comment Commands in GitHub Actions?
Trigger on issue_comment, gate on the comment body and author association, then run the action the command requested.
Related guides
How to Comment on a Pull Request From a Workflow in GitHub ActionsPost a comment on a pull request from a GitHub Actions workflow using actions/github-script and the GITHUB_TO…
How to Run a Workflow on a Fork Safely in GitHub ActionsRun GitHub Actions on fork pull requests without leaking secrets by splitting untrusted build from a privileg…
How to Run kubeconform on Manifests in GitHub ActionsValidate Kubernetes manifests against the API schemas in GitHub Actions with kubeconform so invalid YAML is r…