From c71ed01f8ea588d75bf68bbd1b9fd28378ddda27 Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Thu, 22 May 2025 09:21:00 +0200 Subject: [PATCH] ci(validate): split by platform Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com> --- .github/workflows/validate.yml | 71 ++++++++++++++++++++-------------- docker-bake.hcl | 8 ++++ 2 files changed, 50 insertions(+), 29 deletions(-) diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index a99017106..3b047b20d 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -27,17 +27,52 @@ jobs: prepare: runs-on: ubuntu-24.04 outputs: - targets: ${{ steps.generate.outputs.targets }} + includes: ${{ steps.matrix.outputs.includes }} steps: - name: Checkout uses: actions/checkout@v4 - - name: List targets - id: generate - uses: docker/bake-action/subaction/list-targets@v6 + name: Matrix + id: matrix + uses: actions/github-script@v7 with: - target: validate + script: | + let def = {}; + await core.group(`Parsing definition`, async () => { + const printEnv = Object.assign({}, process.env, { + GOLANGCI_LINT_MULTIPLATFORM: process.env.GITHUB_REPOSITORY === 'moby/buildkit' ? '1' : '', + ARCHUTIL_MULTIPLATFORM: process.env.GITHUB_REPOSITORY === 'moby/buildkit' ? '1' : '' + }); + const resPrint = await exec.getExecOutput('docker', ['buildx', 'bake', 'validate', '--print'], { + ignoreReturnCode: true, + env: printEnv + }); + if (resPrint.stderr.length > 0 && resPrint.exitCode != 0) { + throw new Error(res.stderr); + } + def = JSON.parse(resPrint.stdout.trim()); + }); + await core.group(`Generating matrix`, async () => { + const includes = []; + for (const targetName of Object.keys(def.target)) { + const target = def.target[targetName]; + if (target.platforms && target.platforms.length > 0) { + target.platforms.forEach(platform => { + includes.push({ + target: targetName, + platform: platform + }); + }); + } else { + includes.push({ + target: targetName + }); + } + } + core.info(JSON.stringify(includes, null, 2)); + core.setOutput('includes', JSON.stringify(includes)); + }); validate: runs-on: ubuntu-24.04 @@ -46,14 +81,8 @@ jobs: strategy: fail-fast: false matrix: - target: ${{ fromJson(needs.prepare.outputs.targets) }} + include: ${{ fromJson(needs.prepare.outputs.includes) }} steps: - - - name: Prepare - run: | - if [ "$GITHUB_REPOSITORY" = "moby/buildkit" ]; then - echo "GOLANGCI_LINT_MULTIPLATFORM=1" >> $GITHUB_ENV - fi - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 @@ -66,21 +95,5 @@ jobs: uses: docker/bake-action@v6 with: targets: ${{ matrix.target }} - - archutil-arm64: - runs-on: ubuntu-24.04-arm - steps: - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - with: - version: ${{ env.SETUP_BUILDX_VERSION }} - driver-opts: image=${{ env.SETUP_BUILDKIT_IMAGE }} - buildkitd-flags: --debug - - - name: Validate - uses: docker/bake-action@v6 - with: - targets: validate-archutil set: | - *.platform=linux/arm64 + *.platform=${{ matrix.platform }} diff --git a/docker-bake.hcl b/docker-bake.hcl index 82e4872fd..9559e2075 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -42,6 +42,10 @@ variable "GOLANGCI_LINT_MULTIPLATFORM" { default = null } +variable "ARCHUTIL_MULTIPLATFORM" { + default = null +} + # Defines the output folder variable "DESTDIR" { default = "" @@ -214,6 +218,10 @@ target "validate-archutil" { dockerfile = "./hack/dockerfiles/archutil.Dockerfile" target = "validate" output = ["type=cacheonly"] + platforms = ARCHUTIL_MULTIPLATFORM != null ? [ + "linux/amd64", + "linux/arm64" + ] : [] } target "validate-shfmt" {