From dd4861472c31ddad4a702454af652b62c06b9da4 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Thu, 9 Nov 2023 10:34:45 +0100 Subject: [PATCH] matrix-gen: bake matrix support Signed-off-by: CrazyMax --- .github/workflows/ci-matrix-gen.yml | 18 +++++++++++++++++ subaction/matrix-gen/action.yml | 5 ++++- test/group-matrix/docker-bake.hcl | 31 +++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 test/group-matrix/docker-bake.hcl diff --git a/.github/workflows/ci-matrix-gen.yml b/.github/workflows/ci-matrix-gen.yml index eb509e7..3cd5225 100644 --- a/.github/workflows/ci-matrix-gen.yml +++ b/.github/workflows/ci-matrix-gen.yml @@ -33,3 +33,21 @@ jobs: name: Show matrix run: | echo matrix=${{ steps.gen.outputs.matrix }} + + group-matrix: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v4 + - + name: Matrix gen + id: gen + uses: ./subaction/matrix-gen + with: + workdir: ./test/group-matrix + target: validate + - + name: Show matrix + run: | + echo matrix=${{ steps.gen.outputs.matrix }} diff --git a/subaction/matrix-gen/action.yml b/subaction/matrix-gen/action.yml index b51f8f0..54dd308 100644 --- a/subaction/matrix-gen/action.yml +++ b/subaction/matrix-gen/action.yml @@ -53,7 +53,10 @@ runs: }); await core.group(`Set matrix`, async () => { - const matrix = def.group[target].targets; + let matrix = []; + for (const [key, value] of Object.entries(def.target)) { + matrix.push(key); + } core.info(`matrix: ${JSON.stringify(matrix)}`); core.setOutput('matrix', JSON.stringify(matrix)); }); diff --git a/test/group-matrix/docker-bake.hcl b/test/group-matrix/docker-bake.hcl new file mode 100644 index 0000000..ea27ff6 --- /dev/null +++ b/test/group-matrix/docker-bake.hcl @@ -0,0 +1,31 @@ +group "validate" { + targets = ["lint", "validate-vendor", "validate-doctoc"] +} + +target "lint" { + name = "lint-${buildtags.name}" + dockerfile = "./hack/dockerfiles/lint.Dockerfile" + target = buildtags.target + output = ["type=cacheonly"] + matrix = { + buildtags = [ + { name = "default", tags = "", target = "golangci-lint" }, + { name = "labs", tags = "dfrunsecurity dfparents", target = "golangci-lint" }, + { name = "nydus", tags = "nydus", target = "golangci-lint" }, + { name = "yaml", tags = "", target = "yamllint" }, + { name = "proto", tags = "", target = "protolint" }, + ] + } +} + +target "validate-vendor" { + dockerfile = "./hack/dockerfiles/vendor.Dockerfile" + target = "validate" + output = ["type=cacheonly"] +} + +target "validate-doctoc" { + dockerfile = "./hack/dockerfiles/doctoc.Dockerfile" + target = "validate-toc" + output = ["type=cacheonly"] +}