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

Add suffix input and support empty strings in prefix/suffix #333

Merged
merged 6 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,27 @@ The GitHub action's only output is named `tags` and is a JSON formatted list. Se

## Optional input parameters

- `prefix`: A string that each returned tag should be prefixed with, for example to tag a Docker container set this to `user/repository:`. This is allowed to be a comma/whitespace separated list to tag multiple images, for example `user/repository:,quay.io/user/repository:`.
- `prefix`: One or more whitespace or comma delimited prefixes for returned tags.

As an example, prefix could be set to `ghcr.io/a/b: quay.io/a/b:` to provide
image names with tags for two separate repositories.

The string `""` can be used to represent an empty string, and all combinations
of prefixes and suffixes are used.

- `suffix`: One or more whitespace or comma delimited suffixes for returned
tags.

As an example, suffix could be set to `"" -debian` to provide a default image
variant without suffix next to an image variant referred to with a -debian
suffix.

The string `""` can be used to represent an empty string, and all combinations
of prefixes and suffixes are used.

- `defaultTag`: If the tag output would be empty return this tag instead.
This can be useful for running a workflow in pull requests where no suitable git references are present.
`prefix` is _not_ automatically added.
`prefix` or `suffix` are _not_ automatically added.
- `branchRegex`: If a branch name does not match this regex return `defaultTag` or empty instead.

## Output parameters
Expand Down
93 changes: 92 additions & 1 deletion __tests__/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ test("Multiple prefix", async () => {
repo: "repo",
ref: "refs/tags/0.0.1",
// test use of different whitespace separators and a combination of both
prefix: "prefix1:\tprefix2:\n, prefix3:",
prefix: "prefix1:\tprefix2:\n ,prefix3:",
});
expect(tags).toEqual([
"prefix1:0.0.1",
Expand All @@ -309,6 +309,97 @@ test("Multiple prefix", async () => {
]);
});

test("Single suffix", async () => {
tagInterceptor.reply(200, [
{
name: "0.0.1",
},
]);
const tags = await calculateTags({
token: "TOKEN",
owner: "owner",
repo: "repo",
ref: "refs/tags/0.0.1",
suffix: "-suffix",
});
expect(tags).toEqual([
"0.0.1-suffix",
"0.0-suffix",
"0-suffix",
"latest-suffix",
]);
});

test("Multiple prefix and suffix", async () => {
tagInterceptor.reply(200, [
{
name: "0.0.1",
},
]);
const tags = await calculateTags({
token: "TOKEN",
owner: "owner",
repo: "repo",
ref: "refs/tags/0.0.1",
// test use of different whitespace separators and a combination of both
prefix: "prefix1:,prefix2:",
suffix: "-a -b",
});
expect(tags).toEqual([
"prefix1:0.0.1-a",
"prefix1:0.0.1-b",
"prefix2:0.0.1-a",
"prefix2:0.0.1-b",
"prefix1:0.0-a",
"prefix1:0.0-b",
"prefix2:0.0-a",
"prefix2:0.0-b",
"prefix1:0-a",
"prefix1:0-b",
"prefix2:0-a",
"prefix2:0-b",
"prefix1:latest-a",
"prefix1:latest-b",
"prefix2:latest-a",
"prefix2:latest-b",
]);
});

test("Multiple prefix and suffix with empty string", async () => {
tagInterceptor.reply(200, [
{
name: "0.0.1",
},
]);
const tags = await calculateTags({
token: "TOKEN",
owner: "owner",
repo: "repo",
ref: "refs/tags/0.0.1",
// test use of ""
prefix: '"",prefix2:',
suffix: '"",-b',
});
expect(tags).toEqual([
"0.0.1",
"0.0.1-b",
"prefix2:0.0.1",
"prefix2:0.0.1-b",
"0.0",
"0.0-b",
"prefix2:0.0",
"prefix2:0.0-b",
"0",
"0-b",
"prefix2:0",
"prefix2:0-b",
"latest",
"latest-b",
"prefix2:latest",
"prefix2:latest-b",
]);
});

test("Branch", async () => {
const tags = await calculateTags({
token: "TOKEN",
Expand Down
22 changes: 20 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,32 @@ inputs:
prefix:
required: false
description: |-
A string that each returned tag should be prefixed with, for example to tag a Docker container set this to `user/repository:`.
One or more whitespace or comma delimited prefixes for returned tags.

As an example, prefix could be set to `ghcr.io/a/b: quay.io/a/b:` to
provide image names with tags for two separate repositories.

The string `""` can be used to represent an empty string, and
all combinations of prefixes and suffixes are used.
default: ""
suffix:
required: false
description: |-
One or more whitespace or comma delimited suffixes for returned tags.

As an example, suffix could be set to `"" -debian` to provide
a default image variant without suffix next to an image variant referred
to with a -debian suffix.

The string `""` can be used to represent an empty string, and
all combinations of prefixes and suffixes are used.
default: ""
defaultTag:
required: false
description: |-
If the tag output would be empty return this tag instead.
This can be useful for running a workflow in pull requests where no suitable git references are present.
`prefix` is _not_ automatically added.
`prefix` or `suffix` are _not_ automatically added.
default: ""
branchRegex:
required: false
Expand Down
63 changes: 43 additions & 20 deletions dist/index.js

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

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

Loading
Loading