Skip to content
Latchkey

How to Trigger a Workflow on an Issue or PR Comment in GitHub Actions

The issue_comment event fires on comments for both issues and pull requests, so you can build slash-command automation.

Listen with on.issue_comment and gate the job with an if that checks the comment body. For PR comments, github.event.issue.pull_request is present.

Steps

  • Add issue_comment: under on with types: [created].
  • Gate the job with if: contains(github.event.comment.body, '/deploy').
  • Check github.event.issue.pull_request to act on PR comments only.

Workflow

.github/workflows/chatops.yml
on:
  issue_comment:
    types: [created]
jobs:
  deploy-command:
    if: github.event.issue.pull_request && contains(github.event.comment.body, '/deploy')
    runs-on: ubuntu-latest
    steps:
      - run: echo "Deploy requested by ${{ github.event.comment.user.login }}"

Gotchas

  • issue_comment runs against the default branch workflow, not the PR head, so it cannot build fork code with secrets.
  • Anyone who can comment can fire it; check author_association before running privileged steps.

Related guides

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