mirror of
https://github.com/actions/upload-artifact.git
synced 2025-06-29 12:24:15 +00:00
feat: add upload one artifact per file
Signed-off-by: initdc <initd@outlook.com>
This commit is contained in:
parent
3cea537223
commit
35e561c49c
6 changed files with 365 additions and 48 deletions
|
@ -1,14 +1,28 @@
|
|||
import * as core from '@actions/core'
|
||||
import {Inputs, NoFileOptions} from './constants'
|
||||
import {UploadInputs} from './upload-inputs'
|
||||
import {UploadInputs, UploadPerFile} from './upload-inputs'
|
||||
|
||||
/**
|
||||
* Helper to get all the inputs for the action
|
||||
*/
|
||||
export function getInputs(): UploadInputs {
|
||||
const name = core.getInput(Inputs.Name)
|
||||
const path = core.getInput(Inputs.Path, {required: true})
|
||||
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
|
||||
}
|
||||
|
||||
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})
|
||||
const ifNoFilesFound = core.getInput(Inputs.IfNoFilesFound)
|
||||
const noFileBehavior: NoFileOptions = NoFileOptions[ifNoFilesFound]
|
||||
|
||||
|
@ -22,19 +36,44 @@ export function getInputs(): UploadInputs {
|
|||
)
|
||||
}
|
||||
|
||||
const inputs = {
|
||||
artifactName: name,
|
||||
searchPath: path,
|
||||
ifNoFilesFound: noFileBehavior
|
||||
} as UploadInputs
|
||||
const typedInputs = (
|
||||
artifactPerFile: boolean
|
||||
): UploadInputs | UploadPerFile => {
|
||||
const retentionDaysStr = core.getInput(Inputs.RetentionDays)
|
||||
|
||||
const retentionDaysStr = core.getInput(Inputs.RetentionDays)
|
||||
if (retentionDaysStr) {
|
||||
inputs.retentionDays = parseInt(retentionDaysStr)
|
||||
if (isNaN(inputs.retentionDays)) {
|
||||
core.setFailed('Invalid retention-days')
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
return inputs
|
||||
return typedInputs(artifactPerFile)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue