Ravindra BagaleCourses & study guides मराठी

Chapter 90: GitHub Actions Deep Dive

DevOps

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.

needs orders jobs, matrix fans out versions, concurrency stops races, environments add approval.
needs orders jobs, matrix fans out versions, concurrency stops races, environments add approval.

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-progress stops the older one.
  • environment — A named target like staging or production. It can hold its own secrets and protection rules.
  • Required reviewers — An environment rule. The job waits until a listed person approves.

How

  1. Put tests in a matrix job.
  2. Add needs: test to the build job.
  3. Add a concurrency group on deploy jobs.
  4. In repo Settings → Environments, create production and add required reviewers.
  5. Set environment: production on 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.

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.