Skip to content

Commit f19c369

Browse files
authored
Merge pull request #358 from crazy-max/empty-images
feat: allow images input to be empty to output bare tags
2 parents 051f7ea + 4066f0c commit f19c369

File tree

8 files changed

+153
-12
lines changed

8 files changed

+153
-12
lines changed

.github/workflows/ci.yml

+20
Original file line numberDiff line numberDiff line change
@@ -427,3 +427,23 @@ jobs:
427427
${{ steps.docker_meta.outputs.bake-file-annotations }}
428428
targets: |
429429
release
430+
431+
no-images:
432+
runs-on: ubuntu-latest
433+
steps:
434+
-
435+
name: Checkout
436+
uses: actions/checkout@v4
437+
-
438+
name: Docker meta
439+
uses: ./
440+
with:
441+
tags: |
442+
type=schedule
443+
type=ref,event=branch
444+
type=ref,event=tag
445+
type=ref,event=pr
446+
type=sha
447+
-
448+
name: Print envs
449+
run: env|sort

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,8 @@ images: |
383383
* `name=<string>` image base name
384384
* `enable=<true|false>` enable this entry (default `true`)
385385

386+
If `images` is empty, tags will be generated without base name.
387+
386388
## `flavor` input
387389

388390
`flavor` defines a global behavior for [`tags`](#tags-input):

__tests__/meta.test.ts

+110
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,50 @@ describe('push', () => {
733733
"org.opencontainers.image.url=https://github.com/octocat/Hello-World",
734734
"org.opencontainers.image.version=sha-860c1904a1ce19322e91ac35af1ab07466440c37"
735735
]
736+
],
737+
[
738+
'push21',
739+
'event_push_master.env',
740+
{
741+
images: [] as string[],
742+
tags: [
743+
`type=raw,value=mytag-{{branch}}`,
744+
`type=raw,value=mytag-{{date 'YYYYMMDD'}}`,
745+
`type=raw,value=mytag-{{date 'YYYYMMDD-HHmmss' tz='Asia/Tokyo'}}`,
746+
`type=raw,value=mytag-tag-{{tag}}`,
747+
`type=raw,value=mytag-baseref-{{base_ref}}`,
748+
`type=raw,value=mytag-defbranch,enable={{is_default_branch}}`
749+
],
750+
} as Inputs,
751+
{
752+
main: 'mytag-master',
753+
partial: [
754+
'mytag-20200110',
755+
'mytag-20200110-093000',
756+
'mytag-tag-',
757+
'mytag-baseref-',
758+
'mytag-defbranch'
759+
],
760+
latest: false
761+
} as Version,
762+
[
763+
'mytag-master',
764+
'mytag-20200110',
765+
'mytag-20200110-093000',
766+
'mytag-tag-',
767+
'mytag-baseref-',
768+
'mytag-defbranch'
769+
],
770+
[
771+
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
772+
"org.opencontainers.image.description=This your first repo!",
773+
"org.opencontainers.image.licenses=MIT",
774+
"org.opencontainers.image.revision=266574110acf203503badf966df2ea24b5d732d7",
775+
"org.opencontainers.image.source=https://github.com/octocat/Hello-World",
776+
"org.opencontainers.image.title=Hello-World",
777+
"org.opencontainers.image.url=https://github.com/octocat/Hello-World",
778+
"org.opencontainers.image.version=mytag-master"
779+
]
736780
]
737781
])('given %p with %p event', tagsLabelsTest);
738782
});
@@ -1780,6 +1824,43 @@ describe('tag', () => {
17801824
"org.opencontainers.image.version=v1.2.3rc2"
17811825
]
17821826
],
1827+
[
1828+
'tag33',
1829+
'event_tag_v1.1.1.env',
1830+
{
1831+
images: [] as string[],
1832+
tags: [
1833+
`type=pep440,pattern={{version}}`,
1834+
`type=pep440,pattern={{major}}.{{minor}}.{{patch}}`,
1835+
`type=pep440,pattern={{major}}.{{minor}}`,
1836+
`type=pep440,pattern={{major}}`
1837+
]
1838+
} as Inputs,
1839+
{
1840+
main: '1.1.1',
1841+
partial: [
1842+
"1.1",
1843+
"1"
1844+
],
1845+
latest: true
1846+
} as Version,
1847+
[
1848+
'1.1.1',
1849+
'1.1',
1850+
'1',
1851+
'latest'
1852+
],
1853+
[
1854+
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
1855+
"org.opencontainers.image.description=This your first repo!",
1856+
"org.opencontainers.image.licenses=MIT",
1857+
"org.opencontainers.image.revision=860c1904a1ce19322e91ac35af1ab07466440c37",
1858+
"org.opencontainers.image.source=https://github.com/octocat/Hello-World",
1859+
"org.opencontainers.image.title=Hello-World",
1860+
"org.opencontainers.image.url=https://github.com/octocat/Hello-World",
1861+
"org.opencontainers.image.version=1.1.1"
1862+
]
1863+
]
17831864
])('given %p with %p event', tagsLabelsTest);
17841865
});
17851866

