diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 47cc4da..200b143 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -77,6 +77,14 @@ jobs: name: 'Artifact-A' path: ~/some/path/with/a/tilde + # Test ignoring error if artifact is not found + - name: Download artifact doesn't exist + uses: ./ + with: + name: 'Artifact-not-exist' + path: path/to/artifact-not-exist + if-no-artifact: 'ignore' + - name: Verify successful download run: | $file1 = "some/new/path/file-A.txt" diff --git a/action.yml b/action.yml index 8011381..50e3cd2 100644 --- a/action.yml +++ b/action.yml @@ -8,6 +8,10 @@ inputs: path: description: 'Destination path' required: false + if-no-artifact: + description: 'How to exit action if no artifact is found. Can be fail, warn or ignore' + default: 'fail' + required: false outputs: download-path: description: 'Path of artifact download' diff --git a/dist/index.js b/dist/index.js index 80b6280..7c4dad3 100644 --- a/dist/index.js +++ b/dist/index.js @@ -9498,6 +9498,7 @@ var Inputs; (function (Inputs) { Inputs["Name"] = "name"; Inputs["Path"] = "path"; + Inputs["IfNoArtifact"] = "if-no-artifact"; })(Inputs = exports.Inputs || (exports.Inputs = {})); var Outputs; (function (Outputs) { @@ -9536,9 +9537,12 @@ const path_1 = __nccwpck_require__(1017); const constants_1 = __nccwpck_require__(9042); function run() { return __awaiter(this, void 0, void 0, function* () { + let ifNoArtifact = ''; try { const name = core.getInput(constants_1.Inputs.Name, { required: false }); const path = core.getInput(constants_1.Inputs.Path, { required: false }); + ifNoArtifact = + core.getInput(constants_1.Inputs.IfNoArtifact, { required: false }) || 'fail'; let resolvedPath; // resolve tilde expansions, path.replace only replaces the first occurrence of a pattern if (path.startsWith(`~`)) { @@ -9574,7 +9578,18 @@ function run() { core.info('Artifact download has finished successfully'); } catch (err) { - core.setFailed(err.message); + const { message } = err; + switch (ifNoArtifact) { + case 'warn': + core.warning(message); + break; + case 'ignore': + core.info(message); + break; + case 'fail': + default: + core.setFailed(message); + } } }); } diff --git a/src/constants.ts b/src/constants.ts index 49d800a..e6d7567 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,6 +1,7 @@ export enum Inputs { Name = 'name', - Path = 'path' + Path = 'path', + IfNoArtifact = 'if-no-artifact' } export enum Outputs { DownloadPath = 'download-path' diff --git a/src/download-artifact.ts b/src/download-artifact.ts index b32a7be..76612c1 100644 --- a/src/download-artifact.ts +++ b/src/download-artifact.ts @@ -5,9 +5,12 @@ import {resolve} from 'path' import {Inputs, Outputs} from './constants' async function run(): Promise { + let ifNoArtifact = '' try { const name = core.getInput(Inputs.Name, {required: false}) const path = core.getInput(Inputs.Path, {required: false}) + ifNoArtifact = + core.getInput(Inputs.IfNoArtifact, {required: false}) || 'fail' let resolvedPath // resolve tilde expansions, path.replace only replaces the first occurrence of a pattern @@ -54,7 +57,18 @@ async function run(): Promise { core.setOutput(Outputs.DownloadPath, resolvedPath) core.info('Artifact download has finished successfully') } catch (err) { - core.setFailed(err.message) + const {message} = err as Error + switch (ifNoArtifact) { + case 'warn': + core.warning(message) + break + case 'ignore': + core.info(message) + break + case 'fail': + default: + core.setFailed(message) + } } }