Skip to content

Commit 3f2a4e3

Browse files
committed
feat: allow paramerizable test matrix
Signed-off-by: Frédéric BIDON <fredbi@yahoo.com>
1 parent 208da1c commit 3f2a4e3

File tree

5 files changed

+53
-8
lines changed

5 files changed

+53
-8
lines changed

.github/workflows/go-test-monorepo.yml

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@ on:
1111
description: extra flags to add to go test
1212
type: string
1313
required: false
14+
matrix:
15+
description: |
16+
Optional JSON string to define the test matrix, using keys: "os" and "go".
17+
18+
By default tests run a 6-way matrix running on os (linux,windows,macos)
19+
for the 2 latest go releases (stable, oldstable).
20+
21+
The default matrix used is:
22+
{"os":["ubuntu-latest","macos-latest","windows-latest"],"go": ["oldstable","stable"]}
23+
24+
type: string
25+
required: false
1426

1527
defaults:
1628
run:
@@ -27,6 +39,7 @@ jobs:
2739
module-names: ${{ steps.detect-monorepo.outputs.names }}
2840
coverpkg: ${{ steps.prepare-tests.outputs.coverpkg }}
2941
all-modules: ${{ steps.prepare-tests.outputs.all-modules }}
42+
test-matrix: ${{ steps.test-matrix.outputs.test-matrix }}
3043
steps:
3144
-
3245
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
@@ -88,15 +101,23 @@ jobs:
88101
# golangci-lint run --new-from-rev origin/master
89102
# popd
90103
# done < <(echo ${{ steps.detect-monorepo.outputs.bash-paths }})
104+
-
105+
name: Test matrix
106+
id: test-matrix
107+
env:
108+
MATRIX: |
109+
${{ inputs.test-matrix || '{"os":["ubuntu-latest","macos-latest","windows-latest"],"go": ["oldstable","stable"]}' }}
110+
run: |
111+
echo "test-matrix<<EOF" >> "${GITHUB_OUTPUT}"
112+
printenv MATRIX >> "${GITHUB_OUTPUT}"
113+
echo "EOF" >> "${GITHUB_OUTPUT}"
91114
92115
test:
93116
name: Unit tests mono-repo
94117
needs: [ lint ]
95118
runs-on: ${{ matrix.os }}
96119
strategy:
97-
matrix:
98-
os: [ ubuntu-latest, macos-latest, windows-latest ]
99-
go: ['oldstable', 'stable' ]
120+
matrix: ${{ fromJSON(needs.lint.outputs.test-matrix) }}
100121
steps:
101122
-
102123
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

.github/workflows/go-test.yml

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@ on:
1111
description: extra flags to add to go test
1212
type: string
1313
required: false
14+
matrix:
15+
description: |
16+
Optional JSON string to define the test matrix, using keys: "os" and "go".
17+
18+
By default tests run a 6-way matrix running on os (linux,windows,macos)
19+
for the 2 latest go releases (stable, oldstable).
20+
21+
The default matrix used is:
22+
{"os":["ubuntu-latest","macos-latest","windows-latest"],"go": ["oldstable","stable"]}
23+
24+
type: string
25+
required: false
1426

1527
defaults:
1628
run:
@@ -20,6 +32,8 @@ jobs:
2032
lint:
2133
name: Lint
2234
runs-on: ubuntu-latest
35+
outputs:
36+
test-matrix: ${{ steps.test-matrix.outputs.test-matrix }}
2337
steps:
2438
-
2539
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
@@ -36,16 +50,24 @@ jobs:
3650
version: latest
3751
only-new-issues: true
3852
skip-cache: true
53+
-
54+
name: Test matrix
55+
id: test-matrix
56+
env:
57+
MATRIX: |
58+
${{ inputs.test-matrix || '{"os":["ubuntu-latest","macos-latest","windows-latest"],"go": ["oldstable","stable"]}' }}
59+
run: |
60+
echo "test-matrix<<EOF" >> "${GITHUB_OUTPUT}"
61+
printenv MATRIX >> "${GITHUB_OUTPUT}"
62+
echo "EOF" >> "${GITHUB_OUTPUT}"
3963
4064
test:
4165
name: Unit tests
4266
runs-on: ${{ matrix.os }}
4367
needs: [lint]
4468

4569
strategy:
46-
matrix:
47-
os: [ ubuntu-latest, macos-latest, windows-latest ]
48-
go: ['oldstable', 'stable' ]
70+
matrix: ${{ fromJSON(needs.lint.outputs.test-matrix) }}
4971

5072
steps:
5173
-

go.work.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github.com/go-openapi/testify/v2 v2.4.1/go.mod h1:HCPmvFFnheKK2BuwSA0TbbdxJ3I16pjwMkYkP4Ywn54=

sample-monorepo/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ module github.com/go-openapi/ci-workflows/sample-monorepo
22

33
go 1.25.0
44

5-
require github.com/go-openapi/testify/v2 v2.4.1
5+
require github.com/go-openapi/testify/v2 v2.4.2

sample-monorepo/go.sum

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
github.com/go-openapi/testify/v2 v2.4.1 h1:zB34HDKj4tHwyUQHrUkpV0Q0iXQ6dUCOQtIqn8hE6Iw=
1+
github.com/go-openapi/testify/v2 v2.4.2 h1:tiByHpvE9uHrrKjOszax7ZvKB7QOgizBWGBLuq0ePx4=
2+
github.com/go-openapi/testify/v2 v2.4.2/go.mod h1:SgsVHtfooshd0tublTtJ50FPKhujf47YRqauXXOUxfw=

0 commit comments

Comments
 (0)