@@ -2066,6 +2147,35 @@ describe('latest', () => {
20662147
"org.opencontainers.image.version=v1.1.1"
20672148
]
20682149
],
2150+
[
2151+
'latest10',
2152+
'event_tag_v2.0.8-beta.67.env',
2153+
{
2154+
images: [] as string[],
2155+
tags: [
2156+
`type=match,"pattern=\\d.\\d.\\d"`
2157+
]
2158+
} as Inputs,
2159+
{
2160+
main: '2.0.8',
2161+
partial: [],
2162+
latest: true
2163+
} as Version,
2164+
[
2165+
'2.0.8',
2166+
'latest',
2167+
],
2168+
[
2169+
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
2170+
"org.opencontainers.image.description=This your first repo!",
2171+
"org.opencontainers.image.licenses=MIT",
2172+
"org.opencontainers.image.revision=860c1904a1ce19322e91ac35af1ab07466440c37",
2173+
"org.opencontainers.image.source=https://github.com/octocat/Hello-World",
2174+
"org.opencontainers.image.title=Hello-World",
2175+
"org.opencontainers.image.url=https://github.com/octocat/Hello-World",
2176+
"org.opencontainers.image.version=2.0.8"
2177+
]
2178+
]
20692179
])('given %p with %p event', tagsLabelsTest);
20702180
});
20712181

action.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ inputs:
1313
required: true
1414
images:
1515
description: 'List of Docker images to use as base name for tags'
16-
required: true
16+
required: false
1717
tags:
1818
description: 'List of tags as key-value pair attributes'
1919
required: false

dist/index.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.ts

-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ actionsToolkit.run(
1515
// main
1616
async () => {
1717
const inputs: Inputs = getInputs();
18-
if (inputs.images.length == 0) {
19-
throw new Error(`images input required`);
20-
}
21-
2218
const toolkit = new Toolkit({githubToken: inputs.githubToken});
2319
const context = await getContext(inputs.context);
2420
const repo = await toolkit.github.repoData();

src/meta.ts

+18-5
Original file line numberDiff line numberDiff line change
@@ -440,16 +440,29 @@ export class Meta {
440440
if (!this.version.main) {
441441
return [];
442442
}
443-
const tags: Array<string> = [];
444-
for (const imageName of this.getImageNames()) {
445-
tags.push(`${imageName}:${this.version.main}`);
443+
444+
const generateTags = (imageName: string, version: string): Array<string> => {
445+
const tags: Array<string> = [];
446+
const prefix = imageName !== '' ? `${imageName}:` : '';
447+
tags.push(`${prefix}${version}`);
446448
for (const partial of this.version.partial) {
447-
tags.push(`${imageName}:${partial}`);
449+
tags.push(`${prefix}${partial}`);
448450
}
449451
if (this.version.latest) {
450452
const latestTag = `${this.flavor.prefixLatest ? this.flavor.prefix : ''}latest${this.flavor.suffixLatest ? this.flavor.suffix : ''}`;
451-
tags.push(`${imageName}:${Meta.sanitizeTag(latestTag)}`);
453+
tags.push(`${prefix}${Meta.sanitizeTag(latestTag)}`);
452454
}
455+
return tags;
456+
};
457+
458+
const tags: Array<string> = [];
459+
const images = this.getImageNames();
460+
if (images.length > 0) {
461+
for (const imageName of images) {
462+
tags.push(...generateTags(imageName, this.version.main));
463+
}
464+
} else {
465+
tags.push(...generateTags('', this.version.main));
453466
}
454467
return tags;
455468
}

0 commit comments

Comments
 (0)