Interview Prep/GitHub Actions/Triggers & Events

How do you trigger a `workflow_dispatch` from the CLI and from the API?

BeginnerConceptTriggers & Events
Answer
gh workflow run deploy.yml --ref main -f environment=staging -f dry_run=false
gh run watch $(gh run list --workflow deploy.yml --limit 1 --json databaseId -q '.[0].databaseId')

API:

curl -X POST -H "Authorization: Bearer $TOKEN" -H "Accept: application/vnd.github+json" \
  https://api.github.com/repos/ORG/REPO/actions/workflows/deploy.yml/dispatches \
  -d '{"ref":"main","inputs":{"environment":"staging"}}'

The workflow must exist on the default branch for the button and the gh workflow run lookup to appear.

All GitHub Actions questions Roadmap: GitHub Actions

More on Triggers & Events