Building different versions using a matrix
In this recipe, we are going to build and test our software for different versions, in our case, of the NodeJS environment.
Getting ready
Make sure you have cloned the repository from the previous recipe. Create a new branch to modify the workflow:
$ git switch -c build-matrix
Open the .github/workflows/ci.yml
file in an editor.
How to do it…
- Add the following code to the workflow file:
strategy: matrix: node-version: ["21.x", "20.x"]
Adjust the versions if needed.
- In the
actions/setup-node
action, set the node version to the corresponding value from the matrix context:- uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} check-latest: true
- Commit and push your changes and create a pull request:
$ git add . $ git commit $ git push -u origin build-matrix $ gh pr create --fill...