3
0
Fork 0
mirror of https://gitea.com/docker/metadata-action.git synced 2024-11-22 03:59:33 +01:00

feat: allow the images input to be empty, to output just tags

Signed-off-by: Jason D'Amour <jasondamour98@gmail.com>
This commit is contained in:
Jason D'Amour 2023-06-30 20:02:02 -05:00 committed by CrazyMax
parent 051f7ea71b
commit aacea38e07
No known key found for this signature in database
GPG key ID: ADE44D8C9D44FBE4
2 changed files with 17 additions and 8 deletions

View file

@ -15,10 +15,6 @@ actionsToolkit.run(
// main // main
async () => { async () => {
const inputs: Inputs = getInputs(); const inputs: Inputs = getInputs();
if (inputs.images.length == 0) {
throw new Error(`images input required`);
}
const toolkit = new Toolkit({githubToken: inputs.githubToken}); const toolkit = new Toolkit({githubToken: inputs.githubToken});
const context = await getContext(inputs.context); const context = await getContext(inputs.context);
const repo = await toolkit.github.repoData(); const repo = await toolkit.github.repoData();

View file

@ -441,14 +441,27 @@ export class Meta {
return []; return [];
} }
const tags: Array<string> = []; const tags: Array<string> = [];
for (const imageName of this.getImageNames()) { const images = this.getImageNames();
tags.push(`${imageName}:${this.version.main}`); if (Array.isArray(images) && images.length) {
for (const imageName of images) {
tags.push(`${imageName}:${this.version.main}`);
for (const partial of this.version.partial) {
tags.push(`${imageName}:${partial}`);
}
if (this.version.latest) {
const latestTag = `${this.flavor.prefixLatest ? this.flavor.prefix : ''}latest${this.flavor.suffixLatest ? this.flavor.suffix : ''}`;
tags.push(`${imageName}:${Meta.sanitizeTag(latestTag)}`);
}
}
}
else {
tags.push(this.version.main);
for (const partial of this.version.partial) { for (const partial of this.version.partial) {
tags.push(`${imageName}:${partial}`); tags.push(partial);
} }
if (this.version.latest) { if (this.version.latest) {
const latestTag = `${this.flavor.prefixLatest ? this.flavor.prefix : ''}latest${this.flavor.suffixLatest ? this.flavor.suffix : ''}`; const latestTag = `${this.flavor.prefixLatest ? this.flavor.prefix : ''}latest${this.flavor.suffixLatest ? this.flavor.suffix : ''}`;
tags.push(`${imageName}:${Meta.sanitizeTag(latestTag)}`); tags.push(Meta.sanitizeTag(latestTag));
} }
} }
return tags; return tags;