mirror of
https://github.com/actions/upload-artifact.git
synced 2025-04-05 22:19:38 +00:00
add new overwrite input & docs
This commit is contained in:
@ -4,7 +4,8 @@ export enum Inputs {
|
||||
Path = 'path',
|
||||
IfNoFilesFound = 'if-no-files-found',
|
||||
RetentionDays = 'retention-days',
|
||||
CompressionLevel = 'compression-level'
|
||||
CompressionLevel = 'compression-level',
|
||||
Overwrite = 'overwrite'
|
||||
}
|
||||
|
||||
export enum NoFileOptions {
|
||||
|
@ -8,6 +8,7 @@ import {UploadInputs} from './upload-inputs'
|
||||
export function getInputs(): UploadInputs {
|
||||
const name = core.getInput(Inputs.Name)
|
||||
const path = core.getInput(Inputs.Path, {required: true})
|
||||
const overwrite = core.getBooleanInput(Inputs.Overwrite)
|
||||
|
||||
const ifNoFilesFound = core.getInput(Inputs.IfNoFilesFound)
|
||||
const noFileBehavior: NoFileOptions = NoFileOptions[ifNoFilesFound]
|
||||
@ -25,7 +26,8 @@ export function getInputs(): UploadInputs {
|
||||
const inputs = {
|
||||
artifactName: name,
|
||||
searchPath: path,
|
||||
ifNoFilesFound: noFileBehavior
|
||||
ifNoFilesFound: noFileBehavior,
|
||||
overwrite: overwrite
|
||||
} as UploadInputs
|
||||
|
||||
const retentionDaysStr = core.getInput(Inputs.RetentionDays)
|
||||
|
@ -1,10 +1,27 @@
|
||||
import * as core from '@actions/core'
|
||||
import * as github from '@actions/github'
|
||||
import artifact, {UploadArtifactOptions} from '@actions/artifact'
|
||||
import artifact, {
|
||||
UploadArtifactOptions,
|
||||
ArtifactNotFoundError
|
||||
} from '@actions/artifact'
|
||||
import {findFilesToUpload} from './search'
|
||||
import {getInputs} from './input-helper'
|
||||
import {NoFileOptions} from './constants'
|
||||
|
||||
async function deleteArtifactIfExists(artifactName: string): Promise<void> {
|
||||
try {
|
||||
await artifact.deleteArtifact(artifactName)
|
||||
} catch (error) {
|
||||
if (error instanceof ArtifactNotFoundError) {
|
||||
core.debug(`Skipping deletion of '${artifactName}', it does not exist`)
|
||||
return
|
||||
}
|
||||
|
||||
// Best effort, we don't want to fail the action if this fails
|
||||
core.debug(`Unable to delete artifact: ${(error as Error).message}`)
|
||||
}
|
||||
}
|
||||
|
||||
async function run(): Promise<void> {
|
||||
try {
|
||||
const inputs = getInputs()
|
||||
@ -38,6 +55,10 @@ async function run(): Promise<void> {
|
||||
)
|
||||
core.debug(`Root artifact directory is ${searchResult.rootDirectory}`)
|
||||
|
||||
if (inputs.overwrite) {
|
||||
await deleteArtifactIfExists(inputs.artifactName)
|
||||
}
|
||||
|
||||
const options: UploadArtifactOptions = {}
|
||||
if (inputs.retentionDays) {
|
||||
options.retentionDays = inputs.retentionDays
|
||||
|
@ -25,4 +25,9 @@ export interface UploadInputs {
|
||||
* The level of compression for Zlib to be applied to the artifact archive.
|
||||
*/
|
||||
compressionLevel?: number
|
||||
|
||||
/**
|
||||
* Whether or not to replace an existing artifact with the same name
|
||||
*/
|
||||
overwrite: boolean
|
||||
}
|
||||
|
Reference in New Issue
Block a user