mirror of
https://gitea.com/docker/metadata-action.git
synced 2024-11-22 12:09:32 +01:00
Set latest tag only if matches with a pattern
This commit is contained in:
parent
4d7603f754
commit
0dac4059e9
6 changed files with 207 additions and 3 deletions
|
@ -25,7 +25,7 @@ ___
|
||||||
* [Notes](#notes)
|
* [Notes](#notes)
|
||||||
* [Latest tag](#latest-tag)
|
* [Latest tag](#latest-tag)
|
||||||
* [Coerces Git tag](#coerces-git-tag)
|
* [Coerces Git tag](#coerces-git-tag)
|
||||||
* [Templates available for schedule tag](#templates-available-for-schedule-tag)
|
* [Schedule tag](#schedule-tag)
|
||||||
* [Keep up-to-date with GitHub Dependabot](#keep-up-to-date-with-github-dependabot)
|
* [Keep up-to-date with GitHub Dependabot](#keep-up-to-date-with-github-dependabot)
|
||||||
* [How can I help?](#how-can-i-help)
|
* [How can I help?](#how-can-i-help)
|
||||||
* [License](#license)
|
* [License](#license)
|
||||||
|
@ -117,6 +117,7 @@ Following inputs can be used as `step.with` keys
|
||||||
| `tag-edge` | Bool | Enable edge branch tagging (default `false`) |
|
| `tag-edge` | Bool | Enable edge branch tagging (default `false`) |
|
||||||
| `tag-edge-branch` | String | Branch that will be tagged as edge (default `repo.default_branch`) |
|
| `tag-edge-branch` | String | Branch that will be tagged as edge (default `repo.default_branch`) |
|
||||||
| `tag-coerce-tag` | String | Coerces Git tag to semver if possible using [Handlebars template](https://handlebarsjs.com/guide/) |
|
| `tag-coerce-tag` | String | Coerces Git tag to semver if possible using [Handlebars template](https://handlebarsjs.com/guide/) |
|
||||||
|
| `tag-latest-match` | String | Set `latest` tag only if [matches with a pattern](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp) |
|
||||||
| `tag-schedule` | String | [Handlebars template](https://handlebarsjs.com/guide/) to apply to schedule tag (default `nightly`) |
|
| `tag-schedule` | String | [Handlebars template](https://handlebarsjs.com/guide/) to apply to schedule tag (default `nightly`) |
|
||||||
| `sep-tags` | String | Separator to use for tags output (default `\n`) |
|
| `sep-tags` | String | Separator to use for tags output (default `\n`) |
|
||||||
| `sep-labels` | String | Separator to use for labels output (default `\n`) |
|
| `sep-labels` | String | Separator to use for labels output (default `\n`) |
|
||||||
|
@ -137,11 +138,13 @@ Following outputs are available
|
||||||
|
|
||||||
### Latest tag
|
### Latest tag
|
||||||
|
|
||||||
`latest` tag is created only on `push tag` event and resolves one of the following conditions:
|
`latest` tag is created with the following conditions:
|
||||||
|
|
||||||
* Git tag is a valid [semver](https://semver.org/)
|
* Git tag is a valid [semver](https://semver.org/)
|
||||||
* Provided `tag-coerce-tag` is valid
|
* Provided `tag-coerce-tag` is valid
|
||||||
|
|
||||||
|
If `tag-latest-match` is filled, then it has priority over the creation of the tag.
|
||||||
|
|
||||||
### Coerces Git tag
|
### Coerces Git tag
|
||||||
|
|
||||||
Provides a very forgiving translation of a non-semver tag to semver. For more information see
|
Provides a very forgiving translation of a non-semver tag to semver. For more information see
|
||||||
|
@ -156,7 +159,7 @@ Provides a very forgiving translation of a non-semver tag to semver. For more in
|
||||||
| `{{minor}}` | `v1.2.3` | `2` |
|
| `{{minor}}` | `v1.2.3` | `2` |
|
||||||
| `{{patch}}` | `v1.2.3` | `3` |
|
| `{{patch}}` | `v1.2.3` | `3` |
|
||||||
|
|
||||||
### Templates available for schedule tag
|
### Schedule tag
|
||||||
|
|
||||||
`tag-schedule` is specially crafted input to support [Handlebars template](https://handlebarsjs.com/guide/) with
|
`tag-schedule` is specially crafted input to support [Handlebars template](https://handlebarsjs.com/guide/) with
|
||||||
the following expressions:
|
the following expressions:
|
||||||
|
|
|
@ -601,6 +601,191 @@ describe('push tag', () => {
|
||||||
])('given %p event ', tagsLabelsTest);
|
])('given %p event ', tagsLabelsTest);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('latest', () => {
|
||||||
|
// prettier-ignore
|
||||||
|
test.each([
|
||||||
|
[
|
||||||
|
'event_tag_release1.env',
|
||||||
|
{
|
||||||
|
images: ['user/app'],
|
||||||
|
tagLatestMatch: `^release`,
|
||||||
|
} as Inputs,
|
||||||
|
{
|
||||||
|
version: 'release1',
|
||||||
|
latest: true,
|
||||||
|
} as Version,
|
||||||
|
[
|
||||||
|
'user/app:release1',
|
||||||
|
'user/app:latest'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"org.opencontainers.image.title=Hello-World",
|
||||||
|
"org.opencontainers.image.description=This your first repo!",
|
||||||
|
"org.opencontainers.image.url=https://github.com/octocat/Hello-World",
|
||||||
|
"org.opencontainers.image.source=https://github.com/octocat/Hello-World.git",
|
||||||
|
"org.opencontainers.image.version=release1",
|
||||||
|
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
|
||||||
|
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
|
||||||
|
"org.opencontainers.image.licenses=MIT"
|
||||||
|
]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'event_tag_20200110-RC2.env',
|
||||||
|
{
|
||||||
|
images: ['user/app'],
|
||||||
|
tagLatestMatch: `^\\d`,
|
||||||
|
} as Inputs,
|
||||||
|
{
|
||||||
|
version: '20200110-RC2',
|
||||||
|
latest: true
|
||||||
|
} as Version,
|
||||||
|
[
|
||||||
|
'user/app:20200110-RC2',
|
||||||
|
'user/app:latest'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"org.opencontainers.image.title=Hello-World",
|
||||||
|
"org.opencontainers.image.description=This your first repo!",
|
||||||
|
"org.opencontainers.image.url=https://github.com/octocat/Hello-World",
|
||||||
|
"org.opencontainers.image.source=https://github.com/octocat/Hello-World.git",
|
||||||
|
"org.opencontainers.image.version=20200110-RC2",
|
||||||
|
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
|
||||||
|
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
|
||||||
|
"org.opencontainers.image.licenses=MIT"
|
||||||
|
]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'event_tag_20200110-RC2.env',
|
||||||
|
{
|
||||||
|
images: ['user/app'],
|
||||||
|
tagCoerceTag: '{{major}}',
|
||||||
|
tagLatestMatch: `\\d`,
|
||||||
|
} as Inputs,
|
||||||
|
{
|
||||||
|
version: '20200110',
|
||||||
|
latest: true
|
||||||
|
} as Version,
|
||||||
|
[
|
||||||
|
'user/app:20200110',
|
||||||
|
'user/app:latest'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"org.opencontainers.image.title=Hello-World",
|
||||||
|
"org.opencontainers.image.description=This your first repo!",
|
||||||
|
"org.opencontainers.image.url=https://github.com/octocat/Hello-World",
|
||||||
|
"org.opencontainers.image.source=https://github.com/octocat/Hello-World.git",
|
||||||
|
"org.opencontainers.image.version=20200110",
|
||||||
|
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
|
||||||
|
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
|
||||||
|
"org.opencontainers.image.licenses=MIT"
|
||||||
|
]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'event_tag_v1.1.1.env',
|
||||||
|
{
|
||||||
|
images: ['user/app'],
|
||||||
|
tagLatestMatch: `\\d{1,3}.\\d{1,3}.\\d{1,3}`,
|
||||||
|
} as Inputs,
|
||||||
|
{
|
||||||
|
version: '1.1.1',
|
||||||
|
latest: true
|
||||||
|
} as Version,
|
||||||
|
[
|
||||||
|
'user/app:1.1.1',
|
||||||
|
'user/app:latest'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"org.opencontainers.image.title=Hello-World",
|
||||||
|
"org.opencontainers.image.description=This your first repo!",
|
||||||
|
"org.opencontainers.image.url=https://github.com/octocat/Hello-World",
|
||||||
|
"org.opencontainers.image.source=https://github.com/octocat/Hello-World.git",
|
||||||
|
"org.opencontainers.image.version=1.1.1",
|
||||||
|
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
|
||||||
|
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
|
||||||
|
"org.opencontainers.image.licenses=MIT"
|
||||||
|
]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'event_tag_v1.1.1.env',
|
||||||
|
{
|
||||||
|
images: ['org/app', 'ghcr.io/user/app'],
|
||||||
|
} as Inputs,
|
||||||
|
{
|
||||||
|
version: '1.1.1',
|
||||||
|
latest: true
|
||||||
|
} as Version,
|
||||||
|
[
|
||||||
|
'org/app:1.1.1',
|
||||||
|
'org/app:latest',
|
||||||
|
'ghcr.io/user/app:1.1.1',
|
||||||
|
'ghcr.io/user/app:latest'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"org.opencontainers.image.title=Hello-World",
|
||||||
|
"org.opencontainers.image.description=This your first repo!",
|
||||||
|
"org.opencontainers.image.url=https://github.com/octocat/Hello-World",
|
||||||
|
"org.opencontainers.image.source=https://github.com/octocat/Hello-World.git",
|
||||||
|
"org.opencontainers.image.version=1.1.1",
|
||||||
|
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
|
||||||
|
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
|
||||||
|
"org.opencontainers.image.licenses=MIT"
|
||||||
|
]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'event_tag_v1.1.1.env',
|
||||||
|
{
|
||||||
|
images: ['org/app', 'ghcr.io/user/app'],
|
||||||
|
tagLatestMatch: `2.\\d{1,3}.\\d{1,3}`,
|
||||||
|
} as Inputs,
|
||||||
|
{
|
||||||
|
version: '1.1.1',
|
||||||
|
latest: false
|
||||||
|
} as Version,
|
||||||
|
[
|
||||||
|
'org/app:1.1.1',
|
||||||
|
'ghcr.io/user/app:1.1.1',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"org.opencontainers.image.title=Hello-World",
|
||||||
|
"org.opencontainers.image.description=This your first repo!",
|
||||||
|
"org.opencontainers.image.url=https://github.com/octocat/Hello-World",
|
||||||
|
"org.opencontainers.image.source=https://github.com/octocat/Hello-World.git",
|
||||||
|
"org.opencontainers.image.version=1.1.1",
|
||||||
|
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
|
||||||
|
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
|
||||||
|
"org.opencontainers.image.licenses=MIT"
|
||||||
|
]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'event_tag_v2.0.8-beta.67.env',
|
||||||
|
{
|
||||||
|
images: ['org/app', 'ghcr.io/user/app'],
|
||||||
|
tagLatestMatch: `^\\d{1,3}.\\d{1,3}.\\d{1,3}`,
|
||||||
|
} as Inputs,
|
||||||
|
{
|
||||||
|
version: '2.0.8-beta.67',
|
||||||
|
latest: true
|
||||||
|
} as Version,
|
||||||
|
[
|
||||||
|
'org/app:2.0.8-beta.67',
|
||||||
|
'org/app:latest',
|
||||||
|
'ghcr.io/user/app:2.0.8-beta.67',
|
||||||
|
'ghcr.io/user/app:latest'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"org.opencontainers.image.title=Hello-World",
|
||||||
|
"org.opencontainers.image.description=This your first repo!",
|
||||||
|
"org.opencontainers.image.url=https://github.com/octocat/Hello-World",
|
||||||
|
"org.opencontainers.image.source=https://github.com/octocat/Hello-World.git",
|
||||||
|
"org.opencontainers.image.version=2.0.8-beta.67",
|
||||||
|
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
|
||||||
|
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
|
||||||
|
"org.opencontainers.image.licenses=MIT"
|
||||||
|
]
|
||||||
|
],
|
||||||
|
])('given %p event ', tagsLabelsTest);
|
||||||
|
});
|
||||||
|
|
||||||
describe('pull_request', () => {
|
describe('pull_request', () => {
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
test.each([
|
test.each([
|
||||||
|
|
|
@ -24,6 +24,9 @@ inputs:
|
||||||
tag-coerce-tag:
|
tag-coerce-tag:
|
||||||
description: 'Coerces Git tag to semver if possible using Handlebars template'
|
description: 'Coerces Git tag to semver if possible using Handlebars template'
|
||||||
required: false
|
required: false
|
||||||
|
tag-latest-match:
|
||||||
|
description: 'Set latest tag only if matches with a pattern'
|
||||||
|
required: false
|
||||||
tag-schedule:
|
tag-schedule:
|
||||||
description: 'Handlebars template to apply to schedule tag'
|
description: 'Handlebars template to apply to schedule tag'
|
||||||
default: 'nightly'
|
default: 'nightly'
|
||||||
|
|
6
dist/index.js
generated
vendored
6
dist/index.js
generated
vendored
|
@ -26,6 +26,7 @@ function getInputs() {
|
||||||
tagEdge: /true/i.test(core.getInput('tag-edge') || 'false'),
|
tagEdge: /true/i.test(core.getInput('tag-edge') || 'false'),
|
||||||
tagEdgeBranch: core.getInput('tag-edge-branch'),
|
tagEdgeBranch: core.getInput('tag-edge-branch'),
|
||||||
tagCoerceTag: core.getInput('tag-coerce-tag'),
|
tagCoerceTag: core.getInput('tag-coerce-tag'),
|
||||||
|
tagLatestMatch: core.getInput('tag-latest-match'),
|
||||||
tagSchedule: core.getInput('tag-schedule') || 'nightly',
|
tagSchedule: core.getInput('tag-schedule') || 'nightly',
|
||||||
sepTags: core.getInput('sep-tags') || `\n`,
|
sepTags: core.getInput('sep-tags') || `\n`,
|
||||||
sepLabels: core.getInput('sep-labels') || `\n`,
|
sepLabels: core.getInput('sep-labels') || `\n`,
|
||||||
|
@ -179,6 +180,7 @@ class Meta {
|
||||||
this.date = new Date();
|
this.date = new Date();
|
||||||
}
|
}
|
||||||
version() {
|
version() {
|
||||||
|
var _a;
|
||||||
const currentDate = this.date;
|
const currentDate = this.date;
|
||||||
const version = {
|
const version = {
|
||||||
version: undefined,
|
version: undefined,
|
||||||
|
@ -225,6 +227,10 @@ class Meta {
|
||||||
else if (/^refs\/pull\//.test(this.context.ref)) {
|
else if (/^refs\/pull\//.test(this.context.ref)) {
|
||||||
version.version = `pr-${this.context.ref.replace(/^refs\/pull\//g, '').replace(/\/merge$/g, '')}`;
|
version.version = `pr-${this.context.ref.replace(/^refs\/pull\//g, '').replace(/\/merge$/g, '')}`;
|
||||||
}
|
}
|
||||||
|
if (this.inputs.tagLatestMatch) {
|
||||||
|
const match = (_a = version.version) === null || _a === void 0 ? void 0 : _a.match(new RegExp(this.inputs.tagLatestMatch));
|
||||||
|
version.latest = match !== null;
|
||||||
|
}
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
tags() {
|
tags() {
|
||||||
|
|
|
@ -6,6 +6,7 @@ export interface Inputs {
|
||||||
tagEdge: boolean;
|
tagEdge: boolean;
|
||||||
tagEdgeBranch: string;
|
tagEdgeBranch: string;
|
||||||
tagCoerceTag: string;
|
tagCoerceTag: string;
|
||||||
|
tagLatestMatch: string;
|
||||||
tagSchedule: string;
|
tagSchedule: string;
|
||||||
sepTags: string;
|
sepTags: string;
|
||||||
sepLabels: string;
|
sepLabels: string;
|
||||||
|
@ -19,6 +20,7 @@ export function getInputs(): Inputs {
|
||||||
tagEdge: /true/i.test(core.getInput('tag-edge') || 'false'),
|
tagEdge: /true/i.test(core.getInput('tag-edge') || 'false'),
|
||||||
tagEdgeBranch: core.getInput('tag-edge-branch'),
|
tagEdgeBranch: core.getInput('tag-edge-branch'),
|
||||||
tagCoerceTag: core.getInput('tag-coerce-tag'),
|
tagCoerceTag: core.getInput('tag-coerce-tag'),
|
||||||
|
tagLatestMatch: core.getInput('tag-latest-match'),
|
||||||
tagSchedule: core.getInput('tag-schedule') || 'nightly',
|
tagSchedule: core.getInput('tag-schedule') || 'nightly',
|
||||||
sepTags: core.getInput('sep-tags') || `\n`,
|
sepTags: core.getInput('sep-tags') || `\n`,
|
||||||
sepLabels: core.getInput('sep-labels') || `\n`,
|
sepLabels: core.getInput('sep-labels') || `\n`,
|
||||||
|
|
|
@ -68,6 +68,11 @@ export class Meta {
|
||||||
version.version = `pr-${this.context.ref.replace(/^refs\/pull\//g, '').replace(/\/merge$/g, '')}`;
|
version.version = `pr-${this.context.ref.replace(/^refs\/pull\//g, '').replace(/\/merge$/g, '')}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.inputs.tagLatestMatch) {
|
||||||
|
const match = version.version?.match(new RegExp(this.inputs.tagLatestMatch));
|
||||||
|
version.latest = match !== null;
|
||||||
|
}
|
||||||
|
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue