Skip to content
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
10 changes: 10 additions & 0 deletions src/action.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ describe("Action", () => {
expect(config.workflow).toStrictEqual(123456);
});

it.each(["01-build.yml", "2024-release.yml", "0x1F", "12e3"])(
"should keep a workflow filename starting with digits as a string: %s",
(workflow) => {
mockEnvConfig.workflow = workflow;
const config: ActionConfig = getConfig();

expect(config.workflow).toStrictEqual(workflow);
},
);

it("should handle no inputs being provided", () => {
mockEnvConfig.workflow_inputs = "";
const config: ActionConfig = getConfig();
Expand Down
29 changes: 3 additions & 26 deletions src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,6 @@ export function getConfig(): ActionConfig {
};
}

function getNumberFromValue(value: string): number | undefined {
if (value === "") {
return undefined;
}

try {
const num = parseInt(value);

if (isNaN(num)) {
throw new Error("Parsed value is NaN");
}

return num;
} catch {
throw new Error(`Unable to parse value: ${value}`);
}
}

function getWorkflowInputs(
workflowInputs: string,
): ActionWorkflowInputs | undefined {
Expand Down Expand Up @@ -104,12 +86,7 @@ function getWorkflowInputs(
}

function tryGetWorkflowAsNumber(workflowInput: string): string | number {
try {
// We can assume that the string is defined and not empty at this point.
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return getNumberFromValue(workflowInput)!;
} catch {
// Assume using a workflow name instead of an ID.
return workflowInput;
}
// Only an all-digit input is an ID. parseInt would accept a numeric prefix
// and turn a filename such as "01-build.yml" into the ID 1.
return /^\d+$/.test(workflowInput) ? Number(workflowInput) : workflowInput;
}
Loading