Added on_latest flavor to apply flavor to latest tags

This commit is contained in:
Jacob White 2021-06-16 13:15:24 -04:00
parent 94c9b333c5
commit cffbfa0b4d
No known key found for this signature in database
GPG Key ID: 2E58765CE9B2BB40
5 changed files with 142 additions and 10 deletions

View File

@ -32,7 +32,8 @@ describe('transform', () => {
{
latest: "true",
prefix: "",
suffix: ""
suffix: "",
on_latest: "false"
} as Flavor,
false
],
@ -43,7 +44,8 @@ describe('transform', () => {
{
latest: "false",
prefix: "",
suffix: ""
suffix: "",
on_latest: "false"
} as Flavor,
false
],
@ -54,7 +56,8 @@ describe('transform', () => {
{
latest: "auto",
prefix: "",
suffix: ""
suffix: "",
on_latest: "false"
} as Flavor,
false
],
@ -72,7 +75,8 @@ describe('transform', () => {
{
latest: "auto",
prefix: "sha-",
suffix: ""
suffix: "",
on_latest: "false"
} as Flavor,
false
],
@ -83,7 +87,8 @@ describe('transform', () => {
{
latest: "auto",
prefix: "",
suffix: "-alpine"
suffix: "-alpine",
on_latest: "false"
} as Flavor,
false
],
@ -96,10 +101,36 @@ describe('transform', () => {
{
latest: "false",
prefix: "dev-",
suffix: "-alpine"
suffix: "-alpine",
on_latest: "false"
} as Flavor,
false
],
[
[
`latest=auto`,
`prefix=`,
`suffix=-alpine`,
`on_latest=true`
],
{
latest: "auto",
prefix: "",
suffix: "-alpine",
on_latest: "true"
} as Flavor,
false
],
[
[
`latest=true`,
`prefix=`,
`suffix=-alpine`,
`on_latest=fail`
],
{} as Flavor,
true
]
])('given %p attributes ', async (inputs: string[], expected: Flavor, invalid: boolean) => {
try {
const flavor = Transform(inputs);

View File

@ -1589,6 +1589,78 @@ describe('latest', () => {
"org.opencontainers.image.vendor=MyCompany"
]
],
[
'latest10',
'event_tag_v1.1.1.env',
{
images: ['org/app', 'ghcr.io/user/app'],
tags: [
`type=ref,event=tag`
],
flavor: [
`latest=true`,
`on_latest=true`,
`suffix=-alpine`
],
} as Inputs,
{
main: 'v1.1.1-alpine',
partial: [],
latest: true
} as Version,
[
'org/app:v1.1.1-alpine',
'org/app:latest-alpine',
'ghcr.io/user/app:v1.1.1-alpine',
'ghcr.io/user/app:latest-alpine'
],
[
"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=v1.1.1-alpine",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT"
]
],
[
'latest12',
'event_tag_v1.1.1.env',
{
images: ['org/app', 'ghcr.io/user/app'],
tags: [
`type=ref,event=tag`
],
flavor: [
`latest=true`,
`on_latest=true`,
`prefix=dev-`
],
} as Inputs,
{
main: 'dev-v1.1.1',
partial: [],
latest: true
} as Version,
[
'org/app:dev-v1.1.1',
'org/app:dev-latest',
'ghcr.io/user/app:dev-v1.1.1',
'ghcr.io/user/app:dev-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=dev-v1.1.1",
"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);
});

18
dist/index.js generated vendored
View File

@ -136,7 +136,8 @@ function Transform(inputs) {
const flavor = {
latest: 'auto',
prefix: '',
suffix: ''
suffix: '',
on_latest: 'false'
};
for (const input of inputs) {
const parts = input.split('=', 2);
@ -159,6 +160,13 @@ function Transform(inputs) {
flavor.suffix = parts[1];
break;
}
case 'on_latest': {
flavor.on_latest = parts[1];
if (!['true', 'false'].includes(flavor.on_latest)) {
throw new Error(`Invalid on_latest flavor entry: ${input}`);
}
break;
}
default: {
throw new Error(`Unknown entry: ${input}`);
}
@ -168,6 +176,7 @@ function Transform(inputs) {
core.info(`latest=${flavor.latest}`);
core.info(`prefix=${flavor.prefix}`);
core.info(`suffix=${flavor.suffix}`);
core.info(`on_latest=${flavor.on_latest}`);
core.endGroup();
return flavor;
}
@ -633,7 +642,12 @@ class Meta {
tags.push(`${imageLc}:${partial}`);
}
if (this.version.latest) {
tags.push(`${imageLc}:latest`);
if (this.flavor.on_latest === "true") {
tags.push(`${imageLc}:${this.flavor.prefix}latest${this.flavor.suffix}`);
}
else {
tags.push(`${imageLc}:latest`);
}
}
}
return tags;

View File

@ -4,13 +4,15 @@ export interface Flavor {
latest: string;
prefix: string;
suffix: string;
on_latest: string;
}
export function Transform(inputs: string[]): Flavor {
const flavor: Flavor = {
latest: 'auto',
prefix: '',
suffix: ''
suffix: '',
on_latest: 'false'
};
for (const input of inputs) {
@ -34,6 +36,13 @@ export function Transform(inputs: string[]): Flavor {
flavor.suffix = parts[1];
break;
}
case 'on_latest': {
flavor.on_latest = parts[1];
if (!['true', 'false'].includes(flavor.on_latest)) {
throw new Error(`Invalid on_latest flavor entry: ${input}`);
}
break;
}
default: {
throw new Error(`Unknown entry: ${input}`);
}
@ -44,6 +53,8 @@ export function Transform(inputs: string[]): Flavor {
core.info(`latest=${flavor.latest}`);
core.info(`prefix=${flavor.prefix}`);
core.info(`suffix=${flavor.suffix}`);
core.info(`on_latest=${flavor.on_latest}`);
core.endGroup();
return flavor;

View File

@ -304,7 +304,11 @@ export class Meta {
tags.push(`${imageLc}:${partial}`);
}
if (this.version.latest) {
tags.push(`${imageLc}:latest`);
if (this.flavor.on_latest === 'true') {
tags.push(`${imageLc}:${this.flavor.prefix}latest${this.flavor.suffix}`);
} else {
tags.push(`${imageLc}:latest`);
}
}
}
return tags;