2020-07-31 15:27:37 +00:00
|
|
|
import * as core from '@actions/core'
|
|
|
|
import {Inputs, NoFileOptions} from './constants'
|
2022-10-15 10:03:48 +00:00
|
|
|
import {UploadInputs, UploadPerFile} from './upload-inputs'
|
2020-07-31 15:27:37 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper to get all the inputs for the action
|
|
|
|
*/
|
2022-10-15 10:03:48 +00:00
|
|
|
export function getInputs(): UploadInputs | UploadPerFile {
|
|
|
|
const TRUE_MAP = ['true', 'True', 'TRUE']
|
|
|
|
|
|
|
|
let artifactPerFile = false
|
|
|
|
const artifactPerFileStr = core.getInput(Inputs.ArtifactPerFile)
|
|
|
|
if (artifactPerFileStr) {
|
|
|
|
artifactPerFile = TRUE_MAP.includes(artifactPerFileStr) ? true : false
|
|
|
|
}
|
2020-07-31 15:27:37 +00:00
|
|
|
|
2022-10-15 10:03:48 +00:00
|
|
|
let name = ''
|
|
|
|
let artifactNameRule = ''
|
|
|
|
if (!artifactPerFile) {
|
|
|
|
name = core.getInput(Inputs.Name)
|
|
|
|
} else {
|
|
|
|
artifactNameRule = core.getInput(Inputs.ArtifactNameRule) || '${base}'
|
|
|
|
}
|
|
|
|
|
|
|
|
const path = core.getInput(Inputs.Path, {required: true})
|
2020-07-31 15:27:37 +00:00
|
|
|
const ifNoFilesFound = core.getInput(Inputs.IfNoFilesFound)
|
|
|
|
const noFileBehavior: NoFileOptions = NoFileOptions[ifNoFilesFound]
|
|
|
|
|
|
|
|
if (!noFileBehavior) {
|
|
|
|
core.setFailed(
|
|
|
|
`Unrecognized ${
|
|
|
|
Inputs.IfNoFilesFound
|
|
|
|
} input. Provided: ${ifNoFilesFound}. Available options: ${Object.keys(
|
|
|
|
NoFileOptions
|
|
|
|
)}`
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-10-15 10:03:48 +00:00
|
|
|
const typedInputs = (
|
|
|
|
artifactPerFile: boolean
|
|
|
|
): UploadInputs | UploadPerFile => {
|
|
|
|
const retentionDaysStr = core.getInput(Inputs.RetentionDays)
|
|
|
|
|
|
|
|
if (!artifactPerFile) {
|
|
|
|
const inputs = {
|
|
|
|
artifactsName: name,
|
|
|
|
searchPath: path,
|
|
|
|
ifNoFilesFound: noFileBehavior
|
|
|
|
} as UploadInputs
|
|
|
|
|
|
|
|
if (retentionDaysStr) {
|
|
|
|
inputs.retentionDays = parseInt(retentionDaysStr)
|
|
|
|
if (isNaN(inputs.retentionDays)) {
|
|
|
|
core.setFailed('Invalid retention-days')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return inputs
|
|
|
|
} else {
|
|
|
|
const inputs = {
|
|
|
|
searchPath: path,
|
|
|
|
ifNoFilesFound: noFileBehavior,
|
|
|
|
artifactPerFile: artifactPerFile,
|
|
|
|
artifactNameRule: artifactNameRule
|
|
|
|
} as UploadPerFile
|
|
|
|
|
|
|
|
if (retentionDaysStr) {
|
|
|
|
inputs.retentionDays = parseInt(retentionDaysStr)
|
|
|
|
if (isNaN(inputs.retentionDays)) {
|
|
|
|
core.setFailed('Invalid retention-days')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return inputs
|
2020-09-18 20:04:35 +00:00
|
|
|
}
|
2020-07-31 15:27:37 +00:00
|
|
|
}
|
2020-08-27 17:39:36 +00:00
|
|
|
|
2022-10-15 10:03:48 +00:00
|
|
|
return typedInputs(artifactPerFile)
|
2020-07-31 15:27:37 +00:00
|
|
|
}
|