feat: add tag-suffix and tag-prefix options

This commit is contained in:
CharlieC3 2021-03-08 16:52:14 -05:00
parent 5f29dbc7d7
commit 983af1f9f4
No known key found for this signature in database
GPG Key ID: 0DDC8A2437C56218
6 changed files with 167 additions and 8 deletions

View File

@ -282,6 +282,8 @@ Following inputs can be used as `step.with` keys
| `tag-schedule` | String | [Template](#schedule-tag) to apply to schedule tag (default `nightly`) |
| `tag-custom` | List/CSV | List of custom tags |
| `tag-custom-only` | Bool | Only use `tag-custom` as Docker tags |
| `tag-suffix` | String | Appends a string to the end of all Docker tags |
| `tag-prefix` | String | Prepends a string to the beginning of all Docker tags |
| `label-custom` | List | List of custom labels |
| `sep-tags` | String | Separator to use for tags output (default `\n`) |
| `sep-labels` | String | Separator to use for labels output (default `\n`) |

View File

@ -134,6 +134,32 @@ describe('push', () => {
"org.opencontainers.image.licenses=MIT"
]
],
[
'event_push.env',
{
images: ['user/app'],
tagPrefix: 'prepend-',
tagSuffix: '-append'
} as Inputs,
{
main: 'dev',
partial: [],
latest: false
} as Version,
[
'user/app:prepend-dev-append'
],
[
"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",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT"
]
],
[
'event_push_defbranch.env',
{
@ -233,6 +259,33 @@ describe('push', () => {
"org.opencontainers.image.licenses=MIT"
]
],
[
'event_push.env',
{
images: ['org/app', 'ghcr.io/user/app'],
tagPrefix: 'prepend-',
tagSuffix: '-append'
} as Inputs,
{
main: 'dev',
partial: [],
latest: false
} as Version,
[
'org/app:prepend-dev-append',
'ghcr.io/user/app:prepend-dev-append'
],
[
"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",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT"
]
],
[
'event_push_defbranch.env',
{
@ -287,6 +340,36 @@ describe('push', () => {
"org.opencontainers.image.licenses=MIT"
]
],
[
'event_push.env',
{
images: ['org/app', 'ghcr.io/user/app'],
tagSha: true,
tagPrefix: 'prepend-',
tagSuffix: '-append'
} as Inputs,
{
main: 'dev',
partial: [],
latest: false
} as Version,
[
'org/app:prepend-dev-append',
'org/app:prepend-sha-90dd603-append',
'ghcr.io/user/app:prepend-dev-append',
'ghcr.io/user/app:prepend-sha-90dd603-append'
],
[
"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",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT"
]
],
[
'event_push_defbranch.env',
{
@ -346,6 +429,38 @@ describe('push', () => {
"org.opencontainers.image.licenses=MIT"
]
],
[
'event_push.env',
{
images: ['org/app', 'ghcr.io/user/app'],
tagSha: true,
tagEdge: true,
tagEdgeBranch: 'dev',
tagPrefix: 'prepend-',
tagSuffix: '-append'
} as Inputs,
{
main: 'edge',
partial: [],
latest: false
} as Version,
[
'org/app:prepend-edge-append',
'org/app:prepend-sha-90dd603-append',
'ghcr.io/user/app:prepend-edge-append',
'ghcr.io/user/app:prepend-sha-90dd603-append'
],
[
"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=edge",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT"
]
],
[
'event_push_defbranch.env',
{
@ -1326,6 +1441,36 @@ describe('custom', () => {
"org.opencontainers.image.licenses=MIT"
]
],
[
'event_push.env',
{
images: ['user/app'],
tagCustom: ['my', 'custom', 'tags'],
tagPrefix: 'prepend-',
tagSuffix: '-append'
} as Inputs,
{
main: 'dev',
partial: ['my', 'custom', 'tags'],
latest: false
} as Version,
[
'user/app:prepend-dev-append',
'user/app:prepend-my-append',
'user/app:prepend-custom-append',
'user/app:prepend-tags-append'
],
[
"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",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT"
]
],
[
'event_push.env',
{

View File

@ -50,6 +50,12 @@ inputs:
tag-custom-only:
description: 'Only use tag-custom as Docker tags'
required: false
tag-suffix:
description: 'Appends a string to the end of all Docker tags'
required: false
tag-prefix:
description: 'Prepends a string to the beginning of all Docker tags'
required: false
label-custom:
description: 'List of custom labels'
required: false

10
dist/index.js generated vendored
View File

@ -66,6 +66,8 @@ function getInputs() {
tagSchedule: core.getInput('tag-schedule') || 'nightly',
tagCustom: getInputList('tag-custom'),
tagCustomOnly: /true/i.test(core.getInput('tag-custom-only') || 'false'),
tagSuffix: core.getInput('tag-suffix'),
tagPrefix: core.getInput('tag-prefix'),
labelCustom: getInputList('label-custom'),
sepTags: core.getInput('sep-tags') || `\n`,
sepLabels: core.getInput('sep-labels') || `\n`,
@ -392,15 +394,15 @@ class Meta {
let tags = [];
for (const image of this.inputs.images) {
const imageLc = image.toLowerCase();
tags.push(`${imageLc}:${this.version.main}`);
tags.push(`${imageLc}:${this.inputs.tagPrefix}${this.version.main}${this.inputs.tagSuffix}`);
for (const partial of this.version.partial) {
tags.push(`${imageLc}:${partial}`);
tags.push(`${imageLc}:${this.inputs.tagPrefix}${partial}${this.inputs.tagSuffix}`);
}
if (this.version.latest) {
tags.push(`${imageLc}:latest`);
tags.push(`${imageLc}:${this.inputs.tagPrefix}latest${this.inputs.tagSuffix}`);
}
if (this.context.sha && this.inputs.tagSha) {
tags.push(`${imageLc}:sha-${this.context.sha.substr(0, 7)}`);
tags.push(`${imageLc}:${this.inputs.tagPrefix}sha-${this.context.sha.substr(0, 7)}${this.inputs.tagSuffix}`);
}
}
return tags;

View File

@ -18,6 +18,8 @@ export interface Inputs {
tagSchedule: string;
tagCustom: string[];
tagCustomOnly: boolean;
tagSuffix: string;
tagPrefix: string;
labelCustom: string[];
sepTags: string;
sepLabels: string;
@ -44,6 +46,8 @@ export function getInputs(): Inputs {
tagSchedule: core.getInput('tag-schedule') || 'nightly',
tagCustom: getInputList('tag-custom'),
tagCustomOnly: /true/i.test(core.getInput('tag-custom-only') || 'false'),
tagSuffix: core.getInput('tag-suffix'),
tagPrefix: core.getInput('tag-prefix'),
labelCustom: getInputList('label-custom'),
sepTags: core.getInput('sep-tags') || `\n`,
sepLabels: core.getInput('sep-labels') || `\n`,

View File

@ -117,15 +117,15 @@ export class Meta {
let tags: Array<string> = [];
for (const image of this.inputs.images) {
const imageLc = image.toLowerCase();
tags.push(`${imageLc}:${this.version.main}`);
tags.push(`${imageLc}:${this.inputs.tagPrefix}${this.version.main}${this.inputs.tagSuffix}`);
for (const partial of this.version.partial) {
tags.push(`${imageLc}:${partial}`);
tags.push(`${imageLc}:${this.inputs.tagPrefix}${partial}${this.inputs.tagSuffix}`);
}
if (this.version.latest) {
tags.push(`${imageLc}:latest`);
tags.push(`${imageLc}:${this.inputs.tagPrefix}latest${this.inputs.tagSuffix}`);
}
if (this.context.sha && this.inputs.tagSha) {
tags.push(`${imageLc}:sha-${this.context.sha.substr(0, 7)}`);
tags.push(`${imageLc}:${this.inputs.tagPrefix}sha-${this.context.sha.substr(0, 7)}${this.inputs.tagSuffix}`);
}
}
return tags;