@ -9,17 +9,28 @@ 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 searchPath = parseFromJSON ( path ) || [ path ]
const defaultArtifactName = 'artifact'
const defaultArtifactName = 'artifact'
// Accepts an individual value or an array as input, if array sizes don't match, use default value instead
// Accepts an individual value or an array as input, if array sizes don't match, use default value instead
const artifactName = Array . isArray ( name )
const artifactName = parseParamaterToArrayFromInput (
? name . concat (
name ,
new Array ( Math . max ( 0 , searchPath . length - name . length ) ) . fill (
searchPath . length ,
defaultArtifactName
defaultArtifactName ,
)
( defaultInput , index ) = > {
const artifactIndexStr = index == 0 ? '' : ` _ ${ index + 1 } `
return ` ${ defaultInput } ${ artifactIndexStr } `
}
)
)
: new Array ( searchPath . length ) . fill ( name || defaultArtifactName )
// Accepts an individual value or an array as input
const retention = core . getInput ( Inputs . RetentionDays )
const retentionDays = parseParamaterToArrayFromInput (
retention ,
searchPath . length ,
undefined ,
defaultInput = > defaultInput
) . map ( parseRetentionDays )
const ifNoFilesFound = core . getInput ( Inputs . IfNoFilesFound )
const ifNoFilesFound = core . getInput ( Inputs . IfNoFilesFound )
const noFileBehavior : NoFileOptions = NoFileOptions [ ifNoFilesFound ]
const noFileBehavior : NoFileOptions = NoFileOptions [ ifNoFilesFound ]
@ -37,38 +48,60 @@ export function getInputs(): UploadInputs {
const inputs = {
const inputs = {
artifactName ,
artifactName ,
searchPath ,
searchPath ,
retentionDays ,
ifNoFilesFound : noFileBehavior
ifNoFilesFound : noFileBehavior
} as UploadInputs
} as UploadInputs
// Accepts an individual value or an array as input
return inputs
const retentionDays = core . getInput ( Inputs . RetentionDays )
}
if ( Array . isArray ( retentionDays ) ) {
// If array sizes don't match, use default value instead
function parseParamaterToArrayFromInput (
inputs . retentionDays = retentionDays
input : string | undefined ,
. map ( parseRetentionDays )
requiredLength : number ,
. concat (
defaultInput : string | undefined ,
new Array ( Math . max ( 0 , searchPath . length - retentionDays . length ) ) . fill (
defaultFunc : (
undefined
defaultInput : string | undefined ,
index : number
) = > string | undefined
) : ( string | undefined ) [ ] {
// Accepts an individual value or an array as input, if array size doesn't match the required length, fill the rest with a default value
const inputArray = parseFromJSON ( input || '[]' )
if ( inputArray != null ) {
// If a stringified JSON array is provided, use it and concat it with the default when required
return ( < ( string | undefined ) [ ] > inputArray ) . concat (
Array . from (
{ length : Math.max ( 0 , requiredLength - inputArray . length ) } ,
( _ , index ) = > defaultFunc ( defaultInput , index )
)
)
)
)
} else {
}
const retention = parseRetentionDays ( retentionDays )
// If a string is provided, fill the array with that value
inputs . retentionDays = new Array ( searchPath . length ) . fill ( retention )
return Array . from ( { length : Math.max ( 0 , requiredLength ) } , ( _ , index ) = >
defaultFunc ( input || defaultInput , index )
)
}
}
return inputs
function parseFromJSON ( jsonStr : string ) : string [ ] | undefined {
try {
const json = < string [ ] > JSON . parse ( jsonStr )
if ( Array . isArray ( json ) ) {
return json
}
} catch ( _err ) {
// Input wasn't a stringified JSON array (string[]), return undefined to signal an invalid JSON was provided
}
return undefined
}
}
function parseRetentionDays (
function parseRetentionDays (
retentionDaysStr : string | undefined
retentionDaysStr : string | undefined
) : number | undefined {
) : number | undefined {
if ( retentionDaysStr ) {
if ( retentionDaysStr != null ) {
const retentionDays = parseInt ( retentionDaysStr )
const retentionDays = parseInt ( retentionDaysStr )
if ( isNaN ( retentionDays ) ) {
if ( isNaN ( retentionDays ) ) {
core . setFailed ( 'Invalid retention-days' )
core . setFailed ( 'Invalid retention-days' )
}
}
return retentionDays
return retentionDays
} else {
return undefined
}
}
return undefined
}
}