Allow to add custom tags (#24)

Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2020-12-04 18:12:39 +01:00 committed by GitHub
parent 9de4428611
commit 585ab8356c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 231 additions and 3 deletions

View file

@ -246,6 +246,8 @@ Following inputs can be used as `step.with` keys
| `tag-match-group` | Number | Group to get if `tag-match` matches (default `0`) |
| `tag-latest` | Bool | Set `latest` Docker tag if `tag-semver`, `tag-match` or Git tag event occurs (default `true`) |
| `tag-schedule` | String | [Template](#schedule-tag) to apply to schedule tag (default `nightly`) |
| `tag-custom` | List/CSV | List of custom tags |
| `tag-custom-only` | Bool | Only use `tag-custom` as Docker tags |
| `sep-tags` | String | Separator to use for tags output (default `\n`) |
| `sep-labels` | String | Separator to use for labels output (default `\n`) |
@ -270,7 +272,7 @@ Following outputs are available
Latest Docker tag will be generated by default on `push tag` event. If for example you push the `v1.2.3` Git tag,
you will have at the output of this action the Docker tags `v1.2.3` and `latest`. But you can allow the latest tag to be
generated only if `tag-semver` is a valid [semver](https://semver.org/) or if Git tag matches a regular expression
with the [`tag-match` input](#tag-match-examples).
with the [`tag-match` input](#tag-match-examples). Can be disabled if `tag-latest` is `false`.
### Handle semver tag

View file

@ -1229,3 +1229,193 @@ describe('release', () => {
],
])('given %p event ', tagsLabelsTest);
});
describe('custom', () => {
// prettier-ignore
test.each([
[
'event_push.env',
{
images: ['user/app'],
tagCustom: ['my', 'custom', 'tags']
} as Inputs,
{
main: 'dev',
partial: ['my', 'custom', 'tags'],
latest: false
} as Version,
[
'user/app:dev',
'user/app:my',
'user/app:custom',
'user/app:tags'
],
[
"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",
"org.opencontainers.image.version=dev",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT"
]
],
[
'event_push.env',
{
images: ['user/app'],
tagCustom: ['my']
} as Inputs,
{
main: 'dev',
partial: ['my'],
latest: false
} as Version,
[
'user/app:dev',
'user/app:my'
],
[
"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",
"org.opencontainers.image.version=dev",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT"
]
],
[
'event_tag_release1.env',
{
images: ['user/app'],
tagCustom: ['my', 'custom', 'tags']
} as Inputs,
{
main: 'release1',
partial: ['my', 'custom', 'tags'],
latest: true
} as Version,
[
'user/app:release1',
'user/app:my',
'user/app:custom',
'user/app:tags',
'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",
"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'],
tagMatch: `\\d{8}`,
tagLatest: false,
tagCustom: ['my', 'custom', 'tags']
} as Inputs,
{
main: '20200110',
partial: ['my', 'custom', 'tags'],
latest: false
} as Version,
[
'user/app:20200110',
'user/app:my',
'user/app:custom',
'user/app:tags'
],
[
"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",
"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: ['org/app', 'ghcr.io/user/app'],
tagSemver: ['{{version}}', '{{major}}.{{minor}}', '{{major}}'],
tagCustom: ['my', 'custom', 'tags']
} as Inputs,
{
main: '1.1.1',
partial: ['1.1', '1', 'my', 'custom', 'tags'],
latest: true
} as Version,
[
'org/app:1.1.1',
'org/app:1.1',
'org/app:1',
'org/app:my',
'org/app:custom',
'org/app:tags',
'org/app:latest',
'ghcr.io/user/app:1.1.1',
'ghcr.io/user/app:1.1',
'ghcr.io/user/app:1',
'ghcr.io/user/app:my',
'ghcr.io/user/app:custom',
'ghcr.io/user/app:tags',
'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",
"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'],
tagSemver: ['{{version}}', '{{major}}.{{minor}}.{{patch}}'],
tagCustom: ['my', 'custom', 'tags'],
tagCustomOnly: true,
} as Inputs,
{
main: 'my',
partial: ['custom', 'tags'],
latest: false
} as Version,
[
'org/app:my',
'org/app:custom',
'org/app:tags',
'ghcr.io/user/app:my',
'ghcr.io/user/app:custom',
'ghcr.io/user/app:tags'
],
[
"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",
"org.opencontainers.image.version=my",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT"
]
],
])('given %p event ', tagsLabelsTest);
});

View file

@ -44,6 +44,12 @@ inputs:
description: 'Template to apply to schedule tag'
default: 'nightly'
required: false
tag-custom:
description: 'List of custom tags'
required: false
tag-custom-only:
description: 'Only use tag-custom as Docker tags'
required: false
sep-tags:
description: 'Separator to use for tags output (default \n)'
required: false

16
dist/index.js generated vendored
View file

@ -30,6 +30,8 @@ function getInputs() {
tagMatchGroup: Number(core.getInput('tag-match-group')) || 0,
tagLatest: /true/i.test(core.getInput('tag-latest') || core.getInput('tag-match-latest') || 'true'),
tagSchedule: core.getInput('tag-schedule') || 'nightly',
tagCustom: getInputList('tag-custom'),
tagCustomOnly: /true/i.test(core.getInput('tag-custom-only') || 'false'),
sepTags: core.getInput('sep-tags') || `\n`,
sepLabels: core.getInput('sep-labels') || `\n`,
githubToken: core.getInput('github-token')
@ -185,7 +187,7 @@ class Meta {
}
getVersion() {
const currentDate = this.date;
const version = {
let version = {
main: undefined,
partial: [],
latest: false
@ -248,6 +250,18 @@ class Meta {
else if (/^refs\/pull\//.test(this.context.ref)) {
version.main = `pr-${this.context.ref.replace(/^refs\/pull\//g, '').replace(/\/merge$/g, '')}`;
}
if (this.inputs.tagCustom.length > 0) {
if (this.inputs.tagCustomOnly) {
version = {
main: this.inputs.tagCustom.shift(),
partial: this.inputs.tagCustom,
latest: false
};
}
else {
version.partial.push(...this.inputs.tagCustom);
}
}
version.partial = version.partial.filter((item, index) => version.partial.indexOf(item) === index);
return version;
}

View file

@ -10,6 +10,8 @@ export interface Inputs {
tagMatchGroup: number;
tagLatest: boolean;
tagSchedule: string;
tagCustom: string[];
tagCustomOnly: boolean;
sepTags: string;
sepLabels: string;
githubToken: string;
@ -26,6 +28,8 @@ export function getInputs(): Inputs {
tagMatchGroup: Number(core.getInput('tag-match-group')) || 0,
tagLatest: /true/i.test(core.getInput('tag-latest') || core.getInput('tag-match-latest') || 'true'),
tagSchedule: core.getInput('tag-schedule') || 'nightly',
tagCustom: getInputList('tag-custom'),
tagCustomOnly: /true/i.test(core.getInput('tag-custom-only') || 'false'),
sepTags: core.getInput('sep-tags') || `\n`,
sepLabels: core.getInput('sep-labels') || `\n`,
githubToken: core.getInput('github-token')

View file

@ -33,7 +33,7 @@ export class Meta {
private getVersion(): Version {
const currentDate = this.date;
const version: Version = {
let version: Version = {
main: undefined,
partial: [],
latest: false
@ -91,6 +91,18 @@ export class Meta {
version.main = `pr-${this.context.ref.replace(/^refs\/pull\//g, '').replace(/\/merge$/g, '')}`;
}
if (this.inputs.tagCustom.length > 0) {
if (this.inputs.tagCustomOnly) {
version = {
main: this.inputs.tagCustom.shift(),
partial: this.inputs.tagCustom,
latest: false
};
} else {
version.partial.push(...this.inputs.tagCustom);
}
}
version.partial = version.partial.filter((item, index) => version.partial.indexOf(item) === index);
return version;
}