Allow to override flavor (#63)

Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2021-04-07 20:54:35 +02:00 committed by GitHub
parent 84b9e75d44
commit 1a678de43d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 53 additions and 76 deletions

View file

@ -1169,6 +1169,47 @@ describe('tag', () => {
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071", "org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT" "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); ])('given %p with %p event', tagsLabelsTest);
}); });
@ -1625,20 +1666,20 @@ describe('pr', () => {
] ]
} as Inputs, } as Inputs,
{ {
main: 'glo-2-bal', main: '2-bal',
partial: [], partial: [],
latest: false latest: false
} as Version, } as Version,
[ [
'org/app:glo-2-bal', 'org/app:2-bal',
'ghcr.io/user/app:glo-2-bal' 'ghcr.io/user/app:2-bal'
], ],
[ [
"org.opencontainers.image.title=Hello-World", "org.opencontainers.image.title=Hello-World",
"org.opencontainers.image.description=This your first repo!", "org.opencontainers.image.description=This your first repo!",
"org.opencontainers.image.url=https://github.com/octocat/Hello-World", "org.opencontainers.image.url=https://github.com/octocat/Hello-World",
"org.opencontainers.image.source=https://github.com/octocat/Hello-World", "org.opencontainers.image.source=https://github.com/octocat/Hello-World",
"org.opencontainers.image.version=glo-2-bal", "org.opencontainers.image.version=2-bal",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z", "org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=1e9249f05bfc090e0688b8fb9c1b347586add504", "org.opencontainers.image.revision=1e9249f05bfc090e0688b8fb9c1b347586add504",
"org.opencontainers.image.licenses=MIT" "org.opencontainers.image.licenses=MIT"

View file

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

10
dist/index.js generated vendored
View file

@ -634,13 +634,13 @@ class Meta {
return version; return version;
} }
setFlavor(val, tag) { setFlavor(val, tag) {
if (tag.attrs['prefix'].length > 0) { if (tag.attrs.hasOwnProperty('prefix')) {
val = `${tag.attrs['prefix']}${val}`; val = `${tag.attrs['prefix']}${val}`;
} }
else if (this.flavor.prefix.length > 0) { else if (this.flavor.prefix.length > 0) {
val = `${this.flavor.prefix}${val}`; val = `${this.flavor.prefix}${val}`;
} }
if (tag.attrs['suffix'].length > 0) { if (tag.attrs.hasOwnProperty('suffix')) {
val = `${val}${tag.attrs['suffix']}`; val = `${val}${tag.attrs['suffix']}`;
} }
else if (this.flavor.suffix.length > 0) { else if (this.flavor.suffix.length > 0) {
@ -912,12 +912,6 @@ function Parse(s) {
if (!tag.attrs.hasOwnProperty('priority')) { if (!tag.attrs.hasOwnProperty('priority')) {
tag.attrs['priority'] = exports.DefaultPriorities[tag.type]; 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'])) { if (!['true', 'false'].includes(tag.attrs['enable'])) {
throw new Error(`Invalid value for enable attribute: ${tag.attrs['enable']}`); throw new Error(`Invalid value for enable attribute: ${tag.attrs['enable']}`);
} }

View file

@ -315,12 +315,12 @@ export class Meta {
} }
private setFlavor(val: string, tag: tcl.Tag): string { private setFlavor(val: string, tag: tcl.Tag): string {
if (tag.attrs['prefix'].length > 0) { if (tag.attrs.hasOwnProperty('prefix')) {
val = `${tag.attrs['prefix']}${val}`; val = `${tag.attrs['prefix']}${val}`;
} else if (this.flavor.prefix.length > 0) { } else if (this.flavor.prefix.length > 0) {
val = `${this.flavor.prefix}${val}`; val = `${this.flavor.prefix}${val}`;
} }
if (tag.attrs['suffix'].length > 0) { if (tag.attrs.hasOwnProperty('suffix')) {
val = `${val}${tag.attrs['suffix']}`; val = `${val}${tag.attrs['suffix']}`;
} else if (this.flavor.suffix.length > 0) { } else if (this.flavor.suffix.length > 0) {
val = `${val}${this.flavor.suffix}`; val = `${val}${this.flavor.suffix}`;

View file

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