feat: enable ignore option when no artifact is found

This commit is contained in:
thundermiracle 2023-02-18 11:19:27 +09:00
parent e9ef242655
commit 808bacee91
3 changed files with 21 additions and 2 deletions

View File

@ -8,6 +8,10 @@ inputs:
path: path:
description: 'Destination path' description: 'Destination path'
required: false required: false
if-no-artifact:
description: 'How to exit action if no artifact is found. Can be fail, warn or ignore'
default: 'fail'
required: false
outputs: outputs:
download-path: download-path:
description: 'Path of artifact download' description: 'Path of artifact download'

View File

@ -1,6 +1,7 @@
export enum Inputs { export enum Inputs {
Name = 'name', Name = 'name',
Path = 'path' Path = 'path',
IfNoArtifact = 'if-no-artifact'
} }
export enum Outputs { export enum Outputs {
DownloadPath = 'download-path' DownloadPath = 'download-path'

View File

@ -5,9 +5,12 @@ import {resolve} from 'path'
import {Inputs, Outputs} from './constants' import {Inputs, Outputs} from './constants'
async function run(): Promise<void> { async function run(): Promise<void> {
let ifNoArtifact = ''
try { try {
const name = core.getInput(Inputs.Name, {required: false}) const name = core.getInput(Inputs.Name, {required: false})
const path = core.getInput(Inputs.Path, {required: false}) const path = core.getInput(Inputs.Path, {required: false})
ifNoArtifact =
core.getInput(Inputs.IfNoArtifact, {required: false}) || 'fail'
let resolvedPath let resolvedPath
// resolve tilde expansions, path.replace only replaces the first occurrence of a pattern // resolve tilde expansions, path.replace only replaces the first occurrence of a pattern
@ -54,7 +57,18 @@ async function run(): Promise<void> {
core.setOutput(Outputs.DownloadPath, resolvedPath) core.setOutput(Outputs.DownloadPath, resolvedPath)
core.info('Artifact download has finished successfully') core.info('Artifact download has finished successfully')
} catch (err) { } catch (err) {
core.setFailed(err.message) const {message} = err as Error
switch (ifNoArtifact) {
case 'warn':
core.warning(message)
break
case 'ignore':
core.info(message)
break
case 'fail':
default:
core.setFailed(message)
}
} }
} }