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

View File

@@ -873,3 +873,30 @@ jobs:
uses: ./ uses: ./
with: with:
source: ./test/attest 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 .

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`) | | `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). | | `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) | | `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 }}`) | | `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 ### outputs

View File

@@ -50,6 +50,9 @@ inputs:
targets: targets:
description: "List of bake targets" description: "List of bake targets"
required: false required: false
vars:
description: "Variables to set in the Bake definition as list of key-value pair"
required: false
github-token: github-token:
description: "API token used to authenticate to a Git repository for remote definitions" description: "API token used to authenticate to a Git repository for remote definitions"
default: ${{ github.token }} default: ${{ github.token }}

2
dist/index.js generated vendored

File diff suppressed because one or more lines are too long

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View File

@@ -29,6 +29,7 @@ export interface Inputs {
set: string[]; set: string[];
source: BakeContext; source: BakeContext;
targets: string[]; targets: string[];
vars: string[];
'github-token': string; 'github-token': string;
} }
@@ -47,6 +48,7 @@ export async function getInputs(): Promise<Inputs> {
set: Util.getInputList('set', {ignoreComma: true, quote: false}), set: Util.getInputList('set', {ignoreComma: true, quote: false}),
source: await getBakeContext(core.getInput('source')), source: await getBakeContext(core.getInput('source')),
targets: Util.getInputList('targets'), targets: Util.getInputList('targets'),
vars: Util.getInputList('vars', {ignoreComma: true, quote: false}),
'github-token': core.getInput('github-token') 'github-token': core.getInput('github-token')
}; };
} }
@@ -70,22 +72,30 @@ async function getBakeArgs(inputs: Inputs, definition: BakeDefinition, toolkit:
// allow filesystem entitlements by default // allow filesystem entitlements by default
inputs.allow.push('fs=*'); inputs.allow.push('fs=*');
} }
await Util.asyncForEach(inputs.allow, async allow => { await Util.asyncForEach(inputs.allow, async (allow: string) => {
args.push('--allow', allow); args.push('--allow', allow);
}); });
} }
if (inputs.call) { if (inputs.call) {
if (!(await toolkit.buildx.versionSatisfies('>=0.16.0'))) { 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); args.push('--call', inputs.call);
} }
await Util.asyncForEach(inputs.files, async file => { await Util.asyncForEach(inputs.files, async (file: string) => {
args.push('--file', file); args.push('--file', file);
}); });
await Util.asyncForEach(inputs.set, async set => { await Util.asyncForEach(inputs.set, async (s: string) => {
args.push('--set', set); 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')) { if (await toolkit.buildx.versionSatisfies('>=0.6.0')) {
args.push('--metadata-file', toolkit.buildxBake.getMetadataFilePath()); args.push('--metadata-file', toolkit.buildxBake.getMetadataFilePath());
} }

View File

@@ -109,6 +109,7 @@ actionsToolkit.run(
sbom: inputs.sbom, sbom: inputs.sbom,
source: inputs.source.remoteRef, source: inputs.source.remoteRef,
targets: inputs.targets, targets: inputs.targets,
vars: inputs.vars,
githubToken: gitAuthToken githubToken: gitAuthToken
}, },
{ {