Skip to content

Commit

Permalink
Revert breaking change to prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
consideRatio committed Feb 15, 2024
1 parent 5b0dd69 commit e314ed0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
4 changes: 3 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ inputs:
prefix:
required: false
description: |-
One or more newline deliminated prefixes for returned tags.
One or more whitespace or comma deliminated prefixes for returned tags.
Use of separators besides new lines is deprecated but for now still
supported.
All permutations of prefixes and suffixes are considered.
default: ""
Expand Down
31 changes: 22 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,14 @@ function checkAgainstRegex(name, regexAllowed) {
}

function expandPrefixSuffix(prefix, suffix, tag) {
// Adds all permutations of prefixes and suffixes to a tag, where suffix and
// prefix could be a single prefix or a comma/whitespace separated list.
let prefixes = [...new Set(prefix.split(/\n/))];
// Adds all permutations of prefixes and suffixes to a tag, where prefix could
// be a single prefix or a comma/whitespace separated list of prefixes, and
// suffix could be a single suffix or a new line separated list of suffixes.
let prefixes = [...new Set(prefix.split(/\s|,/).filter(Boolean))];
if (prefixes.length == 0) {
// the permutation logic below requires at least one element
prefixes.push("");
}
let suffixes = [...new Set(suffix.split(/\n/))];
return prefixes.flatMap((p) => suffixes.map((s) => `${p}${tag}${s}`));
}
Expand Down Expand Up @@ -181,19 +186,27 @@ async function run() {
const defaultTag = core.getInput("defaultTag");
const branchRegex = core.getInput("branchRegex");

function check_prefix_suffix(input_name, input_value) {
function check_prefix_suffix(input_name, input_value, just_warn) {
// Partial check that prefix and suffix inputs are OK
// Check if there is any whitespace characters besides new lines or
// commas.
const re = new RegExp(/^[^\s,]+$/g);
if (re.test(input_value.replace("\n", ""))) {
throw new Error(
`Input ${input_name} invalid, contains either comma or whitespace besides the new line separator`,
);
if (just_warn) {
core.warning(
"Input 'prefix' will soon require the use of new lines to separate prefixes, trim away your other whitespace and commas.",
);
} else {
throw new Error(
`Input ${input_name} invalid, contains either comma or whitespace besides the new line separator`,
);
}
}
}
check_prefix_suffix("prefix", prefix);
check_prefix_suffix("suffix", suffix);
// prefix and suffix has different whitespace separators, we are deprecating
// prefix's separators besides new lines
check_prefix_suffix("prefix", suffix, true);
check_prefix_suffix("suffix", suffix, false);

core.debug(JSON.stringify(github.context));
const allTags = await calculateTags({
Expand Down

0 comments on commit e314ed0

Please sign in to comment.