mirror of
https://github.com/docker/metadata-action.git
synced 2025-11-05 23:14:42 +08:00
tag-names output to return tag names without image base name
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
@@ -47,7 +47,7 @@ actionsToolkit.run(
|
||||
setOutput('version', version.main || '');
|
||||
|
||||
// Docker tags
|
||||
const tags: Array<string> = meta.getTags();
|
||||
const tags = meta.getTags();
|
||||
if (tags.length == 0) {
|
||||
core.warning('No Docker tag has been generated. Check tags input.');
|
||||
} else {
|
||||
@@ -58,6 +58,7 @@ actionsToolkit.run(
|
||||
});
|
||||
}
|
||||
setOutput('tags', tags.join(inputs.sepTags));
|
||||
setOutput('tag-names', meta.getTags(true).join(inputs.sepTags));
|
||||
|
||||
// Docker labels
|
||||
const labels: Array<string> = meta.getLabels();
|
||||
|
||||
39
src/meta.ts
39
src/meta.ts
@@ -494,33 +494,37 @@ export class Meta {
|
||||
return images;
|
||||
}
|
||||
|
||||
public getTags(): Array<string> {
|
||||
public getTags(namesOnly?: boolean): Array<string> {
|
||||
if (!this.version.main) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const generateTags = (imageName: string, version: string): Array<string> => {
|
||||
const tags: Array<string> = [];
|
||||
const prefix = imageName !== '' ? `${imageName}:` : '';
|
||||
tags.push(`${prefix}${version}`);
|
||||
for (const partial of this.version.partial) {
|
||||
tags.push(`${prefix}${partial}`);
|
||||
}
|
||||
if (this.version.latest) {
|
||||
const latestTag = `${this.flavor.prefixLatest ? this.flavor.prefix : ''}latest${this.flavor.suffixLatest ? this.flavor.suffix : ''}`;
|
||||
tags.push(`${prefix}${Meta.sanitizeTag(latestTag)}`);
|
||||
}
|
||||
return tags;
|
||||
};
|
||||
if (namesOnly) {
|
||||
return this.generateTags(this.version.main);
|
||||
}
|
||||
|
||||
const tags: Array<string> = [];
|
||||
const images = this.getImageNames();
|
||||
if (images.length > 0) {
|
||||
for (const imageName of images) {
|
||||
tags.push(...generateTags(imageName, this.version.main));
|
||||
tags.push(...this.generateTags(this.version.main, imageName));
|
||||
}
|
||||
} else {
|
||||
tags.push(...generateTags('', this.version.main));
|
||||
tags.push(...this.generateTags(this.version.main));
|
||||
}
|
||||
|
||||
return tags;
|
||||
}
|
||||
|
||||
private generateTags(version: string, imageName?: string): Array<string> {
|
||||
const tags: Array<string> = [];
|
||||
const prefix = imageName ? `${imageName}:` : '';
|
||||
tags.push(`${prefix}${version}`);
|
||||
for (const partial of this.version.partial) {
|
||||
tags.push(`${prefix}${partial}`);
|
||||
}
|
||||
if (this.version.latest) {
|
||||
const latestTag = `${this.flavor.prefixLatest ? this.flavor.prefix : ''}latest${this.flavor.suffixLatest ? this.flavor.suffix : ''}`;
|
||||
tags.push(`${prefix}${Meta.sanitizeTag(latestTag)}`);
|
||||
}
|
||||
return tags;
|
||||
}
|
||||
@@ -568,6 +572,7 @@ export class Meta {
|
||||
}
|
||||
return {
|
||||
tags: this.getTags(),
|
||||
'tag-names': this.getTags(true),
|
||||
labels: this.getLabels().reduce((res, label) => {
|
||||
const matches = label.match(/([^=]*)=(.*)/);
|
||||
if (!matches) {
|
||||
|
||||
Reference in New Issue
Block a user