From e474cef09b1eee487e65bc56c52e6f9216436e47 Mon Sep 17 00:00:00 2001 From: David Hiendl Date: Sat, 2 Dec 2023 23:25:45 +0100 Subject: [PATCH] support build_args --- action.yml | 5 +++++ dist/index.js | 20 ++++++++++++++++++++ src/lib.js | 20 ++++++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/action.yml b/action.yml index bd9e988..98bb1ea 100644 --- a/action.yml +++ b/action.yml @@ -96,6 +96,11 @@ inputs: default: "" required: false + build_args: + description: "list of docker build args to pass to docker (--build-arg key1=value1) as newline seperated multiline string, eg key1=value1\nkey2=value2" + default: "" + required: false + outputs: published_tags: description: "Published tags as csv" diff --git a/dist/index.js b/dist/index.js index 3ca1470..ba5f718 100644 --- a/dist/index.js +++ b/dist/index.js @@ -62276,6 +62276,26 @@ function prepareDockerArgs(destinations) { dockerArgs.push(core.getInput('additional_registry_destinations')); } + if (isNonEmptyStr(core.getInput('build_args'))) { + let buildArgs = core.getInput('build_args') + .split('\n') + .map(s => s.trim()) + .map(s => { + const equalIndex = s.indexOf('='); + const key = s.substring(0, equalIndex - 1); + const value = s.substring(equalIndex + 1); + return { + key, + value + }; + }); + + console.logs('parsed build_args as: ', JSON.stringify(buildArgs, null, 2)); + buildArgs.forEach(arg => { + dockerArgs.push(`--build-arg ${arg.key}="${arv.value}"`); + }); + } + return dockerArgs; } diff --git a/src/lib.js b/src/lib.js index e042889..003a935 100644 --- a/src/lib.js +++ b/src/lib.js @@ -174,6 +174,26 @@ export function prepareDockerArgs(destinations) { dockerArgs.push(core.getInput('additional_registry_destinations')); } + if (isNonEmptyStr(core.getInput('build_args'))) { + let buildArgs = core.getInput('build_args') + .split('\n') + .map(s => s.trim()) + .map(s => { + const equalIndex = s.indexOf('='); + const key = s.substring(0, equalIndex - 1); + const value = s.substring(equalIndex + 1); + return { + key, + value + }; + }); + + console.logs('parsed build_args as: ', JSON.stringify(buildArgs, null, 2)); + buildArgs.forEach(arg => { + dockerArgs.push(`--build-arg ${arg.key}="${arv.value}"`); + }); + } + return dockerArgs; }