Skip to content
Open
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
19 changes: 10 additions & 9 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,17 @@ exports.getBackoffOptions = exports.getConfig = void 0;
const core = __importStar(__nccwpck_require__(2186));
const action_types_1 = __nccwpck_require__(313);
function getNumberFromValue(value) {
try {
const num = parseFloat(value);
if (isNaN(num)) {
throw new Error(`${value}: Parsed value is NaN`);
}
return num;
}
catch (_a) {
const num = parseFloat(value);
return isNaN(num) ? undefined : num;
}
function getWorkflowIdFromValue(value) {
// Only treat as a workflow ID if the entire string is a positive integer
// This prevents filenames like "1-release.yaml" from being parsed as workflow ID 1
if (!/^\d+$/.test(value)) {
return undefined;
}
const num = parseInt(value, 10);
return isNaN(num) ? undefined : num;
}
function getWorkflowInputs(dispatchMethod) {
const workflowInputs = core.getInput('workflow-inputs');
Expand Down Expand Up @@ -182,7 +183,7 @@ The 'workflow' input is not supported for the repository_dispatch method and mus
throw error;
}
if (dispatchMethod === action_types_1.DispatchMethod.WorkflowDispatch) {
return getNumberFromValue(workflow) || workflow;
return getWorkflowIdFromValue(workflow) || workflow;
}
return undefined;
}
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dispatch-workflow",
"version": "2.0.1",
"version": "2.0.2",
"private": true,
"description": "A GitHub action to dispatch a remote GitHub workflow and optionally retrieve its information",
"main": "lib/index.js",
Expand Down
7 changes: 7 additions & 0 deletions src/action/action.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ describe('Action', () => {

expect(config.workflow).toStrictEqual(123456)
})

test('Should treat workflow filename starting with a number as a string, not a workflow ID', () => {
mockGitHubConfig.workflow = '1-release.yaml'
const config: ActionConfig = getConfig()

expect(config.workflow).toStrictEqual('1-release.yaml')
})
})

describe('repositoryDispatch', () => {
Expand Down
19 changes: 11 additions & 8 deletions src/action/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@ import {
import {BackoffOptions} from 'exponential-backoff'

function getNumberFromValue(value: string): number | undefined {
try {
const num = parseFloat(value)
if (isNaN(num)) {
throw new Error(`${value}: Parsed value is NaN`)
}
return num
} catch {
const num = parseFloat(value)
return isNaN(num) ? undefined : num
}

function getWorkflowIdFromValue(value: string): number | undefined {
// Only treat as a workflow ID if the entire string is a positive integer
// This prevents filenames like "1-release.yaml" from being parsed as workflow ID 1
if (!/^\d+$/.test(value)) {
return undefined
}
const num = parseInt(value, 10)
return isNaN(num) ? undefined : num
}

function getWorkflowInputs(
Expand Down Expand Up @@ -134,7 +137,7 @@ The 'workflow' input is not supported for the repository_dispatch method and mus
}

if (dispatchMethod === DispatchMethod.WorkflowDispatch) {
return getNumberFromValue(workflow) || workflow
return getWorkflowIdFromValue(workflow) || workflow
}
return undefined
}
Expand Down
Loading