2020-04-28 17:18:53 +02:00
|
|
|
import * as core from '@actions/core'
|
|
|
|
import {create, UploadOptions} from '@actions/artifact'
|
|
|
|
import {findFilesToUpload} from './search'
|
2020-07-31 17:27:37 +02:00
|
|
|
import {getInputs} from './input-helper'
|
|
|
|
import {NoFileOptions} from './constants'
|
2020-04-28 17:18:53 +02:00
|
|
|
|
|
|
|
async function run(): Promise<void> {
|
|
|
|
try {
|
2020-07-31 17:27:37 +02:00
|
|
|
const inputs = getInputs()
|
|
|
|
const searchResult = await findFilesToUpload(inputs.searchPath)
|
2020-04-28 17:18:53 +02:00
|
|
|
if (searchResult.filesToUpload.length === 0) {
|
2020-07-31 17:27:37 +02:00
|
|
|
// 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
|
|
|
|
}
|
|
|
|
}
|
2020-04-28 17:18:53 +02:00
|
|
|
} else {
|
2021-01-04 11:24:12 +01:00
|
|
|
const s = searchResult.filesToUpload.length === 1 ? '' : 's'
|
2020-04-28 17:18:53 +02:00
|
|
|
core.info(
|
2021-01-04 11:24:12 +01:00
|
|
|
`With the provided path, there will be ${searchResult.filesToUpload.length} file${s} uploaded`
|
2020-04-28 17:18:53 +02:00
|
|
|
)
|
|
|
|
core.debug(`Root artifact directory is ${searchResult.rootDirectory}`)
|
|
|
|
|
2021-02-08 21:09:20 +01:00
|
|
|
if (searchResult.filesToUpload.length > 10000) {
|
|
|
|
core.warning(
|
2021-05-23 14:33:18 +02:00
|
|
|
`There are over 10,000 files in this artifact, consider creating an archive before upload to improve the upload performance.`
|
2021-02-08 21:09:20 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-04-28 17:18:53 +02:00
|
|
|
const artifactClient = create()
|
|
|
|
const options: UploadOptions = {
|
2020-05-18 15:43:29 +02:00
|
|
|
continueOnError: false
|
2020-04-28 17:18:53 +02:00
|
|
|
}
|
2020-08-27 19:39:36 +02:00
|
|
|
if (inputs.retentionDays) {
|
|
|
|
options.retentionDays = inputs.retentionDays
|
|
|
|
}
|
|
|
|
|
2020-05-18 15:43:29 +02:00
|
|
|
const uploadResponse = await artifactClient.uploadArtifact(
|
2020-07-31 17:27:37 +02:00
|
|
|
inputs.artifactName,
|
2020-04-28 17:18:53 +02:00
|
|
|
searchResult.filesToUpload,
|
|
|
|
searchResult.rootDirectory,
|
|
|
|
options
|
|
|
|
)
|
|
|
|
|
2020-05-18 15:43:29 +02:00
|
|
|
if (uploadResponse.failedItems.length > 0) {
|
|
|
|
core.setFailed(
|
|
|
|
`An error was encountered when uploading ${uploadResponse.artifactName}. There were ${uploadResponse.failedItems.length} items that failed to upload.`
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
core.info(
|
|
|
|
`Artifact ${uploadResponse.artifactName} has been successfully uploaded!`
|
|
|
|
)
|
|
|
|
}
|
2020-04-28 17:18:53 +02:00
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
core.setFailed(err.message)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
run()
|