Compare commits

..

3 Commits

Author SHA1 Message Date
CrazyMax
2e1a5c7fa4 Update CHANGELOG 2021-04-07 21:00:00 +02:00
CrazyMax
1a678de43d Allow to override flavor (#63)
Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
2021-04-07 20:54:35 +02:00
CrazyMax
84b9e75d44 Prefix/suffix not taken into account (#62)
Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
2021-04-07 20:31:35 +02:00
6 changed files with 180 additions and 107 deletions

View File

@@ -1,5 +1,10 @@
# Changelog
## 2.3.0 (2021/04/07)
* Allow overriding flavor (#63)
* Prefix/suffix not taken into account for `match`, `semver` and `schedule` types (#62)
## 2.2.1 (2021/04/05)
* Skip and display warning if tag does not match (#59)

View File

@@ -1169,6 +1169,47 @@ describe('tag', () => {
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT"
]
],
[
'tag19',
'event_tag_p1-v1.0.0.env',
{
images: ['org/app', 'ghcr.io/user/app'],
tags: [
`type=match,pattern=p1-v(\\d.\\d.\\d),group=1`,
`type=match,pattern=p1-v(\\d.\\d),group=1,suffix=`,
`type=ref,event=pr`,
`type=sha`
],
flavor: [
`suffix=-dev`
]
} as Inputs,
{
main: '1.0.0-dev',
partial: ['1.0', 'sha-90dd603-dev'],
latest: true
} as Version,
[
'org/app:1.0.0-dev',
'org/app:1.0',
'org/app:sha-90dd603-dev',
'org/app:latest',
'ghcr.io/user/app:1.0.0-dev',
'ghcr.io/user/app:1.0',
'ghcr.io/user/app:sha-90dd603-dev',
'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.0.0-dev",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT"
]
]
])('given %p with %p event', tagsLabelsTest);
});
@@ -1578,6 +1619,72 @@ describe('pr', () => {
"org.opencontainers.image.licenses=MIT"
]
],
[
'pr05',
'event_pull_request.env',
{
images: ['org/app', 'ghcr.io/user/app'],
tags: [
`type=ref,event=pr`
],
flavor: [
`prefix=glo-`,
`suffix=-bal`
]
} as Inputs,
{
main: 'pr-2-bal',
partial: [],
latest: false
} as Version,
[
'org/app:pr-2-bal',
'ghcr.io/user/app:pr-2-bal'
],
[
"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=pr-2-bal",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=1e9249f05bfc090e0688b8fb9c1b347586add504",
"org.opencontainers.image.licenses=MIT"
]
],
[
'pr06',
'event_pull_request.env',
{
images: ['org/app', 'ghcr.io/user/app'],
tags: [
`type=ref,event=pr,prefix=`
],
flavor: [
`prefix=glo-`,
`suffix=-bal`
]
} as Inputs,
{
main: '2-bal',
partial: [],
latest: false
} as Version,
[
'org/app:2-bal',
'ghcr.io/user/app:2-bal'
],
[
"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=2-bal",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=1e9249f05bfc090e0688b8fb9c1b347586add504",
"org.opencontainers.image.licenses=MIT"
]
]
])('given %p with %p event', tagsLabelsTest);
});
@@ -1758,6 +1865,39 @@ describe('schedule', () => {
"org.opencontainers.image.licenses=MIT"
]
],
[
'schedule07',
'event_schedule.env',
{
images: ['org/app', 'ghcr.io/user/app'],
tags: [
`type=schedule`,
],
flavor: [
`prefix=glo-`,
`suffix=-bal`
]
} as Inputs,
{
main: 'glo-nightly-bal',
partial: [],
latest: false
} as Version,
[
'org/app:glo-nightly-bal',
'ghcr.io/user/app:glo-nightly-bal'
],
[
"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=glo-nightly-bal",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT"
]
],
])('given %p with %p event', tagsLabelsTest);
});

View File

