This commit is contained in:
Phred Lane 2025-10-05 14:39:54 +00:00 committed by GitHub
commit fd6a2845ae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 38 additions and 46 deletions

View File

@ -1,3 +1,5 @@
import {info, setFailed, warning} from '@actions/core'
/* eslint-disable no-unused-vars */
export enum Inputs {
Name = 'name',
@ -25,3 +27,9 @@ export enum NoFileOptions {
*/
ignore = 'ignore'
}
export const NoFileFunctionMap = {
[NoFileOptions.error]: setFailed,
[NoFileOptions.ignore]: info,
[NoFileOptions.warn]: warning
} as const

View File

@ -5,7 +5,7 @@ import artifact, {
} from '@actions/artifact'
import {findFilesToUpload} from '../shared/search'
import {getInputs} from './input-helper'
import {NoFileOptions} from './constants'
import {NoFileFunctionMap, NoFileOptions} from './constants'
import {uploadArtifact} from '../shared/upload-artifact'
async function deleteArtifactIfExists(artifactName: string): Promise<void> {
@ -30,27 +30,12 @@ export async function run(): Promise<void> {
)
if (searchResult.filesToUpload.length === 0) {
// No files were found, different use cases warrant different types of behavior if nothing is found
switch (inputs.ifNoFilesFound) {
case NoFileOptions.warn: {
core.warning(
NoFileFunctionMap[inputs.ifNoFilesFound]?.(
`No files were found with the provided path: ${inputs.searchPath}. No artifacts will be uploaded.`
)
break
return
}
case NoFileOptions.error: {
core.setFailed(
`No files were found with the provided path: ${inputs.searchPath}. No artifacts will be uploaded.`
)
break
}
case NoFileOptions.ignore: {
core.info(
`No files were found with the provided path: ${inputs.searchPath}. No artifacts will be uploaded.`
)
break
}
}
} else {
const s = searchResult.filesToUpload.length === 1 ? '' : 's'
core.info(
`With the provided path, there will be ${searchResult.filesToUpload.length} file${s} uploaded`
@ -77,4 +62,3 @@ export async function run(): Promise<void> {
options
)
}
}