mirror of
https://github.com/actions/download-artifact.git
synced 2024-11-22 21:55:29 +00:00
Add allow-not-found input in case artifact does not exist
This commit is contained in:
parent
fa0a91b85d
commit
215ab44d34
@ -17,6 +17,10 @@ inputs:
|
|||||||
If false, the downloaded artifacts will be extracted into individual named directories within the specified path.'
|
If false, the downloaded artifacts will be extracted into individual named directories within the specified path.'
|
||||||
required: false
|
required: false
|
||||||
default: 'false'
|
default: 'false'
|
||||||
|
allow-not-found:
|
||||||
|
description: 'If an artifact was not found, do not cause the action to fail.'
|
||||||
|
required: false
|
||||||
|
default: 'false'
|
||||||
github-token:
|
github-token:
|
||||||
description: 'The GitHub token used to authenticate with the GitHub API.
|
description: 'The GitHub token used to authenticate with the GitHub API.
|
||||||
This is required when downloading artifacts from a different repository or from a different workflow run.
|
This is required when downloading artifacts from a different repository or from a different workflow run.
|
||||||
|
@ -5,7 +5,8 @@ export enum Inputs {
|
|||||||
Repository = 'repository',
|
Repository = 'repository',
|
||||||
RunID = 'run-id',
|
RunID = 'run-id',
|
||||||
Pattern = 'pattern',
|
Pattern = 'pattern',
|
||||||
MergeMultiple = 'merge-multiple'
|
MergeMultiple = 'merge-multiple',
|
||||||
|
AllowNotFound = 'allow-not-found'
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum Outputs {
|
export enum Outputs {
|
||||||
|
@ -23,7 +23,10 @@ async function run(): Promise<void> {
|
|||||||
repository: core.getInput(Inputs.Repository, {required: false}),
|
repository: core.getInput(Inputs.Repository, {required: false}),
|
||||||
runID: parseInt(core.getInput(Inputs.RunID, {required: false})),
|
runID: parseInt(core.getInput(Inputs.RunID, {required: false})),
|
||||||
pattern: core.getInput(Inputs.Pattern, {required: false}),
|
pattern: core.getInput(Inputs.Pattern, {required: false}),
|
||||||
mergeMultiple: core.getBooleanInput(Inputs.MergeMultiple, {required: false})
|
mergeMultiple: core.getBooleanInput(Inputs.MergeMultiple, {
|
||||||
|
required: false
|
||||||
|
}),
|
||||||
|
allowNotFound: core.getBooleanInput(Inputs.AllowNotFound, {required: false})
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!inputs.path) {
|
if (!inputs.path) {
|
||||||
@ -35,7 +38,7 @@ async function run(): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const isSingleArtifactDownload = !!inputs.name
|
const isSingleArtifactDownload = !!inputs.name
|
||||||
const resolvedPath = path.resolve(inputs.path)
|
let resolvedPath = path.resolve(inputs.path)
|
||||||
core.debug(`Resolved path is ${resolvedPath}`)
|
core.debug(`Resolved path is ${resolvedPath}`)
|
||||||
|
|
||||||
const options: FindOptions = {}
|
const options: FindOptions = {}
|
||||||
@ -60,20 +63,25 @@ async function run(): Promise<void> {
|
|||||||
if (isSingleArtifactDownload) {
|
if (isSingleArtifactDownload) {
|
||||||
core.info(`Downloading single artifact`)
|
core.info(`Downloading single artifact`)
|
||||||
|
|
||||||
const {artifact: targetArtifact} = await artifactClient.getArtifact(
|
const targetArtifact = await artifactClient
|
||||||
inputs.name,
|
.getArtifact(inputs.name, options)
|
||||||
options
|
.catch(() => null)
|
||||||
)
|
|
||||||
|
|
||||||
if (!targetArtifact) {
|
if (!targetArtifact) {
|
||||||
throw new Error(`Artifact '${inputs.name}' not found`)
|
const message = `Artifact '${inputs.name}' not found`
|
||||||
|
if (!inputs.allowNotFound) {
|
||||||
|
throw new Error(message)
|
||||||
|
} else {
|
||||||
|
core.warning(message)
|
||||||
|
resolvedPath = ''
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
core.debug(
|
core.debug(
|
||||||
`Found named artifact '${inputs.name}' (ID: ${targetArtifact.id}, Size: ${targetArtifact.size})`
|
`Found named artifact '${inputs.name}' (ID: ${targetArtifact.artifact.id}, Size: ${targetArtifact.artifact.size})`
|
||||||
)
|
)
|
||||||
|
|
||||||
artifacts = [targetArtifact]
|
artifacts = [targetArtifact.artifact]
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
const listArtifactResponse = await artifactClient.listArtifacts({
|
const listArtifactResponse = await artifactClient.listArtifacts({
|
||||||
latest: true,
|
latest: true,
|
||||||
|
Loading…
Reference in New Issue
Block a user