@@ -9,17 +9,28 @@ export function getInputs(): UploadInputs {
9
9
const name = core . getInput ( Inputs . Name )
10
10
const path = core . getInput ( Inputs . Path , { required : true } )
11
11
12
- const searchPath = Array . isArray ( path ) ? path : [ path ]
12
+ const searchPath = parseFromJSON ( path ) || [ path ]
13
13
14
14
const defaultArtifactName = 'artifact'
15
15
// Accepts an individual value or an array as input, if array sizes don't match, use default value instead
16
- const artifactName = Array . isArray ( name )
17
- ? name . concat (
18
- new Array ( Math . max ( 0 , searchPath . length - name . length ) ) . fill (
19
- defaultArtifactName
20
- )
21
- )
22
- : new Array ( searchPath . length ) . fill ( name || defaultArtifactName )
16
+ const artifactName = parseParamaterToArrayFromInput (
17
+ name ,
18
+ searchPath . length ,
19
+ defaultArtifactName ,
20
+ ( defaultInput , index ) => {
21
+ const artifactIndexStr = index == 0 ? '' : `_${ index + 1 } `
22
+ return `${ defaultInput } ${ artifactIndexStr } `
23
+ }
24
+ )
25
+
26
+ // Accepts an individual value or an array as input
27
+ const retention = core . getInput ( Inputs . RetentionDays )
28
+ const retentionDays = parseParamaterToArrayFromInput (
29
+ retention ,
30
+ searchPath . length ,
31
+ undefined ,
32
+ defaultInput => defaultInput
33
+ ) . map ( parseRetentionDays )
23
34
24
35
const ifNoFilesFound = core . getInput ( Inputs . IfNoFilesFound )
25
36
const noFileBehavior : NoFileOptions = NoFileOptions [ ifNoFilesFound ]
@@ -37,26 +48,46 @@ export function getInputs(): UploadInputs {
37
48
const inputs = {
38
49
artifactName,
39
50
searchPath,
51
+ retentionDays,
40
52
ifNoFilesFound : noFileBehavior
41
53
} as UploadInputs
42
54
43
- // Accepts an individual value or an array as input
44
- const retentionDays = core . getInput ( Inputs . RetentionDays )
45
- if ( Array . isArray ( retentionDays ) ) {
46
- // If array sizes don't match, use default value instead
47
- inputs . retentionDays = retentionDays
48
- . map ( parseRetentionDays )
49
- . concat (
50
- new Array ( Math . max ( 0 , searchPath . length - retentionDays . length ) ) . fill (
51
- undefined
52
- )
55
+ return inputs
56
+ }
57
+
58
+ function parseParamaterToArrayFromInput (
59
+ input : string | undefined ,
60
+ requiredLength : number ,
61
+ defaultInput : string | undefined ,
62
+ defaultFunc : (
63
+ defaultInput : string | undefined ,
64
+ index : number
65
+ ) => string | undefined
66
+ ) : ( string | undefined ) [ ] {
67
+ // 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
68
+ const inputArray = parseFromJSON ( input || '[]' )
69
+ if ( inputArray ) {
70
+ // If a stringified JSON array is provided, use it and concat it with the default when required
71
+ return ( < ( string | undefined ) [ ] > inputArray ) . concat (
72
+ Array . from (
73
+ { length : Math . max ( 0 , requiredLength - inputArray . length ) } ,
74
+ ( _ , index ) => defaultFunc ( defaultInput , index )
53
75
)
54
- } else {
55
- const retention = parseRetentionDays ( retentionDays )
56
- inputs . retentionDays = new Array ( searchPath . length ) . fill ( retention )
76
+ )
57
77
}
78
+ // If a string is provided, fill the array with that value
79
+ return Array . from ( { length : Math . max ( 0 , requiredLength ) } , ( _ , index ) =>
80
+ defaultFunc ( input || defaultInput , index )
81
+ )
82
+ }
58
83
59
- return inputs
84
+ function parseFromJSON ( jsonStr : string ) : string [ ] | undefined {
85
+ try {
86
+ return < string [ ] > JSON . parse ( jsonStr )
87
+ } catch ( _err ) {
88
+ // Input wasn't a stringified JSON array (string[]), return undefined to signal an invalid JSON was provided
89
+ }
90
+ return undefined
60
91
}
61
92
62
93
function parseRetentionDays (
@@ -68,7 +99,6 @@ function parseRetentionDays(
68
99
core . setFailed ( 'Invalid retention-days' )
69
100
}
70
101
return retentionDays
71
- } else {
72
- return undefined
73
102
}
103
+ return undefined
74
104
}
0 commit comments