A deployment workflow should run only after CI succeeds on main.
IntermediateScenarioGitHub Actions
Answer
Situation read → Chain workflows.
What I'd do →
- Option A: one workflow with
jobs.deploy.needs: [test]andif: github.ref == 'refs/heads/main'. - Option B:
on: workflow_run: workflows: [ci], types: [completed], branches: [main]withif: github.event.workflow_run.conclusion == 'success'.
Why → One workflow is simpler and shows one graph; workflow_run is useful when workflows live separately, but runs with different context and must check out the correct SHA.
Interview tip → With workflow_run, check out github.event.workflow_run.head_sha.
More on GitHub Actions
What are workflows, jobs, steps and actions in GitHub Actions?BeginnerWhat events can trigger a workflow?BeginnerWhat is the difference between `pull_request` and `pull_request_target`?AdvancedWhat is a runner, and how do GitHub-hosted and self-hosted runners differ?BeginnerHow do you pass data between steps and between jobs?IntermediateHow does a build matrix work?Intermediate