mirror of
https://github.com/actions/download-artifact.git
synced 2025-07-27 08:58:28 +02:00
Add if-not-found
parameter
This commit is contained in:
parent
0706fbf5b9
commit
61eb988d37
6 changed files with 222 additions and 23 deletions
58
dist/index.js
vendored
58
dist/index.js
vendored
|
@ -120958,7 +120958,7 @@ utils.walkdir = function(dirpath, base, callback) {
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.Outputs = exports.Inputs = void 0;
|
||||
exports.NotFoundOptions = exports.Outputs = exports.Inputs = void 0;
|
||||
var Inputs;
|
||||
(function (Inputs) {
|
||||
Inputs["Name"] = "name";
|
||||
|
@ -120966,11 +120966,27 @@ var Inputs;
|
|||
Inputs["GitHubToken"] = "github-token";
|
||||
Inputs["Repository"] = "repository";
|
||||
Inputs["RunID"] = "run-id";
|
||||
Inputs["IfNotFound"] = "if-not-found";
|
||||
})(Inputs = exports.Inputs || (exports.Inputs = {}));
|
||||
var Outputs;
|
||||
(function (Outputs) {
|
||||
Outputs["DownloadPath"] = "download-path";
|
||||
})(Outputs = exports.Outputs || (exports.Outputs = {}));
|
||||
var NotFoundOptions;
|
||||
(function (NotFoundOptions) {
|
||||
/**
|
||||
* Default. Output a warning but do not fail the action
|
||||
*/
|
||||
NotFoundOptions["warn"] = "warn";
|
||||
/**
|
||||
* Fail the action with an error message
|
||||
*/
|
||||
NotFoundOptions["error"] = "error";
|
||||
/**
|
||||
* Do not output any warnings or errors, the action does not fail
|
||||
*/
|
||||
NotFoundOptions["ignore"] = "ignore";
|
||||
})(NotFoundOptions = exports.NotFoundOptions || (exports.NotFoundOptions = {}));
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
@ -121024,6 +121040,33 @@ exports.chunk = (arr, n) => arr.reduce((acc, cur, i) => {
|
|||
acc[index] = [...(acc[index] || []), cur];
|
||||
return acc;
|
||||
}, []);
|
||||
function checkIfNotFoundOption(if_not_found, message) {
|
||||
switch (if_not_found) {
|
||||
case constants_1.NotFoundOptions.warn: {
|
||||
core.warning(message);
|
||||
break;
|
||||
}
|
||||
case constants_1.NotFoundOptions.error: {
|
||||
core.setFailed(message);
|
||||
break;
|
||||
}
|
||||
case constants_1.NotFoundOptions.ignore: {
|
||||
core.info(message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
function getArtifact(name, if_not_found, options) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
try {
|
||||
return yield artifact_1.default.getArtifact(name, options);
|
||||
}
|
||||
catch (err) {
|
||||
const message = `Artifact '${name}' not found`;
|
||||
checkIfNotFoundOption(if_not_found, message);
|
||||
}
|
||||
});
|
||||
}
|
||||
function run() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const inputs = {
|
||||
|
@ -121031,6 +121074,7 @@ function run() {
|
|||
path: core.getInput(constants_1.Inputs.Path, { required: false }),
|
||||
token: core.getInput(constants_1.Inputs.GitHubToken, { required: false }),
|
||||
repository: core.getInput(constants_1.Inputs.Repository, { required: false }),
|
||||
if_not_found: core.getInput(constants_1.Inputs.IfNotFound, { required: false }),
|
||||
runID: parseInt(core.getInput(constants_1.Inputs.RunID, { required: false }))
|
||||
};
|
||||
if (!inputs.path) {
|
||||
|
@ -121058,18 +121102,18 @@ function run() {
|
|||
let artifacts = [];
|
||||
if (isSingleArtifactDownload) {
|
||||
core.info(`Downloading single artifact`);
|
||||
const { artifact: targetArtifact } = yield artifact_1.default.getArtifact(inputs.name, options);
|
||||
if (!targetArtifact) {
|
||||
throw new Error(`Artifact '${inputs.name}' not found`);
|
||||
const targetArtifact = yield getArtifact(inputs.name, inputs.if_not_found, options);
|
||||
if (targetArtifact) {
|
||||
core.debug(`Found named artifact '${inputs.name}' (ID: ${targetArtifact.artifact.id}, Size: ${targetArtifact.artifact.size})`);
|
||||
artifacts = [targetArtifact.artifact];
|
||||
}
|
||||
core.debug(`Found named artifact '${inputs.name}' (ID: ${targetArtifact.id}, Size: ${targetArtifact.size})`);
|
||||
artifacts = [targetArtifact];
|
||||
}
|
||||
else {
|
||||
core.info(`No input name specified, downloading all artifacts. Extra directory with the artifact name will be created for each download`);
|
||||
const listArtifactResponse = yield artifact_1.default.listArtifacts(Object.assign({ latest: true }, options));
|
||||
if (listArtifactResponse.artifacts.length === 0) {
|
||||
throw new Error(`No artifacts found for run '${inputs.runID}' in '${inputs.repository}'`);
|
||||
const message = `No artifacts found for run '${inputs.runID}' in '${inputs.repository}'`;
|
||||
checkIfNotFoundOption(inputs.if_not_found, message);
|
||||
}
|
||||
core.debug(`Found ${listArtifactResponse.artifacts.length} artifacts`);
|
||||
artifacts = listArtifactResponse.artifacts;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue