add new overwrite input & docs

This commit is contained in:
Rob Herley
2024-01-18 13:31:03 -05:00
parent 1eb3cb2b3e
commit 11ff42c7b1
10 changed files with 536 additions and 26 deletions

View File

@ -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 {

View File

@ -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)

View File

@ -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

View File

@ -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
}