Git & GitHub Interview Question #98

What is a matrix strategy in GitHub Actions?

GitHub Collaboration, Repository Rules, Issues, Releases & Actions CI/CD Mid-Level Intermediate

Quick Interview Answer

A matrix strategy runs variations of a job across combinations of configured values, such as operating systems, runtime versions, or target environments.

Detailed Explanation

A matrix strategy runs variations of a job across combinations of configured values, such as operating systems, runtime versions, or target environments.

It is useful when a library or application must be validated on multiple supported platforms. Large matrices can consume significant CI resources, so test only combinations that provide meaningful coverage.

Code Example

jobs:
  test:
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest]
        dotnet: ["8.0.x", "9.0.x"]

    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/setup-dotnet@v4
        with:
          dotnet-version: ${{ matrix.dotnet }}