-
Notifications
You must be signed in to change notification settings - Fork 201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add additional input to define how to fail the action #187
Changes from all commits
f704403
fc70a0d
3683e2b
9018e81
387cb75
757ba7c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -63,11 +63,17 @@ inputs: | |||||
dry_run: | ||||||
description: Check the existence of artifact(s) without downloading. | ||||||
required: false | ||||||
if_no_artifact_found: | ||||||
required: false | ||||||
description: choose how to exit the action if no artifact is found | ||||||
default: "fail" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
outputs: | ||||||
error_message: | ||||||
description: The error message, if an error occurs | ||||||
dry_run: | ||||||
description: Boolean output which is true if the dry run was successful and false otherwise. | ||||||
found_artifact: | ||||||
description: Boolean output which is true if the artifact was found and false otherwise. | ||||||
dawidd6 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
runs: | ||||||
using: node16 | ||||||
main: main.js |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -16,6 +16,7 @@ async function main() { | |||||||
const path = core.getInput("path", { required: true }) | ||||||||
const name = core.getInput("name") | ||||||||
const skipUnpack = core.getInput("skip_unpack") | ||||||||
const ifNoArtifactFound = core.getInput("if_no_artifact_found") | ||||||||
let workflow = core.getInput("workflow") | ||||||||
let workflowConclusion = core.getInput("workflow_conclusion") | ||||||||
let pr = core.getInput("pr") | ||||||||
|
@@ -39,7 +40,7 @@ async function main() { | |||||||
owner: owner, | ||||||||
repo: repo, | ||||||||
run_id: runID || github.context.runId, | ||||||||
}); | ||||||||
}) | ||||||||
workflow = run.data.workflow_id | ||||||||
} | ||||||||
|
||||||||
|
@@ -140,7 +141,8 @@ async function main() { | |||||||
} | ||||||||
|
||||||||
if (!runID) { | ||||||||
throw new Error("no matching workflow run found with any artifacts?") | ||||||||
setExitMessage(ifNoArtifactFound, "no matching workflow run found with any artifacts?") | ||||||||
return | ||||||||
Comment on lines
+144
to
+145
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Could we do it like this? |
||||||||
} | ||||||||
|
||||||||
let artifacts = await client.paginate(client.rest.actions.listWorkflowRunArtifacts, { | ||||||||
|
@@ -167,11 +169,13 @@ async function main() { | |||||||
if (dryRun) { | ||||||||
if (artifacts.length == 0) { | ||||||||
core.setOutput("dry_run", false) | ||||||||
core.setOutput("found_artifact", false) | ||||||||
return | ||||||||
} else { | ||||||||
core.setOutput("dry_run", true) | ||||||||
core.setOutput("found_artifact", true) | ||||||||
core.info('==> (found) Artifacts') | ||||||||
for (const artifact of artifacts){ | ||||||||
for (const artifact of artifacts) { | ||||||||
const size = filesize(artifact.size_in_bytes, { base: 10 }) | ||||||||
core.info(`\t==> Artifact:`) | ||||||||
core.info(`\t==> ID: ${artifact.id}`) | ||||||||
|
@@ -183,10 +187,13 @@ async function main() { | |||||||
} | ||||||||
|
||||||||
if (artifacts.length == 0) { | ||||||||
throw new Error("no artifacts found") | ||||||||
setExitMessage(ifNoArtifactFound, "no artifacts found") | ||||||||
return | ||||||||
} | ||||||||
|
||||||||
core.setOutput("found_artifact", true) | ||||||||
for (const artifact of artifacts) { | ||||||||
|
||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
core.info(`==> Artifact: ${artifact.id}`) | ||||||||
|
||||||||
const size = filesize(artifact.size_in_bytes, { base: 10 }) | ||||||||
|
@@ -224,9 +231,26 @@ async function main() { | |||||||
core.endGroup() | ||||||||
} | ||||||||
} catch (error) { | ||||||||
core.setOutput("found_artifact", false) | ||||||||
core.setOutput("error_message", error.message) | ||||||||
core.setFailed(error.message) | ||||||||
} | ||||||||
|
||||||||
function setExitMessage(ifNoArtifactFound, message) { | ||||||||
core.setOutput("found_artifact", false) | ||||||||
switch (ifNoArtifactFound) { | ||||||||
case "fail": | ||||||||
core.setFailed(message) | ||||||||
break | ||||||||
case "warn": | ||||||||
core.warning(message) | ||||||||
break | ||||||||
case "ignore": | ||||||||
default: | ||||||||
core.info(message) | ||||||||
break | ||||||||
} | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😄