Skip to content

Commit b276cda

Browse files
committed
changing id handling
1 parent 1be8b3c commit b276cda

File tree

3 files changed

+19
-31
lines changed

3 files changed

+19
-31
lines changed

.github/workflows/build-test.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ jobs:
3232
uses: ./
3333
with:
3434
workflow: '1854247'
35-
use-workflow-id: 'true'
3635
token: ${{ secrets.PERSONAL_TOKEN }}
3736
inputs: '{"message": "Mango jam"}'
3837

action.yaml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,11 @@ description: 'Trigger and chain GitHub Actions workflows with workflow_dispatch
33

44
inputs:
55
workflow:
6-
description: 'Name of workflow to run'
6+
description: 'Name or ID of workflow to run'
77
required: true
88
token:
99
description: 'GitHub token with repo write access, can NOT use secrets.GITHUB_TOKEN, see readme'
1010
required: true
11-
use-workflow-id:
12-
description: 'When true the workflow input is treated as an id rather than name'
13-
required: false
14-
default: 'false'
1511
inputs:
1612
description: 'Inputs to pass to the workflow, must be a JSON string.'
1713
required: false

src/main.ts

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ async function run(): Promise<void> {
77
// Required inputs
88
const token = core.getInput('token')
99
const workflowReference = core.getInput('workflow')
10-
const workflowIdFlag = core.getInput('use-workflow-id') || 'false'
1110
// Optional inputs, with defaults
1211
const ref = core.getInput('ref') || github.context.ref
1312
const repo = core.getInput('repo') || `${github.context.repo.owner}/${github.context.repo.repo}`
@@ -22,33 +21,27 @@ async function run(): Promise<void> {
2221
// Get octokit client for making API calls
2322
const octokit = github.getOctokit(token)
2423

25-
let workflowId = ''
26-
if(workflowIdFlag !== 'true') {
27-
// List workflows via API
28-
const listResp = await octokit.request(`GET /repos/${repo}/actions/workflows`, {
29-
ref: ref,
30-
inputs: inputs
31-
})
32-
if(listResp.status != 200) throw new Error(`Got HTTP ${listResp.status} calling list workflows API 💩`)
33-
34-
// Debug response if ACTIONS_STEP_DEBUG is enabled
35-
core.debug(listResp.data)
36-
37-
// Locate workflow by name as we need it's id
38-
const foundWorkflow = listResp.data.workflows.find((wf: Record<string, string>) => {
39-
return wf['name'] === workflowReference
40-
})
41-
if(!foundWorkflow) throw new Error(`Unable to find workflow named '${workflowReference}' in ${repo} 😥`)
42-
43-
workflowId = foundWorkflow.id
44-
} else {
45-
workflowId = workflowReference
46-
}
24+
// List workflows via API
25+
const listResp = await octokit.request(`GET /repos/${repo}/actions/workflows`, {
26+
ref: ref,
27+
inputs: inputs
28+
})
29+
if(listResp.status != 200) throw new Error(`Got HTTP ${listResp.status} calling list workflows API 💩`)
30+
31+
// Debug response if ACTIONS_STEP_DEBUG is enabled
32+
core.debug(listResp.data)
33+
34+
// Locate workflow by name as we need it's id
35+
const foundWorkflow = listResp.data.workflows.find((wf: Record<string, string>) => {
36+
// Match on name or id
37+
return (wf['name'] === workflowReference || wf['id'] === workflowReference)
38+
})
39+
if(!foundWorkflow) throw new Error(`Unable to find workflow '${workflowReference}' in ${repo} 😥`)
4740

48-
console.log(`Workflow id is: ${workflowId}`)
41+
console.log(`Workflow id is: ${foundWorkflow.id}`)
4942

5043
// Call workflow_dispatch API
51-
const dispatchResp = await octokit.request(`POST /repos/${repo}/actions/workflows/${workflowId}/dispatches`, {
44+
const dispatchResp = await octokit.request(`POST /repos/${repo}/actions/workflows/${foundWorkflow.id}/dispatches`, {
5245
ref: ref,
5346
inputs: inputs
5447
})

0 commit comments

Comments
 (0)