Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for uploading multiple artifacts #138

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ inputs:
path:
description: 'A file, directory or wildcard pattern that describes what to upload'
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:
description: >
The desired behavior if no files are found using the provided path.
Expand Down
30 changes: 26 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4022,12 +4022,28 @@ 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.`);
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 {
core.info(`Artifact ${uploadResponse.artifactName} has been successfully uploaded!`);
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.`);
}
else {
core.info(`Artifact ${uploadResponse.artifactName} has been successfully uploaded!`);
}
}
}
}
Expand Down Expand Up @@ -6394,12 +6410,17 @@ function getInputs() {
const path = core.getInput(constants_1.Inputs.Path, { required: true });
const ifNoFilesFound = core.getInput(constants_1.Inputs.IfNoFilesFound);
const noFileBehavior = constants_1.NoFileOptions[ifNoFilesFound];
const single = core.getInput(constants_1.Inputs.SingleArchive) || 'true';
if (!noFileBehavior) {
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 = {
artifactName: name,
searchPath: path,
singleArchive: single,
ifNoFilesFound: noFileBehavior
};
const retentionDaysStr = core.getInput(constants_1.Inputs.RetentionDays);
Expand Down Expand Up @@ -7333,6 +7354,7 @@ var Inputs;
(function (Inputs) {
Inputs["Name"] = "name";
Inputs["Path"] = "path";
Inputs["SingleArchive"] = "single-archive";
Inputs["IfNoFilesFound"] = "if-no-files-found";
Inputs["RetentionDays"] = "retention-days";
})(Inputs = exports.Inputs || (exports.Inputs = {}));
Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export enum Inputs {
Name = 'name',
Path = 'path',
SingleArchive = 'single-archive',
IfNoFilesFound = 'if-no-files-found',
RetentionDays = 'retention-days'
}
Expand Down
8 changes: 8 additions & 0 deletions src/input-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export function getInputs(): UploadInputs {

const ifNoFilesFound = core.getInput(Inputs.IfNoFilesFound)
const noFileBehavior: NoFileOptions = NoFileOptions[ifNoFilesFound]
const single = core.getInput(Inputs.SingleArchive) || 'true'

if (!noFileBehavior) {
core.setFailed(
Expand All @@ -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 = {
artifactName: name,
searchPath: path,
singleArchive: single,
ifNoFilesFound: noFileBehavior
} as UploadInputs

Expand Down
54 changes: 42 additions & 12 deletions src/upload-artifact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ async function run(): Promise<void> {
try {
const inputs = getInputs()
const searchResult = await findFilesToUpload(inputs.searchPath)

if (searchResult.filesToUpload.length === 0) {
// No files were found, different use cases warrant different types of behavior if nothing is found
switch (inputs.ifNoFilesFound) {
Expand Down Expand Up @@ -44,21 +45,50 @@ async function run(): Promise<void> {
options.retentionDays = inputs.retentionDays
}

const uploadResponse = await artifactClient.uploadArtifact(
inputs.artifactName,
searchResult.filesToUpload,
searchResult.rootDirectory,
options
)
if (inputs.singleArchive === 'false') {
core.info(`Uploading artifacts as individual archives`)

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.`
)
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 {
core.info(
`Artifact ${uploadResponse.artifactName} has been successfully uploaded!`
const uploadResponse = await 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.`
)
} else {
core.info(
`Artifact ${uploadResponse.artifactName} has been successfully uploaded!`
)
}
}
}
} catch (err) {
Expand Down
5 changes: 5 additions & 0 deletions src/upload-inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ export interface UploadInputs {
*/
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
*/
Expand Down