2020-07-31 23:27:37 +08:00
|
|
|
import * as core from '@actions/core'
|
|
|
|
import {Inputs, NoFileOptions} from './constants'
|
2022-10-15 18:03:48 +08:00
|
|
|
import {UploadInputs, UploadPerFile} from './upload-inputs'
|
2020-07-31 23:27:37 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper to get all the inputs for the action
|
|
|
|
*/
|
2022-10-15 18:03:48 +08: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 23:27:37 +08:00
|
|
|
|
2022-10-15 18:03:48 +08: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 23:27:37 +08: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 18:03:48 +08: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-19 04:04:35 +08:00
|
|
|
}
|
2020-07-31 23:27:37 +08:00
|
|
|
}
|
2020-08-28 01:39:36 +08:00
|
|
|
|
2022-10-15 18:03:48 +08:00
|
|
|
return typedInputs(artifactPerFile)
|
2020-07-31 23:27:37 +08:00
|
|
|
}
|