@@ -21,8 +21,6 @@ describe('transform', () => {
attrs: {
"priority": DefaultPriorities[Type.Schedule],
"enable": "true",
"prefix": "",
"suffix": "",
"pattern": "nightly"
}
},
@@ -31,8 +29,6 @@ describe('transform', () => {
attrs: {
"priority": DefaultPriorities[Type.Semver],
"enable": "true",
"prefix": "",
"suffix": "",
"pattern": "{{version}}",
"value": ""
}
@@ -42,8 +38,6 @@ describe('transform', () => {
attrs: {
"priority": DefaultPriorities[Type.Match],
"enable": "true",
"prefix": "",
"suffix": "",
"pattern": "\\d.\\d.\\d",
"group": "0",
"value": ""
@@ -54,8 +48,6 @@ describe('transform', () => {
attrs: {
"priority": DefaultPriorities[Type.Edge],
"enable": "true",
"prefix": "",
"suffix": "",
"branch": ""
}
},
@@ -64,8 +56,6 @@ describe('transform', () => {
attrs: {
"priority": DefaultPriorities[Type.Ref],
"enable": "true",
"prefix": "",
"suffix": "",
"event": RefEvent.Branch
}
},
@@ -74,8 +64,6 @@ describe('transform', () => {
attrs: {
"priority": DefaultPriorities[Type.Ref],
"enable": "true",
"prefix": "",
"suffix": "",
"event": RefEvent.Tag
}
},
@@ -85,7 +73,6 @@ describe('transform', () => {
"priority": DefaultPriorities[Type.Ref],
"enable": "true",
"prefix": "pr-",
"suffix": "",
"event": RefEvent.PR
}
},
@@ -94,8 +81,6 @@ describe('transform', () => {
attrs: {
"priority": DefaultPriorities[Type.Raw],
"enable": "true",
"prefix": "",
"suffix": "",
"value": "foo"
}
},
@@ -104,8 +89,7 @@ describe('transform', () => {
attrs: {
"priority": DefaultPriorities[Type.Sha],
"enable": "true",
"prefix": "sha-",
"suffix": ""
"prefix": "sha-"
}
}
] as Tag[],
@@ -135,8 +119,6 @@ describe('parse', () => {
attrs: {
"priority": DefaultPriorities[Type.Schedule],
"enable": "true",
"prefix": "",
"suffix": "",
"pattern": "{{date 'YYYYMMDD'}}"
}
} as Tag,
@@ -149,8 +131,6 @@ describe('parse', () => {
attrs: {
"priority": DefaultPriorities[Type.Semver],
"enable": "true",
"prefix": "",
"suffix": "",
"pattern": "{{version}}",
"value": ""
}
@@ -164,8 +144,6 @@ describe('parse', () => {
attrs: {
"priority": "1",
"enable": "true",
"prefix": "",
"suffix": "",
"pattern": "{{version}}",
"value": ""
}
@@ -179,8 +157,6 @@ describe('parse', () => {
attrs: {
"priority": "1",
"enable": "true",
"prefix": "",
"suffix": "",
"pattern": "{{version}}",
"value": "v1.0.0"
}
@@ -194,8 +170,6 @@ describe('parse', () => {
attrs: {
"priority": DefaultPriorities[Type.Match],
"enable": "true",
"prefix": "",
"suffix": "",
"pattern": "v(.*)",
"group": "1",
"value": ""
@@ -210,8 +184,6 @@ describe('parse', () => {
attrs: {
"priority": DefaultPriorities[Type.Match],
"enable": "true",
"prefix": "",
"suffix": "",
"pattern": "^v(\\d.\\d.\\d)$",
"group": "1",
"value": ""
@@ -226,8 +198,6 @@ describe('parse', () => {
attrs: {
"priority": "700",
"enable": "true",
"prefix": "",
"suffix": "",
"pattern": "v(.*)",
"group": "1",
"value": ""
@@ -242,8 +212,6 @@ describe('parse', () => {
attrs: {
"priority": DefaultPriorities[Type.Match],
"enable": "true",
"prefix": "",
"suffix": "",
"pattern": "v(.*)",
"group": "1",
"value": "v1.2.3"
@@ -263,8 +231,6 @@ describe('parse', () => {
attrs: {
"priority": DefaultPriorities[Type.Edge],
"enable": "true",
"prefix": "",
"suffix": "",
"branch": ""
}
} as Tag,
@@ -277,8 +243,6 @@ describe('parse', () => {
attrs: {
"priority": DefaultPriorities[Type.Edge],
"enable": "true",
"prefix": "",
"suffix": "",
"branch": "master"
}
} as Tag,
@@ -291,8 +255,6 @@ describe('parse', () => {
attrs: {
"priority": DefaultPriorities[Type.Ref],
"enable": "true",
"prefix": "",
"suffix": "",
"event": RefEvent.Tag
}
} as Tag,
@@ -305,8 +267,6 @@ describe('parse', () => {
attrs: {
"priority": DefaultPriorities[Type.Ref],
"enable": "true",
"prefix": "",
"suffix": "",
"event": RefEvent.Branch
}
} as Tag,
@@ -320,7 +280,6 @@ describe('parse', () => {
"priority": DefaultPriorities[Type.Ref],
"enable": "true",
"prefix": "pr-",
"suffix": "",
"event": RefEvent.PR
}
} as Tag,
@@ -343,8 +302,6 @@ describe('parse', () => {
attrs: {
"priority": DefaultPriorities[Type.Raw],
"enable": "true",
"prefix": "",
"suffix": "",
"value": "acustomtag"
}
} as Tag,
@@ -362,8 +319,6 @@ describe('parse', () => {
attrs: {
"priority": DefaultPriorities[Type.Raw],
"enable": "true",
"prefix": "",
"suffix": "",
"value": "acustomtag2"
}
} as Tag,
@@ -376,8 +331,6 @@ describe('parse', () => {
attrs: {
"priority": DefaultPriorities[Type.Raw],
"enable": "true",
"prefix": "",
"suffix": "",
"value": "acustomtag4"
}
} as Tag,
@@ -390,8 +343,6 @@ describe('parse', () => {
attrs: {
"priority": DefaultPriorities[Type.Raw],
"enable": "false",
"prefix": "",
"suffix": "",
"value": "acustomtag5"
}
} as Tag,
@@ -404,8 +355,7 @@ describe('parse', () => {
attrs: {
"priority": DefaultPriorities[Type.Sha],
"enable": "true",
"prefix": "sha-",
"suffix": ""
"prefix": "sha-"
}
} as Tag,
false
@@ -417,8 +367,7 @@ describe('parse', () => {
attrs: {
"priority": DefaultPriorities[Type.Sha],
"enable": "true",
"prefix": "",
"suffix": ""
"prefix": ""
}
} as Tag,
false
@@ -430,8 +379,7 @@ describe('parse', () => {
attrs: {
"priority": DefaultPriorities[Type.Sha],
"enable": "false",
"prefix": "sha-",
"suffix": ""
"prefix": "sha-"
}
} as Tag,
false

30
dist/index.js generated vendored
View File

@@ -439,11 +439,11 @@ class Meta {
return version;
}
const currentDate = this.date;
const vraw = handlebars.compile(tag.attrs['pattern'])({
const vraw = this.setFlavor(handlebars.compile(tag.attrs['pattern'])({
date: function (format) {
return moment_1.default(currentDate).utc().format(format);
}
});
}), tag);
if (version.main == undefined) {
version.main = vraw;
}
@@ -475,24 +475,18 @@ class Meta {
includePrerelease: true
});
if (semver.prerelease(vraw)) {
vraw = handlebars.compile('{{version}}')(sver);
if (version.main == undefined) {
version.main = vraw;
}
else if (vraw !== version.main) {
version.partial.push(vraw);
}
vraw = this.setFlavor(handlebars.compile('{{version}}')(sver), tag);
}
else {
vraw = handlebars.compile(tag.attrs['pattern'])(sver);
vraw = this.setFlavor(handlebars.compile(tag.attrs['pattern'])(sver), tag);
latest = true;
}
if (version.main == undefined) {
version.main = vraw;
}
else if (vraw !== version.main) {
version.partial.push(vraw);
}
latest = true;
}
if (version.latest == undefined) {
version.latest = this.flavor.latest == 'auto' ? latest : this.flavor.latest == 'true';
}
@@ -526,7 +520,7 @@ class Meta {
core.warning(`Group ${tag.attrs['group']} does not exist for ${tag.attrs['pattern']} pattern.`);
return version;
}
vraw = tmatch[tag.attrs['group']];
vraw = this.setFlavor(tmatch[tag.attrs['group']], tag);
latest = true;
if (version.main == undefined) {
version.main = vraw;
@@ -640,13 +634,13 @@ class Meta {
return version;
}
setFlavor(val, tag) {
if (tag.attrs['prefix'].length > 0) {
if (tag.attrs.hasOwnProperty('prefix')) {
val = `${tag.attrs['prefix']}${val}`;
}
else if (this.flavor.prefix.length > 0) {
val = `${this.flavor.prefix}${val}`;
}
if (tag.attrs['suffix'].length > 0) {
if (tag.attrs.hasOwnProperty('suffix')) {
val = `${val}${tag.attrs['suffix']}`;
}
else if (this.flavor.suffix.length > 0) {
@@ -918,12 +912,6 @@ function Parse(s) {
if (!tag.attrs.hasOwnProperty('priority')) {
tag.attrs['priority'] = exports.DefaultPriorities[tag.type];
}
if (!tag.attrs.hasOwnProperty('prefix')) {
tag.attrs['prefix'] = '';
}
if (!tag.attrs.hasOwnProperty('suffix')) {
tag.attrs['suffix'] = '';
}
if (!['true', 'false'].includes(tag.attrs['enable'])) {
throw new Error(`Invalid value for enable attribute: ${tag.attrs['enable']}`);
}

View File

@@ -99,11 +99,14 @@ export class Meta {
}
const currentDate = this.date;
const vraw = handlebars.compile(tag.attrs['pattern'])({
const vraw = this.setFlavor(
handlebars.compile(tag.attrs['pattern'])({
date: function (format) {
return moment(currentDate).utc().format(format);
}
});
}),
tag
);
if (version.main == undefined) {
version.main = vraw;
@@ -138,21 +141,16 @@ export class Meta {
includePrerelease: true
});
if (semver.prerelease(vraw)) {
vraw = handlebars.compile('{{version}}')(sver);
if (version.main == undefined) {
version.main = vraw;
} else if (vraw !== version.main) {
version.partial.push(vraw);
}
vraw = this.setFlavor(handlebars.compile('{{version}}')(sver), tag);
} else {
vraw = handlebars.compile(tag.attrs['pattern'])(sver);
vraw = this.setFlavor(handlebars.compile(tag.attrs['pattern'])(sver), tag);
latest = true;
}
if (version.main == undefined) {
version.main = vraw;
} else if (vraw !== version.main) {
version.partial.push(vraw);
}
latest = true;
}
if (version.latest == undefined) {
version.latest = this.flavor.latest == 'auto' ? latest : this.flavor.latest == 'true';
}
@@ -189,7 +187,7 @@ export class Meta {
return version;
}
vraw = tmatch[tag.attrs['group']];
vraw = this.setFlavor(tmatch[tag.attrs['group']], tag);
latest = true;
if (version.main == undefined) {
@@ -317,12 +315,12 @@ export class Meta {
}
private setFlavor(val: string, tag: tcl.Tag): string {
if (tag.attrs['prefix'].length > 0) {
if (tag.attrs.hasOwnProperty('prefix')) {
val = `${tag.attrs['prefix']}${val}`;
} else if (this.flavor.prefix.length > 0) {
val = `${this.flavor.prefix}${val}`;
}
if (tag.attrs['suffix'].length > 0) {
if (tag.attrs.hasOwnProperty('suffix')) {
val = `${val}${tag.attrs['suffix']}`;
} else if (this.flavor.suffix.length > 0) {
val = `${val}${this.flavor.suffix}`;

View File

@@ -185,12 +185,6 @@ export function Parse(s: string): Tag {
if (!tag.attrs.hasOwnProperty('priority')) {
tag.attrs['priority'] = DefaultPriorities[tag.type];
}
if (!tag.attrs.hasOwnProperty('prefix')) {
tag.attrs['prefix'] = '';
}
if (!tag.attrs.hasOwnProperty('suffix')) {
tag.attrs['suffix'] = '';
}
if (!['true', 'false'].includes(tag.attrs['enable'])) {
throw new Error(`Invalid value for enable attribute: ${tag.attrs['enable']}`);
}