Added support for uploading multiple artifacts

This commit is contained in:
BToersche 2021-05-05 00:43:01 +02:00
commit 0b90c2eee6
No known key found for this signature in database
GPG key ID: CC102EACD57CB45A
4 changed files with 178 additions and 109 deletions

View file

@ -9,6 +9,18 @@ export function getInputs(): UploadInputs {
const name = core.getInput(Inputs.Name)
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 noFileBehavior: NoFileOptions = NoFileOptions[ifNoFilesFound]
@ -23,18 +35,40 @@ export function getInputs(): UploadInputs {
}
const inputs = {
artifactName: name,
searchPath: path,
artifactName,
searchPath,
ifNoFilesFound: noFileBehavior
} as UploadInputs
const retentionDaysStr = core.getInput(Inputs.RetentionDays)
if (retentionDaysStr) {
inputs.retentionDays = parseInt(retentionDaysStr)
if (isNaN(inputs.retentionDays)) {
core.setFailed('Invalid retention-days')
}
// Accepts an individual value or an array as input
const retentionDays = core.getInput(Inputs.RetentionDays)
if (Array.isArray(retentionDays)) {
// If array sizes don't match, use default value instead
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
}
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
}
}