What is a build matrix in CI and when is it useful?

Answer

A build matrix (called strategy.matrix in GitHub Actions) lets you run the same job against multiple combinations of variables simultaneously. This is most commonly used to test across multiple language versions, operating systems, or dependency versions in parallel. For example, a Python library might test against Python 3.9, 3.10, 3.11, and 3.12 on both Ubuntu and macOS — creating 8 parallel jobs from a single matrix definition. A Node.js package might test on Node 18 and 20 across Linux, Windows, and macOS. This ensures your code works across all supported environments without manually defining separate jobs for each. Build matrices are essential for library and open-source projects that need broad compatibility guarantees.