mirror of
https://github.com/docker/metadata-action.git
synced 2025-07-05 01:38:24 +02:00
Rework latest behavior and handle flavor
This commit is contained in:
115
__tests__/flavor.test.ts
Normal file
115
__tests__/flavor.test.ts
Normal file
@ -0,0 +1,115 @@
|
||||
import {Flavor, Transform} from '../src/flavor';
|
||||
|
||||
describe('transform', () => {
|
||||
// prettier-ignore
|
||||
test.each([
|
||||
[
|
||||
[
|
||||
`randomstr`,
|
||||
`latest=auto`
|
||||
],
|
||||
{} as Flavor,
|
||||
true
|
||||
],
|
||||
[
|
||||
[
|
||||
`unknwown=foo`
|
||||
],
|
||||
{} as Flavor,
|
||||
true
|
||||
],
|
||||
[
|
||||
[
|
||||
`latest`,
|
||||
],
|
||||
{} as Flavor,
|
||||
true
|
||||
],
|
||||
[
|
||||
[
|
||||
`latest=true`
|
||||
],
|
||||
{
|
||||
latest: "true",
|
||||
prefix: "",
|
||||
suffix: ""
|
||||
} as Flavor,
|
||||
false
|
||||
],
|
||||
[
|
||||
[
|
||||
`latest=false`
|
||||
],
|
||||
{
|
||||
latest: "false",
|
||||
prefix: "",
|
||||
suffix: ""
|
||||
} as Flavor,
|
||||
false
|
||||
],
|
||||
[
|
||||
[
|
||||
`latest=auto`
|
||||
],
|
||||
{
|
||||
latest: "auto",
|
||||
prefix: "",
|
||||
suffix: ""
|
||||
} as Flavor,
|
||||
false
|
||||
],
|
||||
[
|
||||
[
|
||||
`latest=foo`
|
||||
],
|
||||
{} as Flavor,
|
||||
true
|
||||
],
|
||||
[
|
||||
[
|
||||
`prefix=sha-`
|
||||
],
|
||||
{
|
||||
latest: "auto",
|
||||
prefix: "sha-",
|
||||
suffix: ""
|
||||
} as Flavor,
|
||||
false
|
||||
],
|
||||
[
|
||||
[
|
||||
`suffix=-alpine`
|
||||
],
|
||||
{
|
||||
latest: "auto",
|
||||
prefix: "",
|
||||
suffix: "-alpine"
|
||||
} as Flavor,
|
||||
false
|
||||
],
|
||||
[
|
||||
[
|
||||
`latest=false`,
|
||||
`prefix=dev-`,
|
||||
`suffix=-alpine`
|
||||
],
|
||||
{
|
||||
latest: "false",
|
||||
prefix: "dev-",
|
||||
suffix: "-alpine"
|
||||
} as Flavor,
|
||||
false
|
||||
],
|
||||
])('given %p attributes ', async (inputs: string[], expected: Flavor, invalid: boolean) => {
|
||||
try {
|
||||
const flavor = Transform(inputs);
|
||||
console.log(flavor);
|
||||
expect(flavor).toEqual(expected);
|
||||
} catch (err) {
|
||||
if (!invalid) {
|
||||
console.error(err);
|
||||
}
|
||||
expect(true).toBe(invalid);
|
||||
}
|
||||
});
|
||||
});
|
@ -433,6 +433,36 @@ describe('push', () => {
|
||||
"org.opencontainers.image.licenses=MIT"
|
||||
]
|
||||
],
|
||||
[
|
||||
'push12',
|
||||
'event_push_invalidchars.env',
|
||||
{
|
||||
images: ['org/app', 'ghcr.io/user/app'],
|
||||
tags: [
|
||||
`type=semver,pattern={{version}}`,
|
||||
`type=edge`
|
||||
],
|
||||
} as Inputs,
|
||||
{
|
||||
main: 'my-feature-1245',
|
||||
partial: [],
|
||||
latest: false
|
||||
} as Version,
|
||||
[
|
||||
'org/app:my-feature-1245',
|
||||
'ghcr.io/user/app:my-feature-1245'
|
||||
],
|
||||
[
|
||||
"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-feature-1245",
|
||||
"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);
|
||||
});
|
||||
|
||||
@ -497,7 +527,10 @@ describe('tag', () => {
|
||||
{
|
||||
images: ['user/app'],
|
||||
tags: [
|
||||
`type=match,latest=false,pattern=\\d{8}`
|
||||
`type=match,pattern=\\d{8}`
|
||||
],
|
||||
flavor: [
|
||||
`latest=false`
|
||||
]
|
||||
} as Inputs,
|
||||
{
|
||||
@ -525,7 +558,10 @@ describe('tag', () => {
|
||||
{
|
||||
images: ['user/app'],
|
||||
tags: [
|
||||
`type=match,latest=false,pattern=(.*)-RC,group=1`
|
||||
`type=match,pattern=(.*)-RC,group=1`
|
||||
],
|
||||
flavor: [
|
||||
`latest=false`
|
||||
]
|
||||
} as Inputs,
|
||||
{
|
||||
@ -834,10 +870,13 @@ describe('tag', () => {
|
||||
{
|
||||
images: ['ghcr.io/user/app'],
|
||||
tags: [
|
||||
`type=ref,latest=false,event=tag`,
|
||||
`type=semver,latest=false,pattern={{version}}`,
|
||||
`type=semver,latest=false,pattern={{major}}.{{minor}}`,
|
||||
`type=semver,latest=false,pattern={{major}}`
|
||||
`type=ref,event=tag`,
|
||||
`type=semver,pattern={{version}}`,
|
||||
`type=semver,pattern={{major}}.{{minor}}`,
|
||||
`type=semver,pattern={{major}}`
|
||||
],
|
||||
flavor: [
|
||||
`latest=false`
|
||||
]
|
||||
} as Inputs,
|
||||
{
|
||||
@ -858,7 +897,7 @@ describe('tag', () => {
|
||||
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
|
||||
"org.opencontainers.image.licenses=MIT"
|
||||
]
|
||||
],
|
||||
]
|
||||
])('given %p with %p event', tagsLabelsTest);
|
||||
});
|
||||
|
||||
@ -1046,7 +1085,10 @@ describe('latest', () => {
|
||||
{
|
||||
images: ['org/app', 'ghcr.io/user/app'],
|
||||
tags: [
|
||||
`type=ref,latest=false,event=tag`
|
||||
`type=ref,event=tag`
|
||||
],
|
||||
flavor: [
|
||||
`latest=false`
|
||||
]
|
||||
} as Inputs,
|
||||
{
|
||||
@ -1075,7 +1117,10 @@ describe('latest', () => {
|
||||
{
|
||||
images: ['org/app', 'ghcr.io/MyUSER/MyApp'],
|
||||
tags: [
|
||||
`type=ref,latest=false,event=tag`
|
||||
`type=ref,event=tag`
|
||||
],
|
||||
flavor: [
|
||||
`latest=false`
|
||||
]
|
||||
} as Inputs,
|
||||
{
|
||||
@ -1104,7 +1149,10 @@ describe('latest', () => {
|
||||
{
|
||||
images: ['org/app', 'ghcr.io/MyUSER/MyApp'],
|
||||
tags: [
|
||||
`type=ref,latest=false,event=tag`
|
||||
`type=ref,event=tag`
|
||||
],
|
||||
flavor: [
|
||||
`latest=false`
|
||||
],
|
||||
labels: [
|
||||
"maintainer=CrazyMax",
|
||||
@ -1374,6 +1422,38 @@ describe('schedule', () => {
|
||||
"org.opencontainers.image.licenses=MIT"
|
||||
]
|
||||
],
|
||||
[
|
||||
'schedule06',
|
||||
'event_schedule.env',
|
||||
{
|
||||
images: ['org/app', 'ghcr.io/user/app'],
|
||||
tags: [
|
||||
`type=schedule`,
|
||||
`type=sha,priority=2000`
|
||||
]
|
||||
} as Inputs,
|
||||
{
|
||||
main: 'sha-90dd603',
|
||||
partial: ['nightly'],
|
||||
latest: false
|
||||
} as Version,
|
||||
[
|
||||
'org/app:sha-90dd603',
|
||||
'org/app:nightly',
|
||||
'ghcr.io/user/app:sha-90dd603',
|
||||
'ghcr.io/user/app:nightly'
|
||||
],
|
||||
[
|
||||
"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=sha-90dd603",
|
||||
"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);
|
||||
});
|
||||
|
||||
@ -1517,10 +1597,13 @@ describe('raw', () => {
|
||||
{
|
||||
images: ['user/app'],
|
||||
tags: [
|
||||
`type=match,latest=false,pattern=\\d{8}`,
|
||||
`type=match,pattern=\\d{8}`,
|
||||
`type=raw,my`,
|
||||
`type=raw,custom`,
|
||||
`type=raw,tags`
|
||||
],
|
||||
flavor: [
|
||||
`latest=false`
|
||||
]
|
||||
} as Inputs,
|
||||
{
|
||||
@ -1633,9 +1716,12 @@ describe('raw', () => {
|
||||
images: ['user/app'],
|
||||
tags: [
|
||||
`type=ref,priority=90,event=branch`,
|
||||
`type=raw,latest=true,my`,
|
||||
`type=raw,my`,
|
||||
`type=raw,custom`,
|
||||
`type=raw,tags`
|
||||
],
|
||||
flavor: [
|
||||
`latest=true`
|
||||
]
|
||||
} as Inputs,
|
||||
{
|
||||
@ -1787,10 +1873,13 @@ describe('bake', () => {
|
||||
{
|
||||
images: ['user/app'],
|
||||
tags: [
|
||||
`type=match,latest=false,pattern=\\d{8}`,
|
||||
`type=match,pattern=\\d{8}`,
|
||||
`type=raw,my`,
|
||||
`type=raw,custom`,
|
||||
`type=raw,tags`
|
||||
],
|
||||
flavor: [
|
||||
`latest=false`
|
||||
]
|
||||
} as Inputs,
|
||||
{
|
||||
|
@ -21,7 +21,6 @@ describe('transform', () => {
|
||||
attrs: {
|
||||
"priority": DefaultPriorities[Type.Schedule],
|
||||
"enable": "true",
|
||||
"latest": "auto",
|
||||
"prefix": "",
|
||||
"suffix": "",
|
||||
"pattern": "nightly"
|
||||
@ -32,7 +31,6 @@ describe('transform', () => {
|
||||
attrs: {
|
||||
"priority": DefaultPriorities[Type.Semver],
|
||||
"enable": "true",
|
||||
"latest": "auto",
|
||||
"prefix": "",
|
||||
"suffix": "",
|
||||
"pattern": "{{version}}"
|
||||
@ -43,7 +41,6 @@ describe('transform', () => {
|
||||
attrs: {
|
||||
"priority": DefaultPriorities[Type.Match],
|
||||
"enable": "true",
|
||||
"latest": "auto",
|
||||
"prefix": "",
|
||||
"suffix": "",
|
||||
"pattern": "\\d{1,3}.\\d{1,3}.\\d{1,3}",
|
||||
@ -55,7 +52,6 @@ describe('transform', () => {
|
||||
attrs: {
|
||||
"priority": DefaultPriorities[Type.Edge],
|
||||
"enable": "true",
|
||||
"latest": "auto",
|
||||
"prefix": "",
|
||||
"suffix": "",
|
||||
"branch": ""
|
||||
@ -66,7 +62,6 @@ describe('transform', () => {
|
||||
attrs: {
|
||||
"priority": DefaultPriorities[Type.Ref],
|
||||
"enable": "true",
|
||||
"latest": "auto",
|
||||
"prefix": "",
|
||||
"suffix": "",
|
||||
"event": RefEvent.Branch
|
||||
@ -77,7 +72,6 @@ describe('transform', () => {
|
||||
attrs: {
|
||||
"priority": DefaultPriorities[Type.Ref],
|
||||
"enable": "true",
|
||||
"latest": "auto",
|
||||
"prefix": "",
|
||||
"suffix": "",
|
||||
"event": RefEvent.Tag
|
||||
@ -88,7 +82,6 @@ describe('transform', () => {
|
||||
attrs: {
|
||||
"priority": DefaultPriorities[Type.Ref],
|
||||
"enable": "true",
|
||||
"latest": "auto",
|
||||
"prefix": "pr-",
|
||||
"suffix": "",
|
||||
"event": RefEvent.PR
|
||||
@ -99,7 +92,6 @@ describe('transform', () => {
|
||||
attrs: {
|
||||
"priority": DefaultPriorities[Type.Raw],
|
||||
"enable": "true",
|
||||
"latest": "auto",
|
||||
"prefix": "",
|
||||
"suffix": "",
|
||||
"value": "foo"
|
||||
@ -110,7 +102,6 @@ describe('transform', () => {
|
||||
attrs: {
|
||||
"priority": DefaultPriorities[Type.Sha],
|
||||
"enable": "true",
|
||||
"latest": "auto",
|
||||
"prefix": "sha-",
|
||||
"suffix": ""
|
||||
}
|
||||
@ -142,7 +133,6 @@ describe('parse', () => {
|
||||
attrs: {
|
||||
"priority": DefaultPriorities[Type.Schedule],
|
||||
"enable": "true",
|
||||
"latest": "auto",
|
||||
"prefix": "",
|
||||
"suffix": "",
|
||||
"pattern": "{{date 'YYYYMMDD'}}"
|
||||
@ -162,7 +152,6 @@ describe('parse', () => {
|
||||
attrs: {
|
||||
"priority": DefaultPriorities[Type.Semver],
|
||||
"enable": "true",
|
||||
"latest": "auto",
|
||||
"prefix": "",
|
||||
"suffix": "",
|
||||
"pattern": "{{version}}"
|
||||
@ -177,7 +166,6 @@ describe('parse', () => {
|
||||
attrs: {
|
||||
"priority": "1",
|
||||
"enable": "true",
|
||||
"latest": "auto",
|
||||
"prefix": "",
|
||||
"suffix": "",
|
||||
"pattern": "{{version}}"
|
||||
@ -197,7 +185,6 @@ describe('parse', () => {
|
||||
attrs: {
|
||||
"priority": DefaultPriorities[Type.Match],
|
||||
"enable": "true",
|
||||
"latest": "auto",
|
||||
"prefix": "",
|
||||
"suffix": "",
|
||||
"pattern": "v(.*)",
|
||||
@ -213,7 +200,6 @@ describe('parse', () => {
|
||||
attrs: {
|
||||
"priority": DefaultPriorities[Type.Match],
|
||||
"enable": "true",
|
||||
"latest": "auto",
|
||||
"prefix": "",
|
||||
"suffix": "",
|
||||
"pattern": "^v(\\d{1,3}.\\d{1,3}.\\d{1,3})$",
|
||||
@ -229,7 +215,6 @@ describe('parse', () => {
|
||||
attrs: {
|
||||
"priority": "700",
|
||||
"enable": "true",
|
||||
"latest": "auto",
|
||||
"prefix": "",
|
||||
"suffix": "",
|
||||
"pattern": "v(.*)",
|
||||
@ -250,7 +235,6 @@ describe('parse', () => {
|
||||
attrs: {
|
||||
"priority": DefaultPriorities[Type.Edge],
|
||||
"enable": "true",
|
||||
"latest": "auto",
|
||||
"prefix": "",
|
||||
"suffix": "",
|
||||
"branch": ""
|
||||
@ -265,7 +249,6 @@ describe('parse', () => {
|
||||
attrs: {
|
||||
"priority": DefaultPriorities[Type.Edge],
|
||||
"enable": "true",
|
||||
"latest": "auto",
|
||||
"prefix": "",
|
||||
"suffix": "",
|
||||
"branch": "master"
|
||||
@ -280,7 +263,6 @@ describe('parse', () => {
|
||||
attrs: {
|
||||
"priority": DefaultPriorities[Type.Ref],
|
||||
"enable": "true",
|
||||
"latest": "auto",
|
||||
"prefix": "",
|
||||
"suffix": "",
|
||||
"event": RefEvent.Tag
|
||||
@ -295,7 +277,6 @@ describe('parse', () => {
|
||||
attrs: {
|
||||
"priority": DefaultPriorities[Type.Ref],
|
||||
"enable": "true",
|
||||
"latest": "auto",
|
||||
"prefix": "",
|
||||
"suffix": "",
|
||||
"event": RefEvent.Branch
|
||||
@ -310,7 +291,6 @@ describe('parse', () => {
|
||||
attrs: {
|
||||
"priority": DefaultPriorities[Type.Ref],
|
||||
"enable": "true",
|
||||
"latest": "auto",
|
||||
"prefix": "pr-",
|
||||
"suffix": "",
|
||||
"event": RefEvent.PR
|
||||
@ -335,7 +315,6 @@ describe('parse', () => {
|
||||
attrs: {
|
||||
"priority": DefaultPriorities[Type.Raw],
|
||||
"enable": "true",
|
||||
"latest": "auto",
|
||||
"prefix": "",
|
||||
"suffix": "",
|
||||
"value": "acustomtag"
|
||||
@ -355,7 +334,6 @@ describe('parse', () => {
|
||||
attrs: {
|
||||
"priority": DefaultPriorities[Type.Raw],
|
||||
"enable": "true",
|
||||
"latest": "auto",
|
||||
"prefix": "",
|
||||
"suffix": "",
|
||||
"value": "acustomtag2"
|
||||
@ -370,7 +348,6 @@ describe('parse', () => {
|
||||
attrs: {
|
||||
"priority": DefaultPriorities[Type.Raw],
|
||||
"enable": "true",
|
||||
"latest": "auto",
|
||||
"prefix": "",
|
||||
"suffix": "",
|
||||
"value": "acustomtag4"
|
||||
@ -385,7 +362,6 @@ describe('parse', () => {
|
||||
attrs: {
|
||||
"priority": DefaultPriorities[Type.Raw],
|
||||
"enable": "false",
|
||||
"latest": "auto",
|
||||
"prefix": "",
|
||||
"suffix": "",
|
||||
"value": "acustomtag5"
|
||||
@ -400,7 +376,6 @@ describe('parse', () => {
|
||||
attrs: {
|
||||
"priority": DefaultPriorities[Type.Sha],
|
||||
"enable": "true",
|
||||
"latest": "auto",
|
||||
"prefix": "sha-",
|
||||
"suffix": ""
|
||||
}
|
||||
@ -414,7 +389,6 @@ describe('parse', () => {
|
||||
attrs: {
|
||||
"priority": DefaultPriorities[Type.Sha],
|
||||
"enable": "true",
|
||||
"latest": "auto",
|
||||
"prefix": "",
|
||||
"suffix": ""
|
||||
}
|
||||
@ -428,7 +402,6 @@ describe('parse', () => {
|
||||
attrs: {
|
||||
"priority": DefaultPriorities[Type.Sha],
|
||||
"enable": "false",
|
||||
"latest": "auto",
|
||||
"prefix": "sha-",
|
||||
"suffix": ""
|
||||
}
|
||||
|
Reference in New Issue
Block a user