Skip to content

Commit

Permalink
Allow to override flavor
Browse files Browse the repository at this point in the history
  • Loading branch information
crazy-max committed Apr 7, 2021
1 parent 84b9e75 commit 140b597
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 68 deletions.
49 changes: 45 additions & 4 deletions __tests__/meta.test.ts
Expand Up @@ -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);
});
Expand Down Expand Up @@ -1625,20 +1666,20 @@ describe('pr', () => {
]
} as Inputs,
{
main: 'glo-2-bal',
main: '2-bal',
partial: [],
latest: false
} as Version,
[
'org/app:glo-2-bal',
'ghcr.io/user/app:glo-2-bal'
'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=glo-2-bal",
"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"
Expand Down
60 changes: 4 additions & 56 deletions __tests__/tag.test.ts
Expand Up @@ -21,8 +21,6 @@ describe('transform', () => {
attrs: {
"priority": DefaultPriorities[Type.Schedule],
"enable": "true",
"prefix": "",
"suffix": "",
"pattern": "nightly"
}
},
Expand All @@ -31,8 +29,6 @@ describe('transform', () => {
attrs: {
"priority": DefaultPriorities[Type.Semver],
"enable": "true",
"prefix": "",
"suffix": "",
"pattern": "{{version}}",
"value": ""
}
Expand All @@ -42,8 +38,6 @@ describe('transform', () => {
attrs: {
"priority": DefaultPriorities[Type.Match],
"enable": "true",
"prefix": "",
"suffix": "",
"pattern": "\\d.\\d.\\d",
"group": "0",
"value": ""
Expand All @@ -54,8 +48,6 @@ describe('transform', () => {
attrs: {
"priority": DefaultPriorities[Type.Edge],
"enable": "true",
"prefix": "",
"suffix": "",
"branch": ""
}
},
Expand All @@ -64,8 +56,6 @@ describe('transform', () => {
attrs: {
"priority": DefaultPriorities[Type.Ref],
"enable": "true",
"prefix": "",
"suffix": "",
"event": RefEvent.Branch
}
},
Expand All @@ -74,8 +64,6 @@ describe('transform', () => {
attrs: {
"priority": DefaultPriorities[Type.Ref],
"enable": "true",
"prefix": "",
"suffix": "",
"event": RefEvent.Tag
}
},
Expand All @@ -85,7 +73,6 @@ describe('transform', () => {
"priority": DefaultPriorities[Type.Ref],
"enable": "true",
"prefix": "pr-",
"suffix": "",
"event": RefEvent.PR
}
},
Expand All @@ -94,8 +81,6 @@ describe('transform', () => {
attrs: {
"priority": DefaultPriorities[Type.Raw],
"enable": "true",
"prefix": "",
"suffix": "",
"value": "foo"
}
},
Expand All @@ -104,8 +89,7 @@ describe('transform', () => {
attrs: {
"priority": DefaultPriorities[Type.Sha],
"enable": "true",
"prefix": "sha-",
"suffix": ""
"prefix": "sha-"
}
}
] as Tag[],
Expand Down Expand Up @@ -135,8 +119,6 @@ describe('parse', () => {
attrs: {
"priority": DefaultPriorities[Type.Schedule],
"enable": "true",
"prefix": "",
"suffix": "",
"pattern": "{{date 'YYYYMMDD'}}"
}
} as Tag,
Expand All @@ -149,8 +131,6 @@ describe('parse', () => {
attrs: {
"priority": DefaultPriorities[Type.Semver],
"enable": "true",
"prefix": "",
"suffix": "",
"pattern": "{{version}}",
"value": ""
}
Expand All @@ -164,8 +144,6 @@ describe('parse', () => {
attrs: {
"priority": "1",
"enable": "true",
"prefix": "",
"suffix": "",
"pattern": "{{version}}",
"value": ""
}
Expand All @@ -179,8 +157,6 @@ describe('parse', () => {
attrs: {
"priority": "1",
"enable": "true",
"prefix": "",
"suffix": "",
"pattern": "{{version}}",
"value": "v1.0.0"
}
Expand All @@ -194,8 +170,6 @@ describe('parse', () => {
attrs: {
"priority": DefaultPriorities[Type.Match],
"enable": "true",
"prefix": "",
"suffix": "",
"pattern": "v(.*)",
"group": "1",
"value": ""
Expand All @@ -210,8 +184,6 @@ describe('parse', () => {
attrs: {
"priority": DefaultPriorities[Type.Match],
"enable": "true",
"prefix": "",
"suffix": "",
"pattern": "^v(\\d.\\d.\\d)$",
"group": "1",
"value": ""
Expand All @@ -226,8 +198,6 @@ describe('parse', () => {
attrs: {
"priority": "700",
"enable": "true",
"prefix": "",
"suffix": "",
"pattern": "v(.*)",
"group": "1",
"value": ""
Expand All @@ -242,8 +212,6 @@ describe('parse', () => {
attrs: {
"priority": DefaultPriorities[Type.Match],
"enable": "true",
"prefix": "",
"suffix": "",
"pattern": "v(.*)",
"group": "1",
"value": "v1.2.3"
Expand All @@ -263,8 +231,6 @@ describe('parse', () => {
attrs: {
"priority": DefaultPriorities[Type.Edge],
"enable": "true",
"prefix": "",
"suffix": "",
"branch": ""
}
} as Tag,
Expand All @@ -277,8 +243,6 @@ describe('parse', () => {
attrs: {
"priority": DefaultPriorities[Type.Edge],
"enable": "true",
"prefix": "",
"suffix": "",
"branch": "master"
}
} as Tag,
Expand All @@ -291,8 +255,6 @@ describe('parse', () => {
attrs: {
"priority": DefaultPriorities[Type.Ref],
"enable": "true",
"prefix": "",
"suffix": "",
"event": RefEvent.Tag
}
} as Tag,
Expand All @@ -305,8 +267,6 @@ describe('parse', () => {
attrs: {
"priority": DefaultPriorities[Type.Ref],
"enable": "true",
"prefix": "",
"suffix": "",
"event": RefEvent.Branch
}
} as Tag,
Expand All @@ -320,7 +280,6 @@ describe('parse', () => {
"priority": DefaultPriorities[Type.Ref],
"enable": "true",
"prefix": "pr-",
"suffix": "",
"event": RefEvent.PR
}
} as Tag,
Expand All @@ -343,8 +302,6 @@ describe('parse', () => {
attrs: {
"priority": DefaultPriorities[Type.Raw],
"enable": "true",
"prefix": "",
"suffix": "",
"value": "acustomtag"
}
} as Tag,
Expand All @@ -362,8 +319,6 @@ describe('parse', () => {
attrs: {
"priority": DefaultPriorities[Type.Raw],
"enable": "true",
"prefix": "",
"suffix": "",
"value": "acustomtag2"
}
} as Tag,
Expand All @@ -376,8 +331,6 @@ describe('parse', () => {
attrs: {
"priority": DefaultPriorities[Type.Raw],
"enable": "true",
"prefix": "",
"suffix": "",
"value": "acustomtag4"
}
} as Tag,
Expand All @@ -390,8 +343,6 @@ describe('parse', () => {
attrs: {
"priority": DefaultPriorities[Type.Raw],
"enable": "false",
"prefix": "",
"suffix": "",
"value": "acustomtag5"
}
} as Tag,
Expand All @@ -404,8 +355,7 @@ describe('parse', () => {
attrs: {
"priority": DefaultPriorities[Type.Sha],
"enable": "true",
"prefix": "sha-",
"suffix": ""
"prefix": "sha-"
}
} as Tag,
false
Expand All @@ -417,8 +367,7 @@ describe('parse', () => {
attrs: {
"priority": DefaultPriorities[Type.Sha],
"enable": "true",
"prefix": "",
"suffix": ""
"prefix": ""
}
} as Tag,
false
Expand All @@ -430,8 +379,7 @@ describe('parse', () => {
attrs: {
"priority": DefaultPriorities[Type.Sha],
"enable": "false",
"prefix": "sha-",
"suffix": ""
"prefix": "sha-"
}
} as Tag,
false
Expand Down
4 changes: 2 additions & 2 deletions src/meta.ts
Expand Up @@ -315,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}`;
Expand Down
6 changes: 0 additions & 6 deletions src/tag.ts
Expand Up @@ -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']}`);
}
Expand Down

0 comments on commit 140b597

Please sign in to comment.