From b3435979d1fb0a7ebc8b0aabb7b99e179b5a4a4f Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Sun, 12 Mar 2023 23:34:24 +0100 Subject: [PATCH] use methods from toolkit to handle provenance attrs Signed-off-by: CrazyMax --- __tests__/context.test.ts | 10 ++++----- package.json | 1 - src/context.ts | 43 ++++----------------------------------- src/main.ts | 4 ++-- 4 files changed, 11 insertions(+), 47 deletions(-) diff --git a/__tests__/context.test.ts b/__tests__/context.test.ts index 6595599..deb205a 100644 --- a/__tests__/context.test.ts +++ b/__tests__/context.test.ts @@ -4,7 +4,7 @@ import * as path from 'path'; import {Builder} from '@docker/actions-toolkit/lib/buildx/builder'; import {Buildx} from '@docker/actions-toolkit/lib/buildx/buildx'; import {Context} from '@docker/actions-toolkit/lib/context'; -import {Docker} from '@docker/actions-toolkit/lib/docker'; +import {Docker} from '@docker/actions-toolkit/lib/docker/docker'; import {GitHub} from '@docker/actions-toolkit/lib/github'; import {Toolkit} from '@docker/actions-toolkit/lib/toolkit'; import {BuilderInfo} from '@docker/actions-toolkit/lib/types/builder'; @@ -42,9 +42,9 @@ jest.spyOn(Builder.prototype, 'inspect').mockImplementation(async (): Promise => { return buildxVersion; }); - const inp = await context.getInputs(); + const inp = await context.getInputs(toolkit); const res = await context.getArgs(inp, toolkit); expect(res).toEqual(expected); } diff --git a/package.json b/package.json index e21b81c..3cb1dd2 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,6 @@ "dependencies": { "@actions/core": "^1.10.0", "@docker/actions-toolkit": "^0.1.0-beta.19", - "csv-parse": "^5.3.5", "handlebars": "^4.7.7" }, "devDependencies": { diff --git a/src/context.ts b/src/context.ts index 91121a0..efb2230 100644 --- a/src/context.ts +++ b/src/context.ts @@ -1,5 +1,4 @@ import * as core from '@actions/core'; -import {parse} from 'csv-parse/sync'; import * as handlebars from 'handlebars'; import {Context} from '@docker/actions-toolkit/lib/context'; import {GitHub} from '@docker/actions-toolkit/lib/github'; @@ -40,7 +39,7 @@ export interface Inputs { githubToken: string; } -export async function getInputs(): Promise { +export async function getInputs(toolkit: Toolkit): Promise { return { addHosts: Util.getInputList('add-hosts'), allow: Util.getInputList('allow'), @@ -60,7 +59,7 @@ export async function getInputs(): Promise { noCacheFilters: Util.getInputList('no-cache-filters'), outputs: Util.getInputList('outputs', {ignoreComma: true}), platforms: Util.getInputList('platforms'), - provenance: getProvenanceInput('provenance'), + provenance: toolkit.buildx.inputs.getProvenanceInput('provenance'), pull: core.getBooleanInput('pull'), push: core.getBooleanInput('push'), sbom: core.getInput('sbom'), @@ -145,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', getProvenanceAttrs(`mode=min,inline-only=true`)); + args.push('--provenance', toolkit.buildx.inputs.resolveProvenanceAttrs(`mode=min,inline-only=true`)); } else { // for a public repository, we set max provenance mode. - args.push('--provenance', getProvenanceAttrs(`mode=max`)); + args.push('--provenance', toolkit.buildx.inputs.resolveProvenanceAttrs(`mode=max`)); } } if (inputs.sbom) { @@ -215,37 +214,3 @@ async function getCommonArgs(inputs: Inputs, toolkit: Toolkit): Promise item.trim()); - if (parts[0] == 'builder-id') { - return input; - } - } - // if not add builder-id attribute - return `${input},builder-id=${Context.provenanceBuilderID()}`; -} diff --git a/src/main.ts b/src/main.ts index ea470c5..5debee2 100644 --- a/src/main.ts +++ b/src/main.ts @@ -3,7 +3,7 @@ import * as stateHelper from './state-helper'; import * as core from '@actions/core'; import * as actionsToolkit from '@docker/actions-toolkit'; import {Context} from '@docker/actions-toolkit/lib/context'; -import {Docker} from '@docker/actions-toolkit/lib/docker'; +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 {Toolkit} from '@docker/actions-toolkit/lib/toolkit'; @@ -13,8 +13,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 {