diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b1645a09..c802465c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -26,33 +26,84 @@ jobs: prepare: runs-on: ubuntu-latest outputs: - validate-targets: ${{ steps.validate-targets.outputs.matrix }} - artifact-platforms: ${{ steps.artifact-platforms.outputs.matrix }} + validate-includes: ${{ steps.validate.outputs.includes }} + artifact-platforms: ${{ steps.artifact.outputs.platforms }} steps: - name: Checkout uses: actions/checkout@v4 - - name: Validate targets matrix - id: validate-targets - run: | - echo "matrix=$(docker buildx bake validate --print | jq -cr '.target | keys')" >> $GITHUB_OUTPUT + name: Validate matrix + id: validate + uses: actions/github-script@v7 + env: + GOLANGCI_LINT_MULTIPLATFORM: 1 + with: + script: | + let def = {}; + await core.group(`Parsing definition`, async () => { + const resPrint = await exec.getExecOutput('docker', ['buildx', 'bake', 'validate', '--print'], { + ignoreReturnCode: true + }); + 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)); + }); - - name: Artifact platforms matrix - id: artifact-platforms - run: | - echo "matrix=$(docker buildx bake artifact-all --print | jq -cr '.target."artifact-all".platforms')" >> $GITHUB_OUTPUT + name: Artifact matrix + id: artifact + uses: actions/github-script@v7 + with: + script: | + const targetName = 'artifact-all'; + let def = {}; + await core.group(`Parsing definition`, async () => { + const resPrint = await exec.getExecOutput('docker', ['buildx', 'bake', targetName, '--print'], { + ignoreReturnCode: true + }); + 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 platforms = def.target?.[targetName]?.platforms ?? []; + if (platforms.length === 0) { + throw new Error(`No platforms found for ${targetName} target`); + } + core.info(JSON.stringify(platforms, null, 2)); + core.setOutput('platforms', JSON.stringify(platforms)); + }); validate: runs-on: ubuntu-latest - env: - GOLANGCI_LINT_MULTIPLATFORM: 1 needs: - prepare strategy: fail-fast: false matrix: - target: ${{ fromJson(needs.prepare.outputs.validate-targets) }} + include: ${{ fromJson(needs.prepare.outputs.validate-includes) }} steps: - name: Checkout @@ -66,6 +117,8 @@ jobs: with: source: . targets: ${{ matrix.target }} + set: | + *.platform=${{ matrix.platform }} test: runs-on: ubuntu-latest