Skip to content
Latchkey

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.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →