-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: CrazyMax <[email protected]>
- Loading branch information
Showing
3 changed files
with
164 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
# https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions | ||
name: 'Matrix' | ||
description: 'Generate a matrix from a Bake definition to help distributing builds in your workflow' | ||
|
||
inputs: | ||
workdir: | ||
description: Working directory | ||
default: '.' | ||
required: false | ||
files: | ||
description: List of Bake files | ||
required: false | ||
target: | ||
description: Bake target | ||
required: false | ||
fields: | ||
description: Comma separated list of extra fields to include in the matrix | ||
required: false | ||
|
||
outputs: | ||
matrix: | ||
description: List of includes as matrix | ||
value: ${{ steps.generate.outputs.includes }} | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
- | ||
name: Generate | ||
id: generate | ||
uses: actions/github-script@v7 | ||
with: | ||
script: | | ||
let def; | ||
const files = `${{ inputs.files }}` ? `${{ inputs.files }}`.split('\n') : []; | ||
const target = `${{ inputs.target }}`; | ||
const fields = `${{ inputs.fields }}` ? `${{ inputs.fields }}`.split(',') : []; | ||
await core.group(`Parsing definition`, async () => { | ||
let args = ['buildx', 'bake']; | ||
for (const file of files) { | ||
args.push('--file', file); | ||
} | ||
if (target) { | ||
args.push(target); | ||
} | ||
args.push('--print'); | ||
const res = await exec.getExecOutput('docker', args, { | ||
ignoreReturnCode: true, | ||
silent: true, | ||
cwd: `${{ inputs.workdir }}` | ||
}); | ||
if (res.stderr.length > 0 && res.exitCode != 0) { | ||
throw new Error(res.stderr); | ||
} | ||
def = JSON.parse(res.stdout.trim()); | ||
core.info(JSON.stringify(def, null, 2)); | ||
}); | ||
await core.group(`Generating matrix`, async () => { | ||
let includes = []; | ||
for (const targetName of Object.keys(def.target)) { | ||
const target = def.target[targetName]; | ||
if (fields.length > 0) { | ||
let hasFields = false; | ||
fields.forEach(field => { | ||
if (target[field]) { | ||
hasFields = true; | ||
if (Array.isArray(target[field])) { | ||
target[field].forEach(value => { | ||
const include = { target: targetName }; | ||
include[field] = value; | ||
includes.push(include); | ||
}); | ||
} else { | ||
const include = { target: targetName }; | ||
include[field] = target[field]; | ||
includes.push(include); | ||
} | ||
} else { | ||
core.warning(`Field "${field}" not found in target ${targetName}`); | ||
} | ||
}); | ||
if (!hasFields) { | ||
includes.push({ | ||
target: targetName | ||
}); | ||
} | ||
} else { | ||
includes.push({ | ||
target: targetName | ||
}); | ||
} | ||
} | ||
core.info(JSON.stringify(includes, null, 2)); | ||
core.setOutput('includes', JSON.stringify(includes)); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
group "validate" { | ||
targets = ["lint", "lint-gopls", "validate-vendor", "validate-docs"] | ||
} | ||
|
||
target "lint" { | ||
dockerfile = "./hack/dockerfiles/lint.Dockerfile" | ||
output = ["type=cacheonly"] | ||
platforms = [ | ||
"darwin/amd64", | ||
"darwin/arm64", | ||
"linux/amd64", | ||
"linux/arm64", | ||
"linux/s390x", | ||
"linux/ppc64le", | ||
"linux/riscv64", | ||
"windows/amd64", | ||
"windows/arm64" | ||
] | ||
} | ||
|
||
target "lint-gopls" { | ||
inherits = ["lint"] | ||
target = "gopls-analyze" | ||
} | ||
|
||
target "validate-vendor" { | ||
dockerfile = "./hack/dockerfiles/vendor.Dockerfile" | ||
target = "validate" | ||
output = ["type=cacheonly"] | ||
} | ||
|
||
target "validate-docs" { | ||
dockerfile = "./hack/dockerfiles/docs.Dockerfile" | ||
target = "validate" | ||
output = ["type=cacheonly"] | ||
} |