call input to set method for evaluating build

Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2025-07-30 15:20:30 +02:00
parent 6de75d5ad2
commit 24d8c3471c
5 changed files with 140 additions and 20 deletions

View File

@@ -11,11 +11,12 @@ import {Util} from '@docker/actions-toolkit/lib/util';
import {BakeDefinition} from '@docker/actions-toolkit/lib/types/buildx/bake';
export interface Inputs {
allow: string[];
builder: string;
files: string[];
workdir: string;
targets: string[];
source: string;
allow: string[];
call: string;
files: string[];
'no-cache': boolean;
pull: boolean;
load: boolean;
@@ -23,17 +24,18 @@ export interface Inputs {
push: boolean;
sbom: string;
set: string[];
source: string;
targets: string[];
'github-token': string;
}
export async function getInputs(): Promise<Inputs> {
return {
allow: Util.getInputList('allow'),
builder: core.getInput('builder'),
files: Util.getInputList('files'),
workdir: core.getInput('workdir') || '.',
targets: Util.getInputList('targets'),
source: getSourceInput('source'),
allow: Util.getInputList('allow'),
call: core.getInput('call'),
files: Util.getInputList('files'),
'no-cache': core.getBooleanInput('no-cache'),
pull: core.getBooleanInput('pull'),
load: core.getBooleanInput('load'),
@@ -41,7 +43,7 @@ export async function getInputs(): Promise<Inputs> {
push: core.getBooleanInput('push'),
sbom: core.getInput('sbom'),
set: Util.getInputList('set', {ignoreComma: true, quote: false}),
source: getSourceInput('source'),
targets: Util.getInputList('targets'),
'github-token': core.getInput('github-token')
};
}
@@ -69,6 +71,12 @@ async function getBakeArgs(inputs: Inputs, definition: BakeDefinition, toolkit:
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.`);
}
args.push('--call', inputs.call);
}
await Util.asyncForEach(inputs.files, async file => {
args.push('--file', file);
});

View File

@@ -146,8 +146,26 @@ actionsToolkit.run(
env: buildEnv,
ignoreReturnCode: true
}).then(res => {
if (res.stderr.length > 0 && res.exitCode != 0) {
err = Error(`buildx bake failed with: ${res.stderr.match(/(.*)\s*$/)?.[0]?.trim() ?? 'unknown error'}`);
if (res.exitCode != 0) {
if (inputs.call && inputs.call === 'check' && res.stdout.length > 0) {
// checks warnings are printed to stdout: https://github.com/docker/buildx/pull/2647
// with bake we can have multiple targets being checked so we need to
// count the total number of warnings
const totalWarnings = [...res.stdout.matchAll(/^Check complete, (\d+) warnings? (?:has|have) been found!/gm)].reduce((sum, m) => sum + parseInt(m[1], 10), 0);
if (totalWarnings > 0) {
// https://github.com/docker/buildx/blob/1e50e8ddabe108f009b9925e13a321d7c8f99f26/commands/build.go#L797-L803
if (totalWarnings === 1) {
err = Error(`Check complete, ${totalWarnings} warning has been found!`);
} else {
err = Error(`Check complete, ${totalWarnings} warnings have been found!`);
}
} else {
// if there are no warnings found, return the first line of stdout
err = Error(res.stdout.split('\n')[0]?.trim());
}
} else if (res.stderr.length > 0) {
err = Error(`buildx bake failed with: ${res.stderr.match(/(.*)\s*$/)?.[0]?.trim() ?? 'unknown error'}`);
}
}
});
@@ -191,6 +209,8 @@ actionsToolkit.run(
await core.group(`Check build summary support`, async () => {
if (!buildSummaryEnabled()) {
core.info('Build summary disabled');
} else if (inputs.call && inputs.call !== 'build') {
core.info(`Build summary skipped for ${inputs.call} subrequest`);
} else if (GitHub.isGHES) {
core.info('Build summary is not yet supported on GHES');
} else if (!(await toolkit.buildx.versionSatisfies('>=0.13.0'))) {