Skip to content

Commit

Permalink
Rework latest behavior and handle flavor
Browse files Browse the repository at this point in the history
  • Loading branch information
crazy-max committed Mar 25, 2021
1 parent 63a49e1 commit e2af761
Show file tree
Hide file tree
Showing 10 changed files with 366 additions and 87 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ jobs:
strategy:
fail-fast: false
matrix:
tag-latest:
flavor-latest:
- "auto"
- "true"
- "false"
Expand All @@ -122,10 +122,12 @@ jobs:
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
type=semver,latest=${{ matrix.tag-latest }},pattern={{raw}}
type=semver,latest=${{ matrix.tag-latest }},pattern={{version}}
type=semver,latest=${{ matrix.tag-latest }},pattern={{major}}.{{minor}}.{{patch}}
type=semver,pattern={{raw}}
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}.{{patch}}
type=sha
flavor: |
latest=${{ matrix.flavor-latest }}
label-custom:
runs-on: ubuntu-latest
Expand Down
115 changes: 115 additions & 0 deletions __tests__/flavor.test.ts
Original file line number Diff line number Diff line change
@@ -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);
}
});
});
115 changes: 102 additions & 13 deletions __tests__/meta.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down Expand Up @@ -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,
{
Expand Down Expand Up @@ -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,
{
Expand Down Expand Up @@ -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,
{
Expand All @@ -858,7 +897,7 @@ describe('tag', () => {
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT"
]
],
]
])('given %p with %p event', tagsLabelsTest);
});

Expand Down Expand Up @@ -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,
{
Expand Down Expand Up @@ -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,
{
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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);
});

Expand Down Expand Up @@ -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,
{
Expand Down Expand Up @@ -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,
{
Expand Down Expand Up @@ -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,
{
Expand Down
Loading

0 comments on commit e2af761

Please sign in to comment.