diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 96c269f..37025a0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 . diff --git a/README.md b/README.md index 94f41c8..903f8e3 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/action.yml b/action.yml index d042f39..5f581a5 100644 --- a/action.yml +++ b/action.yml @@ -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 }} diff --git a/src/context.ts b/src/context.ts index d695376..5e156fb 100644 --- a/src/context.ts +++ b/src/context.ts @@ -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 { 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()); } diff --git a/src/main.ts b/src/main.ts index e6dd12b..a1f1582 100644 --- a/src/main.ts +++ b/src/main.ts @@ -109,6 +109,7 @@ actionsToolkit.run( sbom: inputs.sbom, source: inputs.source.remoteRef, targets: inputs.targets, + vars: inputs.vars, githubToken: gitAuthToken }, {