From 1bc598cbb8f4f3cb9d0274f86b484f3dae7e9ae5 Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Tue, 14 May 2024 14:02:37 +0200 Subject: [PATCH] fixes related to actions-toolkit 0.23.0 changes Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com> --- __tests__/context.test.ts | 29 +++++++++++++++++------------ src/context.ts | 2 +- src/main.ts | 5 ++--- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/__tests__/context.test.ts b/__tests__/context.test.ts index e764eb5..63ed0ae 100644 --- a/__tests__/context.test.ts +++ b/__tests__/context.test.ts @@ -39,6 +39,11 @@ jest.spyOn(Docker, 'isAvailable').mockImplementation(async (): Promise return true; }); +const metadataJson = path.join(tmpDir, 'metadata.json'); +jest.spyOn(Bake.prototype, 'getMetadataFilePath').mockImplementation((): string => { + return metadataJson; +}); + jest.spyOn(Builder.prototype, 'inspect').mockImplementation(async (): Promise => { return { name: 'builder2', @@ -152,7 +157,7 @@ describe('getArgs', () => { ]), [ 'bake', - '--metadata-file', path.join(tmpDir, 'metadata-file') + '--metadata-file', metadataJson ] ], [ @@ -167,7 +172,7 @@ describe('getArgs', () => { ]), [ 'bake', - '--metadata-file', path.join(tmpDir, 'metadata-file'), + '--metadata-file', metadataJson, 'webapp', 'validate' ] ], @@ -185,7 +190,7 @@ describe('getArgs', () => { 'bake', '--set', '*.cache-from=type=gha', '--set', '*.cache-to=type=gha', - '--metadata-file', path.join(tmpDir, 'metadata-file') + '--metadata-file', metadataJson ] ], [ @@ -199,7 +204,7 @@ describe('getArgs', () => { ]), [ 'bake', - '--metadata-file', path.join(tmpDir, 'metadata-file'), + '--metadata-file', metadataJson, "--provenance", `mode=min,inline-only=true,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789`, ] ], @@ -215,7 +220,7 @@ describe('getArgs', () => { ]), [ 'bake', - '--metadata-file', path.join(tmpDir, 'metadata-file'), + '--metadata-file', metadataJson, "--provenance", `builder-id=https://github.com/docker/build-push-action/actions/runs/123456789` ] ], @@ -231,7 +236,7 @@ describe('getArgs', () => { ]), [ 'bake', - '--metadata-file', path.join(tmpDir, 'metadata-file'), + '--metadata-file', metadataJson, "--provenance", `mode=max,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789` ] ], @@ -247,7 +252,7 @@ describe('getArgs', () => { ]), [ 'bake', - '--metadata-file', path.join(tmpDir, 'metadata-file'), + '--metadata-file', metadataJson, "--provenance", 'false' ] ], @@ -263,7 +268,7 @@ describe('getArgs', () => { ]), [ 'bake', - '--metadata-file', path.join(tmpDir, 'metadata-file'), + '--metadata-file', metadataJson, "--provenance", 'builder-id=foo' ] ], @@ -282,7 +287,7 @@ describe('getArgs', () => { 'bake', '--set', '*.platform=linux/amd64,linux/ppc64le,linux/s390x', '--set', `*.output=type=image,"name=moby/buildkit:v0.11.0,moby/buildkit:latest",push=true`, - '--metadata-file', path.join(tmpDir, 'metadata-file'), + '--metadata-file', metadataJson, '--provenance', `mode=min,inline-only=true,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789`, 'image-all' ] @@ -301,7 +306,7 @@ describe('getArgs', () => { [ 'bake', '--set', `*.labels.foo=bar=#baz`, - '--metadata-file', path.join(tmpDir, 'metadata-file'), + '--metadata-file', metadataJson, '--provenance', `mode=min,inline-only=true,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789`, 'image-all' ] @@ -321,7 +326,7 @@ describe('getArgs', () => { 'bake', 'https://github.com/docker/build-push-action.git#refs/heads/master', '--file', './foo.hcl', - '--metadata-file', path.join(tmpDir, 'metadata-file'), + '--metadata-file', metadataJson, '--provenance', `mode=min,inline-only=true,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789`, ] ], @@ -336,7 +341,7 @@ describe('getArgs', () => { return buildxVersion; }); const inp = await context.getInputs(); - const definition = await toolkit.bake.getDefinition( + const definition = await toolkit.buildxBake.getDefinition( { files: inp.files, load: inp.load, diff --git a/src/context.ts b/src/context.ts index 9cfe644..1db403e 100644 --- a/src/context.ts +++ b/src/context.ts @@ -65,7 +65,7 @@ async function getBakeArgs(inputs: Inputs, definition: BakeDefinition, toolkit: args.push('--set', set); }); if (await toolkit.buildx.versionSatisfies('>=0.6.0')) { - args.push('--metadata-file', Bake.getMetadataFilePath()); + args.push('--metadata-file', toolkit.buildxBake.getMetadataFilePath()); } if (await toolkit.buildx.versionSatisfies('>=0.10.0')) { if (inputs.provenance) { diff --git a/src/main.ts b/src/main.ts index 5a0a773..53d941d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -3,7 +3,6 @@ import * as path from 'path'; import * as core from '@actions/core'; import * as actionsToolkit from '@docker/actions-toolkit'; -import {Bake} from '@docker/actions-toolkit/lib/buildx/bake'; 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'; @@ -78,7 +77,7 @@ actionsToolkit.run( let definition: BakeDefinition | undefined; await core.group(`Parsing raw definition`, async () => { - definition = await toolkit.bake.getDefinition( + definition = await toolkit.buildxBake.getDefinition( { files: inputs.files, load: inputs.load, @@ -125,7 +124,7 @@ actionsToolkit.run( } }); - const metadata = Bake.resolveMetadata(); + const metadata = toolkit.buildxBake.resolveMetadata(); if (metadata) { await core.group(`Metadata`, async () => { const metadatadt = JSON.stringify(metadata, null, 2);