diff --git a/README.md b/README.md index 2e52e0f..9ab9c4a 100644 --- a/README.md +++ b/README.md @@ -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`) | diff --git a/__tests__/meta.test.ts b/__tests__/meta.test.ts index 3dab864..6f741c6 100644 --- a/__tests__/meta.test.ts +++ b/__tests__/meta.test.ts @@ -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', { diff --git a/action.yml b/action.yml index 257170b..9cea342 100644 --- a/action.yml +++ b/action.yml @@ -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 diff --git a/dist/index.js b/dist/index.js index 8450185..65964ab 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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; diff --git a/src/context.ts b/src/context.ts index 3b55c16..6c7cb66 100644 --- a/src/context.ts +++ b/src/context.ts @@ -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`, diff --git a/src/meta.ts b/src/meta.ts index 592071d..b2fbda9 100644 --- a/src/meta.ts +++ b/src/meta.ts @@ -117,15 +117,15 @@ export class Meta { let tags: Array = []; 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;