Skip to content

Commit 2abe0f5

Browse files
committed
generate the list of dockerfiles dynamically
1 parent e31c124 commit 2abe0f5

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

.github/workflows/docker-integration-tests.yaml

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,34 @@ env:
1010
PLATFORMS: "linux/amd64"
1111

1212
jobs:
13+
list-dockerfiles:
14+
name: Create list of existing dockerfiles
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
- name: Get file list
20+
id: set-matrix
21+
run: |
22+
# lists all Dockerfile_* and ignore (grep) files with extension (e.g. *.md5)
23+
# tranforms the file list in JSON array (StackOverflow#10234327)
24+
# converts the list into objects of dockerfile and image name
25+
ls integration-tests/Dockerfile_* |
26+
grep -Ev "\..{0,3}$" |
27+
jq -R -s 'split("\n")[:-1]' |
28+
jq '. | map({dockerfile: ., image: sub(".*_"; "")})' > filelist.json
29+
echo "matrix=$(jq -c . filelist.json)" >> "$GITHUB_OUTPUT"
30+
outputs:
31+
matrix: ${{ steps.set-matrix.outputs.matrix }}
32+
1333
docker:
34+
needs: [list-dockerfiles]
1435
name: Build and push Docker image
1536
runs-on: ubuntu-latest
1637
strategy:
1738
fail-fast: false
1839
matrix:
19-
include:
20-
- dockerfile: ./integration-tests/Dockerfile_alpine3
21-
image: goss_alpine3
22-
- dockerfile: ./integration-tests/Dockerfile_arch
23-
image: goss_arch
24-
- dockerfile: ./integration-tests/Dockerfile_centos7
25-
image: goss_centos7
26-
- dockerfile: ./integration-tests/Dockerfile_trusty
27-
image: goss_trusty
28-
- dockerfile: ./integration-tests/Dockerfile_wheezy
29-
image: goss_wheezy
40+
include: ${{ fromJson(needs.list-dockerfiles.outputs.matrix) }}
3041
permissions:
3142
packages: write
3243
contents: read

0 commit comments

Comments
 (0)