Why Use a Matrix Strategy?
- Parallel execution for faster feedback
- Broad runtime and OS compatibility
- Simplified maintenance by centralizing variations
1. Defining the Matrix
First, configure your workflow triggers, environment variables, and a basic matrix under theunit-testing job. Here’s an example that hard-codes the runner and Node.js version:
We define three Node.js versions and two OS targets. The
exclude block omits Node.js 18 on macOS.Matrix Combinations
2. Referencing Matrix Variables
Next, updateruns-on and the Node.js setup step to dynamically reference your matrix values. This allows every job to automatically select the correct OS and Node.js version:
Use
${{ matrix.nodejs_version }} and ${{ matrix.operating_system }} to automatically pick each configured combination.3. Running and Observing the Workflow
Commit and push your changes with a descriptive message, for example:
