mirror of
https://github.com/actions/download-artifact.git
synced 2024-11-09 23:22:44 +00:00
Add warn-on-failure
Some users might not want their workflow jobs to die just because an artifact isn't available...
This commit is contained in:
parent
c3c8e4145a
commit
bd6ef4177a
6 changed files with 77 additions and 9 deletions
23
.github/workflows/test.yml
vendored
23
.github/workflows/test.yml
vendored
|
@ -118,6 +118,29 @@ jobs:
|
|||
path: single/directory
|
||||
merge-multiple: true
|
||||
|
||||
- name: Request missing Artifact
|
||||
id: request-missing-artifact
|
||||
uses: ./
|
||||
with:
|
||||
name: nonexistent
|
||||
warn-on-failure: true
|
||||
|
||||
- name: Check missing warning
|
||||
env:
|
||||
output: ${{ steps.request-missing-artifact.outputs.failure }}
|
||||
if: ${{ !contains(env.output, 'Unable to download artifact(s):') }}
|
||||
run: |
|
||||
false
|
||||
shell: bash
|
||||
|
||||
- name: Log missing warning
|
||||
env:
|
||||
output: ${{ steps.request-missing-artifact.outputs.failure }}
|
||||
run_os: ${{ matrix.runs-on }}
|
||||
run: |
|
||||
echo "::notice title=This message is expected::[$run_os] $output"
|
||||
shell: bash
|
||||
|
||||
- name: Verify successful download
|
||||
run: |
|
||||
$fileA = "single/directory/file-A.txt"
|
||||
|
|
|
@ -82,6 +82,10 @@ For assistance with breaking changes, see [MIGRATION.md](docs/MIGRATION.md).
|
|||
# If github-token is specified, this is the run that artifacts will be downloaded from.
|
||||
# Optional. Default is ${{ github.run_id }}
|
||||
run-id:
|
||||
|
||||
# Map failure result to an output instead of failing the job.
|
||||
# Optional. Default is `false`
|
||||
warn-on-failure:
|
||||
```
|
||||
|
||||
### Outputs
|
||||
|
@ -89,6 +93,7 @@ For assistance with breaking changes, see [MIGRATION.md](docs/MIGRATION.md).
|
|||
| Name | Description | Example |
|
||||
| - | - | - |
|
||||
| `download-path` | Absolute path where the artifact(s) were downloaded | `/tmp/my/download/path` |
|
||||
| `failure` | Failure message (if using `warn-on-failure`) | `Unable to download artifact(s): ...` |
|
||||
|
||||
## Examples
|
||||
|
||||
|
|
|
@ -32,9 +32,15 @@ inputs:
|
|||
If github-token is specified, this is the run that artifacts will be downloaded from.'
|
||||
required: false
|
||||
default: ${{ github.run_id }}
|
||||
warn-on-failure:
|
||||
description: 'Map failure result to an output instead of failing the job'
|
||||
required: false
|
||||
default: false
|
||||
outputs:
|
||||
download-path:
|
||||
description: 'Path of artifact download'
|
||||
failure:
|
||||
description: 'Failure message (if warn-on-failure is set)'
|
||||
runs:
|
||||
using: 'node20'
|
||||
main: 'dist/index.js'
|
||||
|
|
21
dist/index.js
vendored
21
dist/index.js
vendored
|
@ -121005,6 +121005,7 @@ var Inputs;
|
|||
Inputs["RunID"] = "run-id";
|
||||
Inputs["Pattern"] = "pattern";
|
||||
Inputs["MergeMultiple"] = "merge-multiple";
|
||||
Inputs["WarnOnFailure"] = "warn-on-failure";
|
||||
})(Inputs || (exports.Inputs = Inputs = {}));
|
||||
var Outputs;
|
||||
(function (Outputs) {
|
||||
|
@ -121069,7 +121070,7 @@ const chunk = (arr, n) => arr.reduce((acc, cur, i) => {
|
|||
return acc;
|
||||
}, []);
|
||||
exports.chunk = chunk;
|
||||
function run() {
|
||||
function run(flags) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const inputs = {
|
||||
name: core.getInput(constants_1.Inputs.Name, { required: false }),
|
||||
|
@ -121078,8 +121079,12 @@ function run() {
|
|||
repository: core.getInput(constants_1.Inputs.Repository, { required: false }),
|
||||
runID: parseInt(core.getInput(constants_1.Inputs.RunID, { required: false })),
|
||||
pattern: core.getInput(constants_1.Inputs.Pattern, { required: false }),
|
||||
mergeMultiple: core.getBooleanInput(constants_1.Inputs.MergeMultiple, { required: false })
|
||||
mergeMultiple: core.getBooleanInput(constants_1.Inputs.MergeMultiple, {
|
||||
required: false
|
||||
}),
|
||||
warnOnFailure: core.getBooleanInput(constants_1.Inputs.WarnOnFailure, { required: false })
|
||||
};
|
||||
flags.warnOnFailure = inputs.warnOnFailure;
|
||||
if (!inputs.path) {
|
||||
inputs.path = process.env['GITHUB_WORKSPACE'] || process.cwd();
|
||||
}
|
||||
|
@ -121147,7 +121152,17 @@ function run() {
|
|||
core.info('Download artifact has finished successfully');
|
||||
});
|
||||
}
|
||||
run().catch(err => core.setFailed(`Unable to download artifact(s): ${err.message}`));
|
||||
{
|
||||
const flags = { warnOnFailure: false };
|
||||
run(flags).catch(err => {
|
||||
if (flags.warnOnFailure) {
|
||||
core.setOutput('failure', `Unable to download artifact(s): ${err.message}`);
|
||||
}
|
||||
else {
|
||||
core.setFailed(`Unable to download artifact(s): ${err.message}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
|
|
@ -5,7 +5,8 @@ export enum Inputs {
|
|||
Repository = 'repository',
|
||||
RunID = 'run-id',
|
||||
Pattern = 'pattern',
|
||||
MergeMultiple = 'merge-multiple'
|
||||
MergeMultiple = 'merge-multiple',
|
||||
WarnOnFailure = 'warn-on-failure'
|
||||
}
|
||||
|
||||
export enum Outputs {
|
||||
|
|
|
@ -8,6 +8,10 @@ import {Inputs, Outputs} from './constants'
|
|||
|
||||
const PARALLEL_DOWNLOADS = 5
|
||||
|
||||
interface Flags {
|
||||
warnOnFailure: boolean
|
||||
}
|
||||
|
||||
export const chunk = <T>(arr: T[], n: number): T[][] =>
|
||||
arr.reduce((acc, cur, i) => {
|
||||
const index = Math.floor(i / n)
|
||||
|
@ -15,7 +19,7 @@ export const chunk = <T>(arr: T[], n: number): T[][] =>
|
|||
return acc
|
||||
}, [] as T[][])
|
||||
|
||||
async function run(): Promise<void> {
|
||||
async function run(flags: Flags): Promise<void> {
|
||||
const inputs = {
|
||||
name: core.getInput(Inputs.Name, {required: false}),
|
||||
path: core.getInput(Inputs.Path, {required: false}),
|
||||
|
@ -23,8 +27,12 @@ async function run(): Promise<void> {
|
|||
repository: core.getInput(Inputs.Repository, {required: false}),
|
||||
runID: parseInt(core.getInput(Inputs.RunID, {required: false})),
|
||||
pattern: core.getInput(Inputs.Pattern, {required: false}),
|
||||
mergeMultiple: core.getBooleanInput(Inputs.MergeMultiple, {required: false})
|
||||
mergeMultiple: core.getBooleanInput(Inputs.MergeMultiple, {
|
||||
required: false
|
||||
}),
|
||||
warnOnFailure: core.getBooleanInput(Inputs.WarnOnFailure, {required: false})
|
||||
}
|
||||
flags.warnOnFailure = inputs.warnOnFailure
|
||||
|
||||
if (!inputs.path) {
|
||||
inputs.path = process.env['GITHUB_WORKSPACE'] || process.cwd()
|
||||
|
@ -131,6 +139,16 @@ async function run(): Promise<void> {
|
|||
core.info('Download artifact has finished successfully')
|
||||
}
|
||||
|
||||
run().catch(err =>
|
||||
core.setFailed(`Unable to download artifact(s): ${err.message}`)
|
||||
)
|
||||
{
|
||||
const flags = {warnOnFailure: false}
|
||||
run(flags).catch(err => {
|
||||
if (flags.warnOnFailure) {
|
||||
core.setOutput(
|
||||
'failure',
|
||||
`Unable to download artifact(s): ${err.message}`
|
||||
)
|
||||
} else {
|
||||
core.setFailed(`Unable to download artifact(s): ${err.message}`)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue