mirror of
https://github.com/actions/upload-artifact.git
synced 2025-06-24 00:26:11 +02:00
feat: add upload one artifact per file
Signed-off-by: initdc <initd@outlook.com>
This commit is contained in:
parent
3cea537223
commit
35e561c49c
6 changed files with 365 additions and 48 deletions
129
dist/index.js
vendored
129
dist/index.js
vendored
|
@ -4733,12 +4733,16 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||
result["default"] = mod;
|
||||
return result;
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const core = __importStar(__webpack_require__(470));
|
||||
const artifact_1 = __webpack_require__(214);
|
||||
const search_1 = __webpack_require__(575);
|
||||
const input_helper_1 = __webpack_require__(583);
|
||||
const constants_1 = __webpack_require__(694);
|
||||
const path_1 = __importDefault(__webpack_require__(622));
|
||||
function run() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
try {
|
||||
|
@ -4775,12 +4779,68 @@ function run() {
|
|||
if (inputs.retentionDays) {
|
||||
options.retentionDays = inputs.retentionDays;
|
||||
}
|
||||
const uploadResponse = yield artifactClient.uploadArtifact(inputs.artifactName, searchResult.filesToUpload, searchResult.rootDirectory, options);
|
||||
if (uploadResponse.failedItems.length > 0) {
|
||||
core.setFailed(`An error was encountered when uploading ${uploadResponse.artifactName}. There were ${uploadResponse.failedItems.length} items that failed to upload.`);
|
||||
const artifactsName = inputs['artifactsName'] || 'artifacts';
|
||||
const artifactPerFile = inputs['artifactPerFile'] || false;
|
||||
if (!artifactPerFile) {
|
||||
const uploadResponse = yield artifactClient.uploadArtifact(artifactsName, searchResult.filesToUpload, searchResult.rootDirectory, options);
|
||||
if (uploadResponse.failedItems.length > 0) {
|
||||
core.setFailed(`An error was encountered when uploading ${uploadResponse.artifactName}. There were ${uploadResponse.failedItems.length} items that failed to upload.`);
|
||||
}
|
||||
else {
|
||||
core.info(`Artifact ${uploadResponse.artifactName} has been successfully uploaded!`);
|
||||
}
|
||||
}
|
||||
else {
|
||||
core.info(`Artifact ${uploadResponse.artifactName} has been successfully uploaded!`);
|
||||
const filesToUpload = searchResult.filesToUpload;
|
||||
const SuccessedItems = [];
|
||||
const FailedItems = [];
|
||||
const artifactNameRule = inputs['artifactNameRule'];
|
||||
for (let i = 0; i < filesToUpload.length; i++) {
|
||||
const file = filesToUpload[i];
|
||||
core.info(file);
|
||||
const pathObject = path_1.default.parse(file);
|
||||
let artifactName = artifactNameRule;
|
||||
for (const key of Object.keys(pathObject)) {
|
||||
const re = `$\{${key}}`;
|
||||
if (artifactNameRule.includes(re)) {
|
||||
const value = pathObject[key] || '';
|
||||
artifactName = artifactName.replace(re, value);
|
||||
}
|
||||
}
|
||||
if (artifactName.includes(path_1.default.sep)) {
|
||||
core.warning(`${artifactName} includes ${path_1.default.sep}`);
|
||||
artifactName = artifactName.split(path_1.default.sep).join('_');
|
||||
}
|
||||
if (artifactName.includes(':')) {
|
||||
core.warning(`${artifactName} includes :`);
|
||||
artifactName = artifactName.split(':').join('-');
|
||||
}
|
||||
core.info(artifactName);
|
||||
const artifactItemExist = SuccessedItems.includes(artifactName);
|
||||
if (artifactItemExist) {
|
||||
const oldArtifactName = artifactName;
|
||||
core.warning(`${artifactName} artifact alreay exist`);
|
||||
artifactName = `${i}__${artifactName}`;
|
||||
core.warning(`${oldArtifactName} => ${artifactName}`);
|
||||
}
|
||||
const uploadResponse = yield artifactClient.uploadArtifact(artifactName, [file], searchResult.rootDirectory, options);
|
||||
if (uploadResponse.failedItems.length > 0) {
|
||||
FailedItems.push(artifactName);
|
||||
}
|
||||
else {
|
||||
SuccessedItems.push(artifactName);
|
||||
}
|
||||
}
|
||||
if (FailedItems.length > 0) {
|
||||
let errMsg = `${FailedItems.length} artifacts failed to upload, they were:\n`;
|
||||
errMsg += FailedItems.join('\n');
|
||||
core.setFailed(errMsg);
|
||||
}
|
||||
if (SuccessedItems.length > 0) {
|
||||
let infoMsg = `${SuccessedItems.length} artifacts has been successfully uploaded! They were:\n`;
|
||||
infoMsg += SuccessedItems.join('\n');
|
||||
core.info(infoMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7174,26 +7234,59 @@ const constants_1 = __webpack_require__(694);
|
|||
* Helper to get all the inputs for the action
|
||||
*/
|
||||
function getInputs() {
|
||||
const name = core.getInput(constants_1.Inputs.Name);
|
||||
const TRUE_MAP = ['true', 'True', 'TRUE'];
|
||||
let artifactPerFile = false;
|
||||
const artifactPerFileStr = core.getInput(constants_1.Inputs.ArtifactPerFile);
|
||||
if (artifactPerFileStr) {
|
||||
artifactPerFile = TRUE_MAP.includes(artifactPerFileStr) ? true : false;
|
||||
}
|
||||
let name = '';
|
||||
let artifactNameRule = '';
|
||||
if (!artifactPerFile) {
|
||||
name = core.getInput(constants_1.Inputs.Name);
|
||||
}
|
||||
else {
|
||||
artifactNameRule = core.getInput(constants_1.Inputs.ArtifactNameRule) || '${base}';
|
||||
}
|
||||
const path = core.getInput(constants_1.Inputs.Path, { required: true });
|
||||
const ifNoFilesFound = core.getInput(constants_1.Inputs.IfNoFilesFound);
|
||||
const noFileBehavior = constants_1.NoFileOptions[ifNoFilesFound];
|
||||
if (!noFileBehavior) {
|
||||
core.setFailed(`Unrecognized ${constants_1.Inputs.IfNoFilesFound} input. Provided: ${ifNoFilesFound}. Available options: ${Object.keys(constants_1.NoFileOptions)}`);
|
||||
}
|
||||
const inputs = {
|
||||
artifactName: name,
|
||||
searchPath: path,
|
||||
ifNoFilesFound: noFileBehavior
|
||||
};
|
||||
const retentionDaysStr = core.getInput(constants_1.Inputs.RetentionDays);
|
||||
if (retentionDaysStr) {
|
||||
inputs.retentionDays = parseInt(retentionDaysStr);
|
||||
if (isNaN(inputs.retentionDays)) {
|
||||
core.setFailed('Invalid retention-days');
|
||||
const typedInputs = (artifactPerFile) => {
|
||||
const retentionDaysStr = core.getInput(constants_1.Inputs.RetentionDays);
|
||||
if (!artifactPerFile) {
|
||||
const inputs = {
|
||||
artifactsName: name,
|
||||
searchPath: path,
|
||||
ifNoFilesFound: noFileBehavior
|
||||
};
|
||||
if (retentionDaysStr) {
|
||||
inputs.retentionDays = parseInt(retentionDaysStr);
|
||||
if (isNaN(inputs.retentionDays)) {
|
||||
core.setFailed('Invalid retention-days');
|
||||
}
|
||||
}
|
||||
return inputs;
|
||||
}
|
||||
}
|
||||
return inputs;
|
||||
else {
|
||||
const inputs = {
|
||||
searchPath: path,
|
||||
ifNoFilesFound: noFileBehavior,
|
||||
artifactPerFile: artifactPerFile,
|
||||
artifactNameRule: artifactNameRule
|
||||
};
|
||||
if (retentionDaysStr) {
|
||||
inputs.retentionDays = parseInt(retentionDaysStr);
|
||||
if (isNaN(inputs.retentionDays)) {
|
||||
core.setFailed('Invalid retention-days');
|
||||
}
|
||||
}
|
||||
return inputs;
|
||||
}
|
||||
};
|
||||
return typedInputs(artifactPerFile);
|
||||
}
|
||||
exports.getInputs = getInputs;
|
||||
|
||||
|
@ -8196,6 +8289,8 @@ var Inputs;
|
|||
Inputs["Path"] = "path";
|
||||
Inputs["IfNoFilesFound"] = "if-no-files-found";
|
||||
Inputs["RetentionDays"] = "retention-days";
|
||||
Inputs["ArtifactPerFile"] = "artifact-per-file";
|
||||
Inputs["ArtifactNameRule"] = "artifact-name-rule";
|
||||
})(Inputs = exports.Inputs || (exports.Inputs = {}));
|
||||
var NoFileOptions;
|
||||
(function (NoFileOptions) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue