Interview Prep/GitHub Actions/Triggers & Events

How do you run a workflow when an issue or PR comment says `/deploy`, safely?

AdvancedConceptTriggers & Events
Answer
on:
  issue_comment:
    types: [created]
jobs:
  deploy:
    if: >
      github.event.issue.pull_request &&
      startsWith(github.event.comment.body, '/deploy') &&
      contains(fromJSON('["OWNER","MEMBER","COLLABORATOR"]'), github.event.comment.author_association)
    runs-on: ubuntu-24.04
    environment: preview

issue_comment runs from the default branch with secrets, so the authorization check matters. Never interpolate comment.body into a script, and resolve the PR head SHA via the API and pin to it, so a push after the comment cannot swap the code (time-of-check to time-of-use).

All GitHub Actions questions Roadmap: GitHub Actions

More on Triggers & Events