1
0
Fork 0
mirror of https://code.forgejo.org/forgejo/upload-artifact.git synced 2024-11-12 12:22:38 +00:00
frg-upload-artifact/src/upload-artifact.ts
Rob Herley 40c8ff5a04
.
2023-12-06 17:34:03 -05:00

82 lines
2.6 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import log from 'why-is-node-running'
import * as core from '../node_modules/@actions/core/'
import artifact, {
UploadArtifactOptions
} from '../node_modules/@actions/artifact/lib/artifact'
import {findFilesToUpload} from './search'
import {getInputs} from './input-helper'
import {NoFileOptions} from './constants'
async function run(): Promise<void> {
try {
const inputs = getInputs()
const searchResult = await findFilesToUpload(inputs.searchPath)
if (searchResult.filesToUpload.length === 0) {
// No files were found, different use cases warrant different types of behavior if nothing is found
switch (inputs.ifNoFilesFound) {
case NoFileOptions.warn: {
core.warning(
`No files were found with the provided path: ${inputs.searchPath}. No artifacts will be uploaded.`
)
break
}
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'
core.info(
`With the provided path, there will be ${searchResult.filesToUpload.length} file${s} uploaded`
)
core.debug(`Root artifact directory is ${searchResult.rootDirectory}`)
const options: UploadArtifactOptions = {}
if (inputs.retentionDays) {
options.retentionDays = inputs.retentionDays
}
if (typeof inputs.compressionLevel !== 'undefined') {
options.compressionLevel = inputs.compressionLevel
}
const uploadResponse = await artifact.uploadArtifact(
inputs.artifactName,
searchResult.filesToUpload,
searchResult.rootDirectory,
options
)
core.info(
`Artifact ${inputs.artifactName} has been successfully uploaded! Final size is ${uploadResponse.size} bytes. Artifact ID is ${uploadResponse.id}`
)
core.setOutput('artifact-id', uploadResponse.id)
}
} catch (error) {
core.setFailed((error as Error).message)
setTimeout(function () {
core.notice(' why-is-node-running')
log()
}, 100)
setTimeout(function () {
core.notice(' why-is-node-running')
log()
}, 10000)
setTimeout(function () {
core.notice(' why-is-node-running')
log()
}, 30000)
}
}
run()