mirror of
https://gitea.com/actions/upload-artifact.git
synced 2024-11-23 00:55:58 +01:00
Add support for uploading multiple artifacts
This commit is contained in:
parent
27bce4eee7
commit
0f84e7bc9c
6 changed files with 87 additions and 16 deletions
|
@ -8,6 +8,11 @@ inputs:
|
||||||
path:
|
path:
|
||||||
description: 'A file, directory or wildcard pattern that describes what to upload'
|
description: 'A file, directory or wildcard pattern that describes what to upload'
|
||||||
required: true
|
required: true
|
||||||
|
single-archive:
|
||||||
|
description: >
|
||||||
|
Whether or not all files for the action should be combined into a single archive
|
||||||
|
or uploaded as separate archives
|
||||||
|
default: 'true'
|
||||||
if-no-files-found:
|
if-no-files-found:
|
||||||
description: >
|
description: >
|
||||||
The desired behavior if no files are found using the provided path.
|
The desired behavior if no files are found using the provided path.
|
||||||
|
|
22
dist/index.js
vendored
22
dist/index.js
vendored
|
@ -4022,6 +4022,21 @@ function run() {
|
||||||
if (inputs.retentionDays) {
|
if (inputs.retentionDays) {
|
||||||
options.retentionDays = inputs.retentionDays;
|
options.retentionDays = inputs.retentionDays;
|
||||||
}
|
}
|
||||||
|
if (inputs.singleArchive === 'false') {
|
||||||
|
core.info(`Uploading artifacts as individual archives`);
|
||||||
|
for (const fileToUpload of searchResult.filesToUpload) {
|
||||||
|
const uploadName = inputs.artifactName.concat('_'.concat(fileToUpload.substring(fileToUpload.lastIndexOf('/') + 1)));
|
||||||
|
core.info(`Attempting to upload artifact with name: ${uploadName} at path ${fileToUpload}`);
|
||||||
|
const uploadResponse = yield artifactClient.uploadArtifact(uploadName, [fileToUpload], searchResult.rootDirectory, options);
|
||||||
|
if (uploadResponse.failedItems.length > 0) {
|
||||||
|
core.setFailed(`An error was encountered when uploading ${uploadName}. There were ${uploadResponse.failedItems.length} items that failed to upload.`);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
core.info(`Artifact ${uploadName} has been successfully uploaded!`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
const uploadResponse = yield artifactClient.uploadArtifact(inputs.artifactName, searchResult.filesToUpload, searchResult.rootDirectory, options);
|
const uploadResponse = yield artifactClient.uploadArtifact(inputs.artifactName, searchResult.filesToUpload, searchResult.rootDirectory, options);
|
||||||
if (uploadResponse.failedItems.length > 0) {
|
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.`);
|
core.setFailed(`An error was encountered when uploading ${uploadResponse.artifactName}. There were ${uploadResponse.failedItems.length} items that failed to upload.`);
|
||||||
|
@ -4031,6 +4046,7 @@ function run() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
core.setFailed(err.message);
|
core.setFailed(err.message);
|
||||||
}
|
}
|
||||||
|
@ -6394,12 +6410,17 @@ function getInputs() {
|
||||||
const path = core.getInput(constants_1.Inputs.Path, { required: true });
|
const path = core.getInput(constants_1.Inputs.Path, { required: true });
|
||||||
const ifNoFilesFound = core.getInput(constants_1.Inputs.IfNoFilesFound);
|
const ifNoFilesFound = core.getInput(constants_1.Inputs.IfNoFilesFound);
|
||||||
const noFileBehavior = constants_1.NoFileOptions[ifNoFilesFound];
|
const noFileBehavior = constants_1.NoFileOptions[ifNoFilesFound];
|
||||||
|
const single = core.getInput(constants_1.Inputs.SingleArchive) || 'true';
|
||||||
if (!noFileBehavior) {
|
if (!noFileBehavior) {
|
||||||
core.setFailed(`Unrecognized ${constants_1.Inputs.IfNoFilesFound} input. Provided: ${ifNoFilesFound}. Available options: ${Object.keys(constants_1.NoFileOptions)}`);
|
core.setFailed(`Unrecognized ${constants_1.Inputs.IfNoFilesFound} input. Provided: ${ifNoFilesFound}. Available options: ${Object.keys(constants_1.NoFileOptions)}`);
|
||||||
}
|
}
|
||||||
|
if (single !== 'true' && single !== 'false') {
|
||||||
|
core.setFailed(`Unrecognized ${constants_1.Inputs.SingleArchive} input. Provided: ${single}. Must be 'true' or 'false'.`);
|
||||||
|
}
|
||||||
const inputs = {
|
const inputs = {
|
||||||
artifactName: name,
|
artifactName: name,
|
||||||
searchPath: path,
|
searchPath: path,
|
||||||
|
singleArchive: single,
|
||||||
ifNoFilesFound: noFileBehavior
|
ifNoFilesFound: noFileBehavior
|
||||||
};
|
};
|
||||||
const retentionDaysStr = core.getInput(constants_1.Inputs.RetentionDays);
|
const retentionDaysStr = core.getInput(constants_1.Inputs.RetentionDays);
|
||||||
|
@ -7333,6 +7354,7 @@ var Inputs;
|
||||||
(function (Inputs) {
|
(function (Inputs) {
|
||||||
Inputs["Name"] = "name";
|
Inputs["Name"] = "name";
|
||||||
Inputs["Path"] = "path";
|
Inputs["Path"] = "path";
|
||||||
|
Inputs["SingleArchive"] = "single-archive";
|
||||||
Inputs["IfNoFilesFound"] = "if-no-files-found";
|
Inputs["IfNoFilesFound"] = "if-no-files-found";
|
||||||
Inputs["RetentionDays"] = "retention-days";
|
Inputs["RetentionDays"] = "retention-days";
|
||||||
})(Inputs = exports.Inputs || (exports.Inputs = {}));
|
})(Inputs = exports.Inputs || (exports.Inputs = {}));
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
export enum Inputs {
|
export enum Inputs {
|
||||||
Name = 'name',
|
Name = 'name',
|
||||||
Path = 'path',
|
Path = 'path',
|
||||||
|
SingleArchive = 'single-archive',
|
||||||
IfNoFilesFound = 'if-no-files-found',
|
IfNoFilesFound = 'if-no-files-found',
|
||||||
RetentionDays = 'retention-days'
|
RetentionDays = 'retention-days'
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ export function getInputs(): UploadInputs {
|
||||||
|
|
||||||
const ifNoFilesFound = core.getInput(Inputs.IfNoFilesFound)
|
const ifNoFilesFound = core.getInput(Inputs.IfNoFilesFound)
|
||||||
const noFileBehavior: NoFileOptions = NoFileOptions[ifNoFilesFound]
|
const noFileBehavior: NoFileOptions = NoFileOptions[ifNoFilesFound]
|
||||||
|
const single = core.getInput(Inputs.SingleArchive) || 'true'
|
||||||
|
|
||||||
if (!noFileBehavior) {
|
if (!noFileBehavior) {
|
||||||
core.setFailed(
|
core.setFailed(
|
||||||
|
@ -22,9 +23,16 @@ export function getInputs(): UploadInputs {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (single !== 'true' && single !== 'false') {
|
||||||
|
core.setFailed(
|
||||||
|
`Unrecognized ${Inputs.SingleArchive} input. Provided: ${single}. Must be 'true' or 'false'.`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const inputs = {
|
const inputs = {
|
||||||
artifactName: name,
|
artifactName: name,
|
||||||
searchPath: path,
|
searchPath: path,
|
||||||
|
singleArchive: single,
|
||||||
ifNoFilesFound: noFileBehavior
|
ifNoFilesFound: noFileBehavior
|
||||||
} as UploadInputs
|
} as UploadInputs
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ async function run(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const inputs = getInputs()
|
const inputs = getInputs()
|
||||||
const searchResult = await findFilesToUpload(inputs.searchPath)
|
const searchResult = await findFilesToUpload(inputs.searchPath)
|
||||||
|
|
||||||
if (searchResult.filesToUpload.length === 0) {
|
if (searchResult.filesToUpload.length === 0) {
|
||||||
// No files were found, different use cases warrant different types of behavior if nothing is found
|
// No files were found, different use cases warrant different types of behavior if nothing is found
|
||||||
switch (inputs.ifNoFilesFound) {
|
switch (inputs.ifNoFilesFound) {
|
||||||
|
@ -44,6 +45,34 @@ async function run(): Promise<void> {
|
||||||
options.retentionDays = inputs.retentionDays
|
options.retentionDays = inputs.retentionDays
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (inputs.singleArchive === 'false') {
|
||||||
|
core.info(`Uploading artifacts as individual archives`)
|
||||||
|
|
||||||
|
for (const fileToUpload of searchResult.filesToUpload) {
|
||||||
|
const uploadName = inputs.artifactName.concat(
|
||||||
|
'_'.concat(
|
||||||
|
fileToUpload.substring(fileToUpload.lastIndexOf('/') + 1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
core.info(
|
||||||
|
`Attempting to upload artifact with name: ${uploadName} at path ${fileToUpload}`
|
||||||
|
)
|
||||||
|
const uploadResponse = await artifactClient.uploadArtifact(
|
||||||
|
uploadName,
|
||||||
|
[fileToUpload],
|
||||||
|
searchResult.rootDirectory,
|
||||||
|
options
|
||||||
|
)
|
||||||
|
|
||||||
|
if (uploadResponse.failedItems.length > 0) {
|
||||||
|
core.setFailed(
|
||||||
|
`An error was encountered when uploading ${uploadName}. There were ${uploadResponse.failedItems.length} items that failed to upload.`
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
core.info(`Artifact ${uploadName} has been successfully uploaded!`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
const uploadResponse = await artifactClient.uploadArtifact(
|
const uploadResponse = await artifactClient.uploadArtifact(
|
||||||
inputs.artifactName,
|
inputs.artifactName,
|
||||||
searchResult.filesToUpload,
|
searchResult.filesToUpload,
|
||||||
|
@ -61,6 +90,7 @@ async function run(): Promise<void> {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
core.setFailed(err.message)
|
core.setFailed(err.message)
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,11 @@ export interface UploadInputs {
|
||||||
*/
|
*/
|
||||||
searchPath: string
|
searchPath: string
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether or not to upload artifacts as a single archive or as individual files
|
||||||
|
*/
|
||||||
|
singleArchive: string
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The desired behavior if no files are found with the provided search path
|
* The desired behavior if no files are found with the provided search path
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue