mirror of
https://github.com/actions/upload-artifact.git
synced 2024-11-24 22:35:29 +00:00
Added support for uploading multiple artifacts
This commit is contained in:
parent
ee69f02b3d
commit
0b90c2eee6
114
dist/index.js
vendored
114
dist/index.js
vendored
@ -4028,44 +4028,49 @@ function run() {
|
|||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
try {
|
try {
|
||||||
const inputs = input_helper_1.getInputs();
|
const inputs = input_helper_1.getInputs();
|
||||||
const searchResult = yield search_1.findFilesToUpload(inputs.searchPath);
|
for (let i = 0; i < inputs.searchPath.length; i++) {
|
||||||
if (searchResult.filesToUpload.length === 0) {
|
const searchPath = inputs.searchPath[i];
|
||||||
// No files were found, different use cases warrant different types of behavior if nothing is found
|
const artifactName = inputs.artifactName[i];
|
||||||
switch (inputs.ifNoFilesFound) {
|
const retentionDays = inputs.retentionDays[i];
|
||||||
case constants_1.NoFileOptions.warn: {
|
const searchResult = yield search_1.findFilesToUpload(searchPath);
|
||||||
core.warning(`No files were found with the provided path: ${inputs.searchPath}. No artifacts will be uploaded.`);
|
if (searchResult.filesToUpload.length === 0) {
|
||||||
break;
|
// No files were found, different use cases warrant different types of behavior if nothing is found
|
||||||
|
switch (inputs.ifNoFilesFound) {
|
||||||
|
case constants_1.NoFileOptions.warn: {
|
||||||
|
core.warning(`No files were found with the provided path: ${searchPath}. No artifacts will be uploaded.`);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case constants_1.NoFileOptions.error: {
|
||||||
|
core.setFailed(`No files were found with the provided path: ${searchPath}. No artifacts will be uploaded.`);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case constants_1.NoFileOptions.ignore: {
|
||||||
|
core.info(`No files were found with the provided path: ${searchPath}. No artifacts will be uploaded.`);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
case constants_1.NoFileOptions.error: {
|
|
||||||
core.setFailed(`No files were found with the provided path: ${inputs.searchPath}. No artifacts will be uploaded.`);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case constants_1.NoFileOptions.ignore: {
|
|
||||||
core.info(`No files were found with the provided path: ${inputs.searchPath}. No artifacts will be uploaded.`);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
const s = searchResult.filesToUpload.length === 1 ? '' : 's';
|
|
||||||
core.info(`With the provided path, there will be ${searchResult.filesToUpload.length} file${s} uploaded`);
|
|
||||||
core.debug(`Root artifact directory is ${searchResult.rootDirectory}`);
|
|
||||||
if (searchResult.filesToUpload.length > 10000) {
|
|
||||||
core.warning(`There are over 10,000 files in this artifact, consider create an archive before upload to improve the upload performance.`);
|
|
||||||
}
|
|
||||||
const artifactClient = artifact_1.create();
|
|
||||||
const options = {
|
|
||||||
continueOnError: false
|
|
||||||
};
|
|
||||||
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.`);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
core.info(`Artifact ${uploadResponse.artifactName} has been successfully uploaded!`);
|
const s = searchResult.filesToUpload.length === 1 ? '' : 's';
|
||||||
|
core.info(`With the provided path, there will be ${searchResult.filesToUpload.length} file${s} uploaded`);
|
||||||
|
core.debug(`Root artifact directory is ${searchResult.rootDirectory}`);
|
||||||
|
if (searchResult.filesToUpload.length > 10000) {
|
||||||
|
core.warning(`There are over 10,000 files in this artifact, consider create an archive before upload to improve the upload performance.`);
|
||||||
|
}
|
||||||
|
const artifactClient = artifact_1.create();
|
||||||
|
const options = {
|
||||||
|
continueOnError: false
|
||||||
|
};
|
||||||
|
if (retentionDays) {
|
||||||
|
options.retentionDays = retentionDays;
|
||||||
|
}
|
||||||
|
const uploadResponse = yield artifactClient.uploadArtifact(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!`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -6576,26 +6581,49 @@ const constants_1 = __webpack_require__(694);
|
|||||||
function getInputs() {
|
function getInputs() {
|
||||||
const name = core.getInput(constants_1.Inputs.Name);
|
const name = core.getInput(constants_1.Inputs.Name);
|
||||||
const path = core.getInput(constants_1.Inputs.Path, { required: true });
|
const path = core.getInput(constants_1.Inputs.Path, { required: true });
|
||||||
|
const searchPath = Array.isArray(path) ? path : [path];
|
||||||
|
const defaultArtifactName = 'artifact';
|
||||||
|
// Accepts an individual value or an array as input, if array sizes don't match, use default value instead
|
||||||
|
const artifactName = Array.isArray(name)
|
||||||
|
? name.concat(new Array(Math.max(0, searchPath.length - name.length)).fill(defaultArtifactName))
|
||||||
|
: new Array(searchPath.length).fill(name || defaultArtifactName);
|
||||||
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];
|
||||||
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)}`);
|
||||||
}
|
}
|
||||||
const inputs = {
|
const inputs = {
|
||||||
artifactName: name,
|
artifactName,
|
||||||
searchPath: path,
|
searchPath,
|
||||||
ifNoFilesFound: noFileBehavior
|
ifNoFilesFound: noFileBehavior
|
||||||
};
|
};
|
||||||
const retentionDaysStr = core.getInput(constants_1.Inputs.RetentionDays);
|
// Accepts an individual value or an array as input
|
||||||
if (retentionDaysStr) {
|
const retentionDays = core.getInput(constants_1.Inputs.RetentionDays);
|
||||||
inputs.retentionDays = parseInt(retentionDaysStr);
|
if (Array.isArray(retentionDays)) {
|
||||||
if (isNaN(inputs.retentionDays)) {
|
// If array sizes don't match, use default value instead
|
||||||
core.setFailed('Invalid retention-days');
|
inputs.retentionDays = retentionDays
|
||||||
}
|
.map(parseRetentionDays)
|
||||||
|
.concat(new Array(Math.max(0, searchPath.length - retentionDays.length)).fill(undefined));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const retention = parseRetentionDays(retentionDays);
|
||||||
|
inputs.retentionDays = new Array(searchPath.length).fill(retention);
|
||||||
}
|
}
|
||||||
return inputs;
|
return inputs;
|
||||||
}
|
}
|
||||||
exports.getInputs = getInputs;
|
exports.getInputs = getInputs;
|
||||||
|
function parseRetentionDays(retentionDaysStr) {
|
||||||
|
if (retentionDaysStr) {
|
||||||
|
const retentionDays = parseInt(retentionDaysStr);
|
||||||
|
if (isNaN(retentionDays)) {
|
||||||
|
core.setFailed('Invalid retention-days');
|
||||||
|
}
|
||||||
|
return retentionDays;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
@ -9,6 +9,18 @@ export function getInputs(): UploadInputs {
|
|||||||
const name = core.getInput(Inputs.Name)
|
const name = core.getInput(Inputs.Name)
|
||||||
const path = core.getInput(Inputs.Path, {required: true})
|
const path = core.getInput(Inputs.Path, {required: true})
|
||||||
|
|
||||||
|
const searchPath = Array.isArray(path) ? path : [path]
|
||||||
|
|
||||||
|
const defaultArtifactName = 'artifact'
|
||||||
|
// Accepts an individual value or an array as input, if array sizes don't match, use default value instead
|
||||||
|
const artifactName = Array.isArray(name)
|
||||||
|
? name.concat(
|
||||||
|
new Array(Math.max(0, searchPath.length - name.length)).fill(
|
||||||
|
defaultArtifactName
|
||||||
|
)
|
||||||
|
)
|
||||||
|
: new Array(searchPath.length).fill(name || defaultArtifactName)
|
||||||
|
|
||||||
const ifNoFilesFound = core.getInput(Inputs.IfNoFilesFound)
|
const ifNoFilesFound = core.getInput(Inputs.IfNoFilesFound)
|
||||||
const noFileBehavior: NoFileOptions = NoFileOptions[ifNoFilesFound]
|
const noFileBehavior: NoFileOptions = NoFileOptions[ifNoFilesFound]
|
||||||
|
|
||||||
@ -23,18 +35,40 @@ export function getInputs(): UploadInputs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const inputs = {
|
const inputs = {
|
||||||
artifactName: name,
|
artifactName,
|
||||||
searchPath: path,
|
searchPath,
|
||||||
ifNoFilesFound: noFileBehavior
|
ifNoFilesFound: noFileBehavior
|
||||||
} as UploadInputs
|
} as UploadInputs
|
||||||
|
|
||||||
const retentionDaysStr = core.getInput(Inputs.RetentionDays)
|
// Accepts an individual value or an array as input
|
||||||
if (retentionDaysStr) {
|
const retentionDays = core.getInput(Inputs.RetentionDays)
|
||||||
inputs.retentionDays = parseInt(retentionDaysStr)
|
if (Array.isArray(retentionDays)) {
|
||||||
if (isNaN(inputs.retentionDays)) {
|
// If array sizes don't match, use default value instead
|
||||||
core.setFailed('Invalid retention-days')
|
inputs.retentionDays = retentionDays
|
||||||
}
|
.map(parseRetentionDays)
|
||||||
|
.concat(
|
||||||
|
new Array(Math.max(0, searchPath.length - retentionDays.length)).fill(
|
||||||
|
undefined
|
||||||
|
)
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
const retention = parseRetentionDays(retentionDays)
|
||||||
|
inputs.retentionDays = new Array(searchPath.length).fill(retention)
|
||||||
}
|
}
|
||||||
|
|
||||||
return inputs
|
return inputs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parseRetentionDays(
|
||||||
|
retentionDaysStr: string | undefined
|
||||||
|
): number | undefined {
|
||||||
|
if (retentionDaysStr) {
|
||||||
|
const retentionDays = parseInt(retentionDaysStr)
|
||||||
|
if (isNaN(retentionDays)) {
|
||||||
|
core.setFailed('Invalid retention-days')
|
||||||
|
}
|
||||||
|
return retentionDays
|
||||||
|
} else {
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -7,65 +7,72 @@ import {NoFileOptions} from './constants'
|
|||||||
async function run(): Promise<void> {
|
async function run(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const inputs = getInputs()
|
const inputs = getInputs()
|
||||||
const searchResult = await findFilesToUpload(inputs.searchPath)
|
|
||||||
if (searchResult.filesToUpload.length === 0) {
|
for (let i = 0; i < inputs.searchPath.length; i++) {
|
||||||
// No files were found, different use cases warrant different types of behavior if nothing is found
|
const searchPath = inputs.searchPath[i]
|
||||||
switch (inputs.ifNoFilesFound) {
|
const artifactName = inputs.artifactName[i]
|
||||||
case NoFileOptions.warn: {
|
const retentionDays = inputs.retentionDays[i]
|
||||||
core.warning(
|
|
||||||
`No files were found with the provided path: ${inputs.searchPath}. No artifacts will be uploaded.`
|
const searchResult = await findFilesToUpload(searchPath)
|
||||||
)
|
if (searchResult.filesToUpload.length === 0) {
|
||||||
break
|
// No files were found, different use cases warrant different types of behavior if nothing is found
|
||||||
|
switch (inputs.ifNoFilesFound) {
|
||||||
|
case NoFileOptions.warn: {
|
||||||
|
core.warning(
|
||||||
|
`No files were found with the provided path: ${searchPath}. No artifacts will be uploaded.`
|
||||||
|
)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
case NoFileOptions.error: {
|
||||||
|
core.setFailed(
|
||||||
|
`No files were found with the provided path: ${searchPath}. No artifacts will be uploaded.`
|
||||||
|
)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
case NoFileOptions.ignore: {
|
||||||
|
core.info(
|
||||||
|
`No files were found with the provided path: ${searchPath}. No artifacts will be uploaded.`
|
||||||
|
)
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
case NoFileOptions.error: {
|
|
||||||
core.setFailed(
|
|
||||||
`No files were found with the provided path: ${inputs.searchPath}. No artifacts will be uploaded.`
|
|
||||||
)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
case NoFileOptions.ignore: {
|
|
||||||
core.info(
|
|
||||||
`No files were found with the provided path: ${inputs.searchPath}. No artifacts will be uploaded.`
|
|
||||||
)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const s = searchResult.filesToUpload.length === 1 ? '' : 's'
|
|
||||||
core.info(
|
|
||||||
`With the provided path, there will be ${searchResult.filesToUpload.length} file${s} uploaded`
|
|
||||||
)
|
|
||||||
core.debug(`Root artifact directory is ${searchResult.rootDirectory}`)
|
|
||||||
|
|
||||||
if (searchResult.filesToUpload.length > 10000) {
|
|
||||||
core.warning(
|
|
||||||
`There are over 10,000 files in this artifact, consider create an archive before upload to improve the upload performance.`
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
const artifactClient = create()
|
|
||||||
const options: UploadOptions = {
|
|
||||||
continueOnError: false
|
|
||||||
}
|
|
||||||
if (inputs.retentionDays) {
|
|
||||||
options.retentionDays = inputs.retentionDays
|
|
||||||
}
|
|
||||||
|
|
||||||
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 {
|
} else {
|
||||||
|
const s = searchResult.filesToUpload.length === 1 ? '' : 's'
|
||||||
core.info(
|
core.info(
|
||||||
`Artifact ${uploadResponse.artifactName} has been successfully uploaded!`
|
`With the provided path, there will be ${searchResult.filesToUpload.length} file${s} uploaded`
|
||||||
)
|
)
|
||||||
|
core.debug(`Root artifact directory is ${searchResult.rootDirectory}`)
|
||||||
|
|
||||||
|
if (searchResult.filesToUpload.length > 10000) {
|
||||||
|
core.warning(
|
||||||
|
`There are over 10,000 files in this artifact, consider create an archive before upload to improve the upload performance.`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const artifactClient = create()
|
||||||
|
const options: UploadOptions = {
|
||||||
|
continueOnError: false
|
||||||
|
}
|
||||||
|
if (retentionDays) {
|
||||||
|
options.retentionDays = retentionDays
|
||||||
|
}
|
||||||
|
|
||||||
|
const uploadResponse = await artifactClient.uploadArtifact(
|
||||||
|
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) {
|
} catch (err) {
|
||||||
|
@ -4,12 +4,12 @@ export interface UploadInputs {
|
|||||||
/**
|
/**
|
||||||
* The name of the artifact that will be uploaded
|
* The name of the artifact that will be uploaded
|
||||||
*/
|
*/
|
||||||
artifactName: string
|
artifactName: string[]
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The search path used to describe what to upload as part of the artifact
|
* The search path used to describe what to upload as part of the artifact
|
||||||
*/
|
*/
|
||||||
searchPath: string
|
searchPath: 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
|
||||||
@ -19,5 +19,5 @@ export interface UploadInputs {
|
|||||||
/**
|
/**
|
||||||
* Duration after which artifact will expire in days
|
* Duration after which artifact will expire in days
|
||||||
*/
|
*/
|
||||||
retentionDays: number
|
retentionDays: (number | undefined)[]
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user