Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add tag-suffix and tag-prefix options #47

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,23 @@ jobs:
ghcr.io/name/app
tag-sha: true

tag-prefix-suffix:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Docker meta
uses: ./
with:
images: |
${{ env.DOCKER_IMAGE }}
ghcr.io/name/app
tag-sha: true
tag-prefix: prefix-
tag-suffix: -suffix

tag-schedule:
runs-on: ubuntu-latest
strategy:
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`) |
Expand Down
145 changes: 145 additions & 0 deletions __tests__/meta.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
{
Expand Down Expand Up @@ -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',
{
Expand Down Expand Up @@ -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',
{
Expand Down Expand Up @@ -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',
{
Expand Down Expand Up @@ -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',
{
Expand Down
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export interface Inputs {
tagSchedule: string;
tagCustom: string[];
tagCustomOnly: boolean;
tagSuffix: string;
tagPrefix: string;
labelCustom: string[];
sepTags: string;
sepLabels: string;
Expand All @@ -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`,
Expand Down
8 changes: 4 additions & 4 deletions src/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down