Skip to content

Commit 7cb8454

Browse files
ci: autogenerate image matrix
Rather than a hardcoded matrix in both files, just generate it dynamically based on the discovered m4 files. Pass this to the subsequent build step. Signed-off-by: Bill Roberts <bill.c.roberts@gmail.com>
1 parent e313cc6 commit 7cb8454

2 files changed

Lines changed: 41 additions & 19 deletions

File tree

.github/workflows/main.yml

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,32 @@ permissions:
99
contents: read
1010

1111
jobs:
12-
publish-image:
12+
generate-matrix:
13+
runs-on: ubuntu-latest
14+
15+
outputs:
16+
distros: ${{ steps.set-matrix.outputs.distros }}
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
21+
- id: set-matrix
22+
run: |
23+
DISTROS=$(find . -maxdepth 1 -name '*.docker.m4' \
24+
| sed 's|^\./||' \
25+
| sed 's|\.docker\.m4$||' \
26+
| jq -R -s -c 'split("\n")[:-1]')
27+
28+
echo "distros=$DISTROS" >> $GITHUB_OUTPUT
29+
30+
build-image:
1331
name: Build Docker Images
32+
needs: generate-matrix
1433
runs-on: ubuntu-latest
1534
strategy:
1635
fail-fast: false
1736
matrix:
18-
distro: [
19-
"alpine-3.15", "alpine-3.19",
20-
"arch-linux",
21-
"fedora-32.ppc64le", "fedora-41", "fedora-43",
22-
"opensuse-leap-15.2", "opensuse-leap", "opensuse-leap-ossl3",
23-
"ubuntu-20.04.arm32v7", "ubuntu-20.04.arm64v8", "ubuntu-20.04",
24-
"ubuntu-20.04-ossl3", "ubuntu-22.04", "ubuntu-22.04-mbedtls-3.1",
25-
"ubuntu-22.04-mbedtls-3.6", "ubuntu-24.04"
26-
]
37+
distro: ${{ fromJson(needs.generate-matrix.outputs.distros) }}
2738
steps:
2839
-
2940
name: Check out the repo

.github/workflows/publish.yml

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,32 @@ permissions:
1010
contents: read
1111
packages: write
1212
jobs:
13+
generate-matrix:
14+
runs-on: ubuntu-latest
15+
16+
outputs:
17+
distros: ${{ steps.set-matrix.outputs.distros }}
18+
19+
steps:
20+
- uses: actions/checkout@v4
21+
22+
- id: set-matrix
23+
run: |
24+
DISTROS=$(find . -maxdepth 1 -name '*.docker.m4' \
25+
| sed 's|^\./||' \
26+
| sed 's|\.docker\.m4$||' \
27+
| jq -R -s -c 'split("\n")[:-1]')
28+
29+
echo "distros=$DISTROS" >> $GITHUB_OUTPUT
30+
1331
publish-image:
1432
name: Publish Docker Images
33+
needs: generate-matrix
1534
runs-on: ubuntu-latest
1635
strategy:
1736
fail-fast: false
1837
matrix:
19-
distro: [
20-
"alpine-3.15", "alpine-3.19",
21-
"arch-linux",
22-
"fedora-32.ppc64le", "fedora-41", "fedora-43",
23-
"opensuse-leap-15.2", "opensuse-leap", "opensuse-leap-ossl3",
24-
"ubuntu-20.04.arm32v7", "ubuntu-20.04.arm64v8", "ubuntu-20.04",
25-
"ubuntu-20.04-ossl3", "ubuntu-22.04", "ubuntu-22.04-mbedtls-3.1",
26-
"ubuntu-22.04-mbedtls-3.6", "ubuntu-24.04"
27-
]
38+
distro: ${{ fromJson(needs.generate-matrix.outputs.distros) }}
2839

2940
if: "github.repository_owner == 'tpm2-software'"
3041
steps:

0 commit comments

Comments
 (0)