Skip to content

Commit bd33ca5

Browse files
authored
Make 'workflow' input optional (dawidd6#178)
1 parent 13cbc32 commit bd33ca5

3 files changed

Lines changed: 19 additions & 5 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ Let's suppose you have a workflow with a job in it that at the end uploads an ar
1818
# Required, if artifact is from a different repo
1919
# Required, if repo is private a Personal Access Token with `repo` scope is needed
2020
github_token: ${{secrets.GITHUB_TOKEN}}
21-
# Required, workflow file name or ID
21+
# Optional, workflow file name or ID
22+
# If not specified, will be inferred from run_id (if run_id is specified), or will be the current workflow
2223
workflow: workflow_name.yml
2324
# Optional, the status or conclusion of a completed workflow to search for
2425
# Can be one of a workflow conclusion:

action.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ inputs:
1010
required: false
1111
default: ${{github.token}}
1212
workflow:
13-
description: Workflow name
14-
required: true
13+
description: |
14+
Workflow name.
15+
16+
If not specified, will be inferred from run_id (if run_id is specified), or will be the current workflow
17+
required: false
1518
workflow_conclusion:
1619
description: |
1720
Wanted status or conclusion to search for in recent runs

main.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ function inform(key, val) {
1212
async function main() {
1313
try {
1414
const token = core.getInput("github_token", { required: true })
15-
const workflow = core.getInput("workflow", { required: true })
1615
const [owner, repo] = core.getInput("repo", { required: true }).split("/")
1716
const path = core.getInput("path", { required: true })
1817
const name = core.getInput("name")
1918
const skipUnpack = core.getInput("skip_unpack")
19+
let workflow = core.getInput("workflow")
2020
let workflowConclusion = core.getInput("workflow_conclusion")
2121
let pr = core.getInput("pr")
2222
let commit = core.getInput("commit")
@@ -30,10 +30,20 @@ async function main() {
3030

3131
const client = github.getOctokit(token)
3232

33+
core.info(`==> Repository: ${owner}/${repo}`)
3334
core.info(`==> Artifact name: ${name}`)
3435
core.info(`==> Local path: ${path}`)
36+
37+
if (!workflow) {
38+
const run = await client.rest.actions.getWorkflowRun({
39+
owner: owner,
40+
repo: repo,
41+
run_id: runID || github.context.runId,
42+
});
43+
workflow = run.data.workflow_id
44+
}
45+
3546
core.info(`==> Workflow name: ${workflow}`)
36-
core.info(`==> Repository: ${owner}/${repo}`)
3747
core.info(`==> Workflow conclusion: ${workflowConclusion}`)
3848

3949
const uniqueInputSets = [

0 commit comments

Comments
 (0)