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:
@@ -314,6 +314,7 @@ The following outputs are available:
|
|||||||
|-------------------------|--------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|-------------------------|--------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
| `version` | String | Docker image version |
|
| `version` | String | Docker image version |
|
||||||
| `tags` | String | Docker tags |
|
| `tags` | String | Docker tags |
|
||||||
|
| `tag-names` | String | Docker tag names without image base name |
|
||||||
| `labels` | String | Docker labels |
|
| `labels` | String | Docker labels |
|
||||||
| `annotations` | String | [Annotations](https://github.com/moby/buildkit/blob/master/docs/annotations.md) |
|
| `annotations` | String | [Annotations](https://github.com/moby/buildkit/blob/master/docs/annotations.md) |
|
||||||
| `json` | String | JSON output of tags and labels |
|
| `json` | String | JSON output of tags and labels |
|
||||||
|
|||||||
@@ -3936,6 +3936,12 @@ describe('json', () => {
|
|||||||
"user/app:custom",
|
"user/app:custom",
|
||||||
"user/app:tags"
|
"user/app:tags"
|
||||||
],
|
],
|
||||||
|
"tag-names": [
|
||||||
|
"dev",
|
||||||
|
"my",
|
||||||
|
"custom",
|
||||||
|
"tags"
|
||||||
|
],
|
||||||
"labels": {
|
"labels": {
|
||||||
"foo": "",
|
"foo": "",
|
||||||
"org.opencontainers.image.created": "2020-01-10T00:30:00.000Z",
|
"org.opencontainers.image.created": "2020-01-10T00:30:00.000Z",
|
||||||
@@ -3974,6 +3980,10 @@ describe('json', () => {
|
|||||||
"user/app:dev",
|
"user/app:dev",
|
||||||
"user/app:my",
|
"user/app:my",
|
||||||
],
|
],
|
||||||
|
"tag-names": [
|
||||||
|
"dev",
|
||||||
|
"my",
|
||||||
|
],
|
||||||
"labels": {
|
"labels": {
|
||||||
"org.opencontainers.image.created": "2020-01-10T00:30:00.000Z",
|
"org.opencontainers.image.created": "2020-01-10T00:30:00.000Z",
|
||||||
"org.opencontainers.image.description": "This your first repo!",
|
"org.opencontainers.image.description": "This your first repo!",
|
||||||
@@ -4017,6 +4027,13 @@ describe('json', () => {
|
|||||||
"user/app:tags",
|
"user/app:tags",
|
||||||
"user/app:latest"
|
"user/app:latest"
|
||||||
],
|
],
|
||||||
|
"tag-names": [
|
||||||
|
"release1",
|
||||||
|
"my",
|
||||||
|
"custom",
|
||||||
|
"tags",
|
||||||
|
"latest"
|
||||||
|
],
|
||||||
"labels": {
|
"labels": {
|
||||||
"org.opencontainers.image.created": "2020-01-10T00:30:00.000Z",
|
"org.opencontainers.image.created": "2020-01-10T00:30:00.000Z",
|
||||||
"org.opencontainers.image.description": "This your first repo!",
|
"org.opencontainers.image.description": "This your first repo!",
|
||||||
@@ -4061,6 +4078,12 @@ describe('json', () => {
|
|||||||
"user/app:custom",
|
"user/app:custom",
|
||||||
"user/app:tags"
|
"user/app:tags"
|
||||||
],
|
],
|
||||||
|
"tag-names": [
|
||||||
|
"20200110",
|
||||||
|
"my",
|
||||||
|
"custom",
|
||||||
|
"tags"
|
||||||
|
],
|
||||||
"labels": {
|
"labels": {
|
||||||
"org.opencontainers.image.created": "2020-01-10T00:30:00.000Z",
|
"org.opencontainers.image.created": "2020-01-10T00:30:00.000Z",
|
||||||
"org.opencontainers.image.description": "This your first repo!",
|
"org.opencontainers.image.description": "This your first repo!",
|
||||||
@@ -4114,6 +4137,15 @@ describe('json', () => {
|
|||||||
"ghcr.io/user/app:tags",
|
"ghcr.io/user/app:tags",
|
||||||
"ghcr.io/user/app:latest"
|
"ghcr.io/user/app:latest"
|
||||||
],
|
],
|
||||||
|
"tag-names": [
|
||||||
|
"1.1.1",
|
||||||
|
"1.1",
|
||||||
|
"1",
|
||||||
|
"my",
|
||||||
|
"custom",
|
||||||
|
"tags",
|
||||||
|
"latest",
|
||||||
|
],
|
||||||
"labels": {
|
"labels": {
|
||||||
"org.opencontainers.image.created": "2020-01-10T00:30:00.000Z",
|
"org.opencontainers.image.created": "2020-01-10T00:30:00.000Z",
|
||||||
"org.opencontainers.image.description": "This your first repo!",
|
"org.opencontainers.image.description": "This your first repo!",
|
||||||
@@ -4156,6 +4188,11 @@ describe('json', () => {
|
|||||||
"ghcr.io/user/app:custom",
|
"ghcr.io/user/app:custom",
|
||||||
"ghcr.io/user/app:tags"
|
"ghcr.io/user/app:tags"
|
||||||
],
|
],
|
||||||
|
"tag-names": [
|
||||||
|
"my",
|
||||||
|
"custom",
|
||||||
|
"tags",
|
||||||
|
],
|
||||||
"labels": {
|
"labels": {
|
||||||
"org.opencontainers.image.created": "2020-01-10T00:30:00.000Z",
|
"org.opencontainers.image.created": "2020-01-10T00:30:00.000Z",
|
||||||
"org.opencontainers.image.description": "This your first repo!",
|
"org.opencontainers.image.description": "This your first repo!",
|
||||||
@@ -4196,6 +4233,10 @@ describe('json', () => {
|
|||||||
"org/app:v1.1.1",
|
"org/app:v1.1.1",
|
||||||
"org/app:latest"
|
"org/app:latest"
|
||||||
],
|
],
|
||||||
|
"tag-names": [
|
||||||
|
"v1.1.1",
|
||||||
|
"latest"
|
||||||
|
],
|
||||||
"labels": {
|
"labels": {
|
||||||
"maintainer": "CrazyMax",
|
"maintainer": "CrazyMax",
|
||||||
"org.opencontainers.image.created": "2020-01-10T00:30:00.000Z",
|
"org.opencontainers.image.created": "2020-01-10T00:30:00.000Z",
|
||||||
|
|||||||
@@ -48,6 +48,8 @@ outputs:
|
|||||||
description: 'Generated Docker image version'
|
description: 'Generated Docker image version'
|
||||||
tags:
|
tags:
|
||||||
description: 'Generated Docker tags'
|
description: 'Generated Docker tags'
|
||||||
|
tag-names:
|
||||||
|
description: 'Generated Docker tag names without image base name'
|
||||||
labels:
|
labels:
|
||||||
description: 'Generated Docker labels'
|
description: 'Generated Docker labels'
|
||||||
annotations:
|
annotations:
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ actionsToolkit.run(
|
|||||||
setOutput('version', version.main || '');
|
setOutput('version', version.main || '');
|
||||||
|
|
||||||
// Docker tags
|
// Docker tags
|
||||||
const tags: Array<string> = meta.getTags();
|
const tags = meta.getTags();
|
||||||
if (tags.length == 0) {
|
if (tags.length == 0) {
|
||||||
core.warning('No Docker tag has been generated. Check tags input.');
|
core.warning('No Docker tag has been generated. Check tags input.');
|
||||||
} else {
|
} else {
|
||||||
@@ -58,6 +58,7 @@ actionsToolkit.run(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
setOutput('tags', tags.join(inputs.sepTags));
|
setOutput('tags', tags.join(inputs.sepTags));
|
||||||
|
setOutput('tag-names', meta.getTags(true).join(inputs.sepTags));
|
||||||
|
|
||||||
// Docker labels
|
// Docker labels
|
||||||
const labels: Array<string> = meta.getLabels();
|
const labels: Array<string> = meta.getLabels();
|
||||||
|
|||||||
39
src/meta.ts
39
src/meta.ts
@@ -494,33 +494,37 @@ export class Meta {
|
|||||||
return images;
|
return images;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getTags(): Array<string> {
|
public getTags(namesOnly?: boolean): Array<string> {
|
||||||
if (!this.version.main) {
|
if (!this.version.main) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
if (namesOnly) {
|
||||||
const generateTags = (imageName: string, version: string): Array<string> => {
|
return this.generateTags(this.version.main);
|
||||||
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;
|
|
||||||
};
|
|
||||||
|
|
||||||
const tags: Array<string> = [];
|
const tags: Array<string> = [];
|
||||||
const images = this.getImageNames();
|
const images = this.getImageNames();
|
||||||
if (images.length > 0) {
|
if (images.length > 0) {
|
||||||
for (const imageName of images) {
|
for (const imageName of images) {
|
||||||
tags.push(...generateTags(imageName, this.version.main));
|
tags.push(...this.generateTags(this.version.main, imageName));
|
||||||
}
|
}
|
||||||
} else {
|
} 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;
|
return tags;
|
||||||
}
|
}
|
||||||
@@ -568,6 +572,7 @@ export class Meta {
|
|||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
tags: this.getTags(),
|
tags: this.getTags(),
|
||||||
|
'tag-names': this.getTags(true),
|
||||||
labels: this.getLabels().reduce((res, label) => {
|
labels: this.getLabels().reduce((res, label) => {
|
||||||
const matches = label.match(/([^=]*)=(.*)/);
|
const matches = label.match(/([^=]*)=(.*)/);
|
||||||
if (!matches) {
|
if (!matches) {
|
||||||
|
|||||||
Reference in New Issue
Block a user