mirror of
https://github.com/docker/bake-action.git
synced 2026-10-15 20:00:28 +02:00
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:
+14
-1
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user