Merge pull request #420 from crazy-max/vars-input

add vars input for bake variables
This commit is contained in:
CrazyMax
2026-04-15 18:57:05 +02:00
committed by GitHub
7 changed files with 49 additions and 7 deletions
+27
View File
@@ -873,3 +873,30 @@ jobs:
uses: ./
with:
source: ./test/attest
var:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0
with:
version: ${{ inputs.buildx-version || env.BUILDX_VERSION }}
driver-opts: |
image=${{ inputs.buildkit-image || env.BUILDKIT_IMAGE }}
-
name: Build
uses: ./
with:
source: ./test/go
targets: binary
vars: |
DESTDIR=/tmp/build
-
name: Check output folder
working-directory: /tmp/build
run: |
tree .
+1
View File
@@ -239,6 +239,7 @@ The following inputs can be used as `step.with` keys
| `set` | List | List of [targets values to override](https://docs.docker.com/engine/reference/commandline/buildx_bake/#set) (e.g., `targetpattern.key=value`) |
| `source` | String | Build source to use. Supports local path and [remote bake definition](https://docs.docker.com/build/bake/remote-definition/). With a local path, Bake runs from that directory, so all relative paths are resolved from it. See [Source semantics](#source-semantics). |
| `targets` | List/CSV | List of bake targets (`default` target used if empty) |
| `vars` | List | [Variables](https://docs.docker.com/build/bake/variables/) to set in the Bake definition as list of key-value pair |
| `github-token` | String | API token used to authenticate to a Git repository for [remote definitions](https://docs.docker.com/build/bake/remote-definition/) (default `${{ github.token }}`) |
### outputs
+3
View File
@@ -50,6 +50,9 @@ inputs:
targets:
description: "List of bake targets"
required: false
vars:
description: "Variables to set in the Bake definition as list of key-value pair"
required: false
github-token:
description: "API token used to authenticate to a Git repository for remote definitions"
default: ${{ github.token }}
Generated Vendored
+1 -1
View File
File diff suppressed because one or more lines are too long
Generated Vendored
+1 -1
View File
File diff suppressed because one or more lines are too long
+15 -5
View File
@@ -29,6 +29,7 @@ export interface Inputs {
set: string[];
source: BakeContext;
targets: string[];
vars: string[];
'github-token': string;
}
@@ -47,6 +48,7 @@ export async function getInputs(): Promise<Inputs> {
set: Util.getInputList('set', {ignoreComma: true, quote: false}),
source: await getBakeContext(core.getInput('source')),
targets: Util.getInputList('targets'),
vars: Util.getInputList('vars', {ignoreComma: true, quote: false}),
'github-token': core.getInput('github-token')
};
}
@@ -70,22 +72,30 @@ async function getBakeArgs(inputs: Inputs, definition: BakeDefinition, toolkit:
// allow filesystem entitlements by default
inputs.allow.push('fs=*');
}
await Util.asyncForEach(inputs.allow, async allow => {
await Util.asyncForEach(inputs.allow, async (allow: string) => {
args.push('--allow', allow);
});
}
if (inputs.call) {
if (!(await toolkit.buildx.versionSatisfies('>=0.16.0'))) {
throw new Error(`Buildx >= 0.16.0 is required to use the call flag.`);
throw new Error(`Buildx >= 0.16.0 is required to use the call input.`);
}
args.push('--call', inputs.call);
}
await Util.asyncForEach(inputs.files, async file => {
await Util.asyncForEach(inputs.files, async (file: string) => {
args.push('--file', file);
});
await Util.asyncForEach(inputs.set, async set => {
args.push('--set', set);
await Util.asyncForEach(inputs.set, async (s: string) => {
args.push('--set', s);
});
if (inputs.vars.length > 0) {
if (!(await toolkit.buildx.versionSatisfies('>=0.31.0'))) {
throw new Error(`Buildx >= 0.31.0 is required to use the vars input.`);
}
await Util.asyncForEach(inputs.vars, async (v: string) => {
args.push('--var', v);
});
}
if (await toolkit.buildx.versionSatisfies('>=0.6.0')) {
args.push('--metadata-file', toolkit.buildxBake.getMetadataFilePath());
}
+1
View File
@@ -109,6 +109,7 @@ actionsToolkit.run(
sbom: inputs.sbom,
source: inputs.source.remoteRef,
targets: inputs.targets,
vars: inputs.vars,
githubToken: gitAuthToken
},
{