Chapter 90: GitHub Actions Deep Dive
90.4 YAML deep dive — needs, matrix, concurrency, environments and approvals
Story (fictional teaching scenario). Neha's team in Hyderabad tested a Python API on three Python versions by copying the job three times. Then Lucas from São Paulo showed her matrix: one job, three versions. Next, two deploys raced each other and the older one won. concurrency fixed that. Finally the CTO wanted a human to approve prod. An environment named production with a required reviewer paused the deploy until Neha clicked Approve. Four keywords, four real problems solved.
Why
Real pipelines have order, many versions, races and humans. These keywords handle all four without copy-paste.
What
- needs — Job B waits for job A to pass.
- matrix — Runs one job many times with different values.
- concurrency — A group name. Only one run in the group at a time.
cancel-in-progressstops the older one. - environment — A named target like
stagingorproduction. It can hold its own secrets and protection rules. - Required reviewers — An environment rule. The job waits until a listed person approves.
How
- Put tests in a matrix job.
- Add
needs: testto the build job. - Add a
concurrencygroup on deploy jobs. - In repo Settings → Environments, create
productionand add required reviewers. - Set
environment: productionon the deploy job.
Example 1: Matrix plus needs
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python: ["3.12", "3.13", "3.14"]
steps:
- uses: actions/checkout@v7
- uses: actions/setup-python@v7
with:
python-version: ${{ matrix.python }}
- run: python --version
build:
needs: test
runs-on: ubuntu-latest
steps:
- run: echo "all tests passed, building"
Output (illustrative) (run summary)
test (3.12) ✓ Python 3.12.x
test (3.13) ✓ Python 3.13.x
test (3.14) ✓ Python 3.14.x
build ✓ all tests passed, building
What it shows: One job became three. build waited until all three passed. If one fails, build is skipped.
Example 2: Concurrency and an approval gate
jobs:
deploy:
runs-on: ubuntu-latest
environment: production
concurrency:
group: deploy-prod
cancel-in-progress: false
steps:
- run: echo "deploying release"
Output (illustrative) (run page)
deploy ⏸ Waiting for review: production needs approval from 1 reviewer
...
deploy ✓ deploying release (approved by neha-k)
What it shows: The job paused at the environment gate. After approval it ran. A second deploy would queue in deploy-prod instead of racing. The reviewer name is an example.
Ravindra Bagale's Tip
For deploys, keep cancel-in-progress false so a half-done deploy is not killed. For PR tests, set it true to save minutes.
Deploy साठी cancel-in-progress false ठेवा, म्हणजे अर्धवट deploy मध्येच मरणार नाही. PR tests साठी true ठेवा, minutes वाचतात.
Deploy के लिए cancel-in-progress false रखो, ताकि आधा deploy बीच में न मरे. PR tests के लिए true रखो, minutes बचते हैं.
Quick quiz
Q1. What does needs do?
Makes a job wait for another job to succeed.
Q2. What does a matrix do?
Runs the same job many times with different values, like versions.
Q3. How do you force a human approval before prod?
Use an environment with required reviewers and set environment: on the job.
Did you understand? Let us try it once more.