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).
More on Triggers & Events
How do you trigger a workflow on pushes to `main` and on PRs that target `main`?BeginnerWhat activity types does `pull_request` trigger on by default, and how do you add more?IntermediateHow do `branches` and `branches-ignore` filters work with globs?BeginnerHow do path filters work, and what are their limits?AdvancedHow do you trigger only on version tags, and what is the gotcha with pushing many tags?IntermediateWhat is `workflow_dispatch`, and what input types does it support?Beginner