Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(deps): Bump @docker/actions-toolkit from 0.19.0 to 0.20.0 #197

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions __tests__/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jest.spyOn(Builder.prototype, 'inspect').mockImplementation(async (): Promise<Bu
};
});

jest.spyOn(Bake.prototype, 'parseDefinitions').mockImplementation(async (): Promise<BakeDefinition> => {
jest.spyOn(Bake.prototype, 'getDefinition').mockImplementation(async (): Promise<BakeDefinition> => {
return JSON.parse(`{
"group": {
"default": {
Expand Down Expand Up @@ -334,7 +334,23 @@ describe('getArgs', () => {
return buildxVersion;
});
const inp = await context.getInputs();
const res = await context.getArgs(inp, toolkit);
const definition = await toolkit.bake.getDefinition(
{
files: inp.files,
load: inp.load,
noCache: inp.noCache,
overrides: inp.set,
provenance: inp.provenance,
push: inp.push,
sbom: inp.sbom,
source: inp.source,
targets: inp.targets
},
{
cwd: inp.workdir
}
);
const res = await context.getArgs(inp, definition, toolkit);
expect(res).toEqual(expected);
}
);
Expand Down
4 changes: 2 additions & 2 deletions dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"license": "Apache-2.0",
"dependencies": {
"@actions/core": "^1.10.1",
"@docker/actions-toolkit": "^0.19.0",
"@docker/actions-toolkit": "^0.20.0",
"handlebars": "^4.7.8"
},
"devDependencies": {
Expand Down
32 changes: 18 additions & 14 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {Inputs as BuildxInputs} from '@docker/actions-toolkit/lib/buildx/inputs'
import {GitHub} from '@docker/actions-toolkit/lib/github';
import {Toolkit} from '@docker/actions-toolkit/lib/toolkit';
import {Util} from '@docker/actions-toolkit/lib/util';
import {BakeDefinition} from '@docker/actions-toolkit/lib/types/bake';

export interface Inputs {
builder: string;
Expand Down Expand Up @@ -35,29 +36,23 @@ export async function getInputs(): Promise<Inputs> {
push: core.getBooleanInput('push'),
sbom: core.getInput('sbom'),
set: Util.getInputList('set', {ignoreComma: true, quote: false}),
source: core.getInput('source')
source: getSourceInput('source')
};
}

export async function getArgs(inputs: Inputs, toolkit: Toolkit): Promise<Array<string>> {
export async function getArgs(inputs: Inputs, definition: BakeDefinition, toolkit: Toolkit): Promise<Array<string>> {
// prettier-ignore
return [
...await getBakeArgs(inputs, toolkit),
...await getBakeArgs(inputs, definition, toolkit),
...await getCommonArgs(inputs),
...inputs.targets
];
}

async function getBakeArgs(inputs: Inputs, toolkit: Toolkit): Promise<Array<string>> {
async function getBakeArgs(inputs: Inputs, definition: BakeDefinition, toolkit: Toolkit): Promise<Array<string>> {
const args: Array<string> = ['bake'];
let source = handlebars.compile(inputs.source)({
defaultContext: Context.gitContext()
});
if (source === '.') {
source = '';
}
if (source) {
args.push(source);
if (inputs.source) {
args.push(inputs.source);
}
await Util.asyncForEach(inputs.files, async file => {
args.push('--file', file);
Expand All @@ -69,10 +64,9 @@ async function getBakeArgs(inputs: Inputs, toolkit: Toolkit): Promise<Array<stri
args.push('--metadata-file', BuildxInputs.getBuildMetadataFilePath());
}
if (await toolkit.buildx.versionSatisfies('>=0.10.0')) {
const bakedef = await toolkit.bake.parseDefinitions([...inputs.files, source], inputs.targets, inputs.set, inputs.load, inputs.push, inputs.workdir);
if (inputs.provenance) {
args.push('--provenance', inputs.provenance);
} else if ((await toolkit.buildkit.versionSatisfies(inputs.builder, '>=0.11.0')) && !Bake.hasDockerExporter(bakedef, inputs.load)) {
} else if ((await toolkit.buildkit.versionSatisfies(inputs.builder, '>=0.11.0')) && !Bake.hasDockerExporter(definition, inputs.load)) {
// if provenance not specified and BuildKit version compatible for
// attestation, set default provenance. Also needs to make sure user
// doesn't want to explicitly load the image to docker.
Expand Down Expand Up @@ -111,3 +105,13 @@ async function getCommonArgs(inputs: Inputs): Promise<Array<string>> {
}
return args;
}

function getSourceInput(name: string): string {
let source = handlebars.compile(core.getInput(name))({
defaultContext: Context.gitContext()
});
if (source === '.') {
source = '';
}
return source;
}
26 changes: 25 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ 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';
import {BakeDefinition} from '@docker/actions-toolkit/lib/types/bake';
import {ConfigFile} from '@docker/actions-toolkit/lib/types/docker';

import * as context from './context';
Expand Down Expand Up @@ -72,7 +73,30 @@ actionsToolkit.run(
await toolkit.buildx.printVersion();
});

const args: string[] = await context.getArgs(inputs, toolkit);
let definition: BakeDefinition | undefined;
await core.group(`Parsing raw definition`, async () => {
definition = await toolkit.bake.getDefinition(
{
files: inputs.files,
load: inputs.load,
noCache: inputs.noCache,
overrides: inputs.set,
provenance: inputs.provenance,
push: inputs.push,
sbom: inputs.sbom,
source: inputs.source,
targets: inputs.targets
},
{
cwd: inputs.workdir
}
);
});
if (!definition) {
throw new Error('Bake definition not set');
}

const args: string[] = await context.getArgs(inputs, definition, toolkit);
const buildCmd = await toolkit.buildx.getCommand(args);

await core.group(`Bake definition`, async () => {
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -765,10 +765,10 @@
dependencies:
"@jridgewell/trace-mapping" "0.3.9"

"@docker/actions-toolkit@^0.19.0":
version "0.19.0"
resolved "https://registry.yarnpkg.com/@docker/actions-toolkit/-/actions-toolkit-0.19.0.tgz#3b17d06c46d60142423651ddb9d390f65f109a8c"
integrity sha512-Es08sgfIBOsEBQLfrJQtfgf5mM9Rl4nfZ7byYQ+umbI7VcUEF4AusyNfqsZob7ZRGu+YUw2jJivZysjVCz6LMg==
"@docker/actions-toolkit@^0.20.0":
version "0.20.0"
resolved "https://registry.yarnpkg.com/@docker/actions-toolkit/-/actions-toolkit-0.20.0.tgz#9619ff5da7f282e02e22509a5f2f1d707d4437fe"
integrity sha512-oAHSQnWjEyRGmGXePt5A/rZG76U/gddQWF/JmD8lZQOL5WZ7WgfUd2MucOaxq3cd66rMew+iwkfqDzFJQewQQw==
dependencies:
"@actions/cache" "^3.2.4"
"@actions/core" "^1.10.1"
Expand Down
Loading