Make input username and password optional

If user has authenticated to container image registry
before running this action, then it's not required
to provide username and password in this action

Signed-off-by: divyansh42 <diagrawa@redhat.com>
This commit is contained in:
divyansh42 2021-04-09 14:56:06 +05:30
parent 002092527f
commit 2c3fb7261b
7 changed files with 49 additions and 84 deletions

View file

@ -49,8 +49,8 @@ async function run(): Promise<void> {
tagsList.push(DEFAULT_TAG);
}
const registry = core.getInput(Inputs.REGISTRY, { required: true });
const username = core.getInput(Inputs.USERNAME, { required: true });
const password = core.getInput(Inputs.PASSWORD, { required: true });
const username = core.getInput(Inputs.USERNAME);
const password = core.getInput(Inputs.PASSWORD);
const tlsVerify = core.getInput(Inputs.TLS_VERIFY);
const digestFileInput = core.getInput(Inputs.DIGESTFILE);
@ -158,7 +158,10 @@ async function run(): Promise<void> {
const registryWithoutTrailingSlash = registry.replace(/\/$/, "");
const creds = `${username}:${password}`;
let creds = "";
if (username && password) {
creds = `${username}:${password}`;
}
let digestFile = digestFileInput;
const imageNameWithTag = `${imageToPush}:${tagsList[0]}`;
@ -179,8 +182,6 @@ async function run(): Promise<void> {
"--quiet",
"--digestfile",
digestFile,
"--creds",
creds,
imageWithTag,
registryPath,
];
@ -194,6 +195,11 @@ async function run(): Promise<void> {
args.push(`--tls-verify=${tlsVerify}`);
}
// check if registry creds are provided
if (creds) {
args.push(`--creds=${creds}`);
}
await execute(await getPodmanPath(), args);
core.info(`Successfully pushed "${imageWithTag}" to "${registryPath}"`);