From a54198e85aba1b4e4005e4cae89b66bcc551d948 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Mon, 17 Apr 2023 01:32:21 +0200 Subject: [PATCH] use new implementation from toolkit Signed-off-by: CrazyMax --- __tests__/context.test.ts | 2 +- src/context.ts | 18 +++++++++--------- src/main.ts | 9 +++++---- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/__tests__/context.test.ts b/__tests__/context.test.ts index deb205a..66a1ddc 100644 --- a/__tests__/context.test.ts +++ b/__tests__/context.test.ts @@ -609,7 +609,7 @@ nproc=3`], jest.spyOn(Buildx.prototype, 'version').mockImplementation(async (): Promise => { return buildxVersion; }); - const inp = await context.getInputs(toolkit); + const inp = await context.getInputs(); const res = await context.getArgs(inp, toolkit); expect(res).toEqual(expected); } diff --git a/src/context.ts b/src/context.ts index efb2230..a0d2b22 100644 --- a/src/context.ts +++ b/src/context.ts @@ -39,7 +39,7 @@ export interface Inputs { githubToken: string; } -export async function getInputs(toolkit: Toolkit): Promise { +export async function getInputs(): Promise { return { addHosts: Util.getInputList('add-hosts'), allow: Util.getInputList('allow'), @@ -59,7 +59,7 @@ export async function getInputs(toolkit: Toolkit): Promise { noCacheFilters: Util.getInputList('no-cache-filters'), outputs: Util.getInputList('outputs', {ignoreComma: true}), platforms: Util.getInputList('platforms'), - provenance: toolkit.buildx.inputs.getProvenanceInput('provenance'), + provenance: BuildxInputs.getProvenanceInput('provenance'), pull: core.getBooleanInput('pull'), push: core.getBooleanInput('push'), sbom: core.getInput('sbom'), @@ -120,7 +120,7 @@ async function getBuildArgs(inputs: Inputs, context: string, toolkit: Toolkit): args.push('--file', inputs.file); } if (!BuildxInputs.hasLocalExporter(inputs.outputs) && !BuildxInputs.hasTarExporter(inputs.outputs) && (inputs.platforms.length == 0 || (await toolkit.buildx.versionSatisfies('>=0.4.2')))) { - args.push('--iidfile', toolkit.buildx.inputs.getBuildImageIDFilePath()); + args.push('--iidfile', BuildxInputs.getBuildImageIDFilePath()); } await Util.asyncForEach(inputs.labels, async label => { args.push('--label', label); @@ -144,10 +144,10 @@ async function getBuildArgs(inputs: Inputs, context: string, toolkit: Toolkit): if (GitHub.context.payload.repository?.private ?? false) { // if this is a private repository, we set the default provenance // attributes being set in buildx: https://github.com/docker/buildx/blob/fb27e3f919dcbf614d7126b10c2bc2d0b1927eb6/build/build.go#L603 - args.push('--provenance', toolkit.buildx.inputs.resolveProvenanceAttrs(`mode=min,inline-only=true`)); + args.push('--provenance', BuildxInputs.resolveProvenanceAttrs(`mode=min,inline-only=true`)); } else { // for a public repository, we set max provenance mode. - args.push('--provenance', toolkit.buildx.inputs.resolveProvenanceAttrs(`mode=max`)); + args.push('--provenance', BuildxInputs.resolveProvenanceAttrs(`mode=max`)); } } if (inputs.sbom) { @@ -156,20 +156,20 @@ async function getBuildArgs(inputs: Inputs, context: string, toolkit: Toolkit): } await Util.asyncForEach(inputs.secrets, async secret => { try { - args.push('--secret', toolkit.buildx.inputs.resolveBuildSecretString(secret)); + args.push('--secret', BuildxInputs.resolveBuildSecretString(secret)); } catch (err) { core.warning(err.message); } }); await Util.asyncForEach(inputs.secretFiles, async secretFile => { try { - args.push('--secret', toolkit.buildx.inputs.resolveBuildSecretFile(secretFile)); + args.push('--secret', BuildxInputs.resolveBuildSecretFile(secretFile)); } catch (err) { core.warning(err.message); } }); if (inputs.githubToken && !BuildxInputs.hasGitAuthTokenSecret(inputs.secrets) && context.startsWith(Context.gitContext())) { - args.push('--secret', toolkit.buildx.inputs.resolveBuildSecretString(`GIT_AUTH_TOKEN=${inputs.githubToken}`)); + args.push('--secret', BuildxInputs.resolveBuildSecretString(`GIT_AUTH_TOKEN=${inputs.githubToken}`)); } if (inputs.shmSize) { args.push('--shm-size', inputs.shmSize); @@ -198,7 +198,7 @@ async function getCommonArgs(inputs: Inputs, toolkit: Toolkit): Promise=0.6.0')) { - args.push('--metadata-file', toolkit.buildx.inputs.getBuildMetadataFilePath()); + args.push('--metadata-file', BuildxInputs.getBuildMetadataFilePath()); } if (inputs.network) { args.push('--network', inputs.network); diff --git a/src/main.ts b/src/main.ts index 5debee2..5c236e2 100644 --- a/src/main.ts +++ b/src/main.ts @@ -6,6 +6,7 @@ import {Context} from '@docker/actions-toolkit/lib/context'; import {Docker} from '@docker/actions-toolkit/lib/docker/docker'; import {Exec} from '@docker/actions-toolkit/lib/exec'; import {GitHub} from '@docker/actions-toolkit/lib/github'; +import {Inputs as BuildxInputs} from '@docker/actions-toolkit/lib/buildx/inputs'; import {Toolkit} from '@docker/actions-toolkit/lib/toolkit'; import * as context from './context'; @@ -13,8 +14,8 @@ import * as context from './context'; actionsToolkit.run( // main async () => { + const inputs: context.Inputs = await context.getInputs(); const toolkit = new Toolkit(); - const inputs: context.Inputs = await context.getInputs(toolkit); await core.group(`GitHub Actions runtime token ACs`, async () => { try { @@ -54,9 +55,9 @@ actionsToolkit.run( } }); - const imageID = await toolkit.buildx.inputs.resolveBuildImageID(); - const metadata = await toolkit.buildx.inputs.resolveBuildMetadata(); - const digest = await toolkit.buildx.inputs.resolveDigest(); + const imageID = BuildxInputs.resolveBuildImageID(); + const metadata = BuildxInputs.resolveBuildMetadata(); + const digest = BuildxInputs.resolveDigest(); if (imageID) { await core.group(`ImageID`, async () => {