accept JSON arrays for bake vars to preserve multiline values

Parse the vars input as a JSON array of strings, falling back to the
existing list parser when JSON parsing fails. Preserve multiline values,
whitespace, and literal quotes in each Buildx --var argument.

Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2026-10-13 09:34:38 +02:00
parent cac84ca08e
commit a0190aa0a4
4 changed files with 90 additions and 3 deletions
+14 -1
View File
@@ -48,7 +48,7 @@ export async function getInputs(): Promise<Inputs> {
set: Util.getInputList('set', {ignoreComma: true, quote: false}),
source: await getBakeContext(core.getInput('source')),
targets: Util.getInputList('targets'),
vars: Util.getInputList('vars', {ignoreComma: true, quote: false}),
vars: getBakeVars(core.getInput('vars')),
'github-token': core.getInput('github-token')
};
}
@@ -171,6 +171,19 @@ async function getBakeContext(sourceInput: string): Promise<BakeContext> {
};
}
function getBakeVars(varsInput: string): string[] {
let parsed: unknown;
try {
parsed = JSON.parse(varsInput);
} catch {
return Util.getList(varsInput, {ignoreComma: true, quote: false});
}
if (!Array.isArray(parsed) || !parsed.every(value => typeof value === 'string')) {
throw new Error('Invalid vars input: expected a JSON array of strings.');
}
return parsed;
}
function noDefaultAttestations(): boolean {
if (process.env.BUILDX_NO_DEFAULT_ATTESTATIONS) {
return Util.parseBool(process.env.BUILDX_NO_DEFAULT_ATTESTATIONS);