mirror of
https://github.com/actions/upload-artifact.git
synced 2025-10-08 20:06:27 +00:00
simplified logic for handling "no files" upload notification
This commit is contained in:
parent
2848b2cda0
commit
53778d2818
@ -1,3 +1,5 @@
|
|||||||
|
import {info, setFailed, warning} from '@actions/core'
|
||||||
|
|
||||||
/* eslint-disable no-unused-vars */
|
/* eslint-disable no-unused-vars */
|
||||||
export enum Inputs {
|
export enum Inputs {
|
||||||
Name = 'name',
|
Name = 'name',
|
||||||
@ -25,3 +27,9 @@ export enum NoFileOptions {
|
|||||||
*/
|
*/
|
||||||
ignore = 'ignore'
|
ignore = 'ignore'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const NoFileFunctionMap = {
|
||||||
|
[NoFileOptions.error]: setFailed,
|
||||||
|
[NoFileOptions.ignore]: info,
|
||||||
|
[NoFileOptions.warn]: warning
|
||||||
|
} as const
|
||||||
|
@ -5,7 +5,7 @@ import artifact, {
|
|||||||
} from '@actions/artifact'
|
} from '@actions/artifact'
|
||||||
import {findFilesToUpload} from '../shared/search'
|
import {findFilesToUpload} from '../shared/search'
|
||||||
import {getInputs} from './input-helper'
|
import {getInputs} from './input-helper'
|
||||||
import {NoFileOptions} from './constants'
|
import {NoFileFunctionMap, NoFileOptions} from './constants'
|
||||||
import {uploadArtifact} from '../shared/upload-artifact'
|
import {uploadArtifact} from '../shared/upload-artifact'
|
||||||
|
|
||||||
async function deleteArtifactIfExists(artifactName: string): Promise<void> {
|
async function deleteArtifactIfExists(artifactName: string): Promise<void> {
|
||||||
@ -30,27 +30,12 @@ export async function run(): Promise<void> {
|
|||||||
)
|
)
|
||||||
if (searchResult.filesToUpload.length === 0) {
|
if (searchResult.filesToUpload.length === 0) {
|
||||||
// No files were found, different use cases warrant different types of behavior if nothing is found
|
// No files were found, different use cases warrant different types of behavior if nothing is found
|
||||||
switch (inputs.ifNoFilesFound) {
|
NoFileFunctionMap[inputs.ifNoFilesFound]?.(
|
||||||
case NoFileOptions.warn: {
|
|
||||||
core.warning(
|
|
||||||
`No files were found with the provided path: ${inputs.searchPath}. No artifacts will be uploaded.`
|
`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'
|
const s = searchResult.filesToUpload.length === 1 ? '' : 's'
|
||||||
core.info(
|
core.info(
|
||||||
`With the provided path, there will be ${searchResult.filesToUpload.length} file${s} uploaded`
|
`With the provided path, there will be ${searchResult.filesToUpload.length} file${s} uploaded`
|
||||||
@ -77,4 +62,3 @@ export async function run(): Promise<void> {
|
|||||||
options
|
options
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user