This action helps build more complex GitHub Actions build matrices.
Required Build matrix configuration.
A build matrix to use in your jobs.
Use this action in a job and use its output as your build matrix.
jobs:
setup-build-matrix:
runs-on: ubuntu-latest
steps:
- name: Build matrix
id: build-matrix
uses: jgiannuzzi/setup-build-matrix@v1
with:
config: |
matrix:
# Base matrix
os: [ubuntu-latest, windows-latest]
component: [backend, ui]
dotnet: [3.1.405, 5.0.102]
operations:
# Append a new matrix to the base matrix
- type: append
matrix:
os: [macos-latest]
component: [backend,ui]
dotnet: [4.7.2,5.0.102]
# Do a database-style outer join to merge the 2 node versions
# on matching component==ui keys.
- type: merge
match: [component]
matrix:
component: [ui]
node: [14.15.4, 15.6.0]
# Add an extra dotnet version just for ui on windows
- type: add
match: [os, component]
matrix:
os: [windows-latest]
component: [ui]
dotnet: [4.7.2]
outputs:
matrix: ${{ steps.build-matrix.outputs.matrix }}
build:
needs: setup-build-matrix
strategy:
matrix: ${{ fromJson(needs.setup-build-matrix.outputs.matrix) }}
runs-on: ${{ matrix.os }}
steps:
...The above workflow is equivalent to this:
jobs:
build:
strategy:
matrix:
include:
- os: macos-latest
component: backend
dotnet: 4.7.2
- os: macos-latest
component: backend
dotnet: 5.0.102
- os: macos-latest
component: ui
dotnet: 4.7.2
node: 14.15.4
- os: macos-latest
component: ui
dotnet: 4.7.2
node: 15.6.0
- os: macos-latest
component: ui
dotnet: 5.0.102
node: 14.15.4
- os: macos-latest
component: ui
dotnet: 5.0.102
node: 15.6.0
- os: ubuntu-latest
component: backend
dotnet: 3.1.405
- os: ubuntu-latest
component: backend
dotnet: 5.0.102
- os: ubuntu-latest
component: ui
dotnet: 3.1.405
node: 14.15.4
- os: ubuntu-latest
component: ui
dotnet: 3.1.405
node: 15.6.0
- os: ubuntu-latest
component: ui
dotnet: 5.0.102
node: 14.15.4
- os: ubuntu-latest
component: ui
dotnet: 5.0.102
node: 15.6.0
- os: windows-latest
component: backend
dotnet: 3.1.405
- os: windows-latest
component: backend
dotnet: 5.0.102
- os: windows-latest
component: ui
dotnet: 3.1.405
node: 14.15.4
- os: windows-latest
component: ui
dotnet: 3.1.405
node: 15.6.0
- os: windows-latest
component: ui
dotnet: 4.7.2
node: 14.15.4
- os: windows-latest
component: ui
dotnet: 4.7.2
node: 15.6.0
- os: windows-latest
component: ui
dotnet: 5.0.102
node: 14.15.4
- os: windows-latest
component: ui
dotnet: 5.0.102
node: 15.6.0
runs-on: ${{ matrix.os }}
steps:
...It can be helpful to visualize the operations that happened as actual matrices.
This is our initial matrix.
| os | component | dotnet |
|---|---|---|
| ubuntu-latest | backend | 3.1.405 |
| ubuntu-latest | backend | 5.0.102 |
| ubuntu-latest | ui | 3.1.405 |
| ubuntu-latest | ui | 5.0.102 |
| windows-latest | backend | 3.1.405 |
| windows-latest | backend | 5.0.102 |
| windows-latest | ui | 3.1.405 |
| windows-latest | ui | 5.0.102 |
We start by appending a matrix.
| os | component | dotnet |
|---|---|---|
| macos-latest | backend | 4.7.2 |
| macos-latest | backend | 5.0.102 |
| macos-latest | ui | 4.7.2 |
| macos-latest | ui | 5.0.102 |
This results in the following intermediate matrix. Notice that the new rows in bold appear at the top since the matrix is kept sorted.
| os | component | dotnet |
|---|---|---|
| macos-latest | backend | 4.7.2 |
| macos-latest | backend | 5.0.102 |
| macos-latest | ui | 4.7.2 |
| macos-latest | ui | 5.0.102 |
| ubuntu-latest | backend | 3.1.405 |
| ubuntu-latest | backend | 5.0.102 |
| ubuntu-latest | ui | 3.1.405 |
| ubuntu-latest | ui | 5.0.102 |
| windows-latest | backend | 3.1.405 |
| windows-latest | backend | 5.0.102 |
| windows-latest | ui | 3.1.405 |
| windows-latest | ui | 5.0.102 |
We then perform a merge with the following matrix on the component column.
| component | node |
|---|---|
| ui | 14.15.4 |
| ui | 15.6.0 |
This results in the following intermediate matrix.
Notice the new merged rows in bold that are replacing the previous ui rows.
| os | component | dotnet | node |
|---|---|---|---|
| macos-latest | backend | 4.7.2 | |
| macos-latest | backend | 5.0.102 | |
| macos-latest | ui | 4.7.2 | 14.15.4 |
| macos-latest | ui | 4.7.2 | 15.6.0 |
| macos-latest | ui | 5.0.102 | 14.15.4 |
| macos-latest | ui | 5.0.102 | 15.6.0 |
| ubuntu-latest | backend | 3.1.405 | |
| ubuntu-latest | backend | 5.0.102 | |
| ubuntu-latest | ui | 3.1.405 | 14.15.4 |
| ubuntu-latest | ui | 3.1.405 | 15.6.0 |
| ubuntu-latest | ui | 5.0.102 | 14.15.4 |
| ubuntu-latest | ui | 5.0.102 | 15.6.0 |
| windows-latest | backend | 3.1.405 | |
| windows-latest | backend | 5.0.102 | |
| windows-latest | ui | 3.1.405 | 14.15.4 |
| windows-latest | ui | 3.1.405 | 15.6.0 |
| windows-latest | ui | 5.0.102 | 14.15.4 |
| windows-latest | ui | 5.0.102 | 15.6.0 |
We then add the following matrix, matching on the os and component columns.
| os | component | dotnet |
|---|---|---|
| windows-latest | ui | 4.7.2 |
This results in the following final matrix. Notice the 2 new added rows in bold.
| os | component | dotnet | node |
|---|---|---|---|
| macos-latest | backend | 4.7.2 | |
| macos-latest | backend | 5.0.102 | |
| macos-latest | ui | 4.7.2 | 14.15.4 |
| macos-latest | ui | 4.7.2 | 15.6.0 |
| macos-latest | ui | 5.0.102 | 14.15.4 |
| macos-latest | ui | 5.0.102 | 15.6.0 |
| ubuntu-latest | backend | 3.1.405 | |
| ubuntu-latest | backend | 5.0.102 | |
| ubuntu-latest | ui | 3.1.405 | 14.15.4 |
| ubuntu-latest | ui | 3.1.405 | 15.6.0 |
| ubuntu-latest | ui | 5.0.102 | 14.15.4 |
| ubuntu-latest | ui | 5.0.102 | 15.6.0 |
| windows-latest | backend | 3.1.405 | |
| windows-latest | backend | 5.0.102 | |
| windows-latest | ui | 3.1.405 | 14.15.4 |
| windows-latest | ui | 3.1.405 | 15.6.0 |
| windows-latest | ui | 4.7.2 | 14.15.4 |
| windows-latest | ui | 4.7.2 | 15.6.0 |
| windows-latest | ui | 5.0.102 | 14.15.4 |
| windows-latest | ui | 5.0.102 | 15.6.0 |
Note that the rows that have no values for a column will not have that key set at all in their resulting matrix object.