mirror of
https://github.com/actions/toolkit.git
synced 2026-08-16 00:00:21 +02:00
Refactor the validation logic in uploadArtifact a bit
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
|
import * as fs from 'fs'
|
||||||
import * as path from 'path'
|
import * as path from 'path'
|
||||||
import {
|
import {
|
||||||
UploadArtifactOptions,
|
UploadArtifactOptions,
|
||||||
@@ -42,6 +43,10 @@ export async function uploadArtifact(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!fs.existsSync(files[0])) {
|
||||||
|
throw new FilesNotFoundError(files)
|
||||||
|
}
|
||||||
|
|
||||||
artifactFileName = path.basename(files[0])
|
artifactFileName = path.basename(files[0])
|
||||||
name = artifactFileName
|
name = artifactFileName
|
||||||
}
|
}
|
||||||
@@ -49,16 +54,18 @@ export async function uploadArtifact(
|
|||||||
validateArtifactName(name)
|
validateArtifactName(name)
|
||||||
validateRootDirectory(rootDirectory)
|
validateRootDirectory(rootDirectory)
|
||||||
|
|
||||||
const zipSpecification: UploadZipSpecification[] = getUploadZipSpecification(
|
let zipSpecification: UploadZipSpecification[] = []
|
||||||
files,
|
|
||||||
rootDirectory
|
|
||||||
)
|
|
||||||
|
|
||||||
if (!options?.skipArchive && zipSpecification.length === 0) {
|
if (!options?.skipArchive) {
|
||||||
throw new FilesNotFoundError(
|
zipSpecification = getUploadZipSpecification(files, rootDirectory)
|
||||||
zipSpecification.flatMap(s => (s.sourcePath ? [s.sourcePath] : []))
|
|
||||||
)
|
if (zipSpecification.length === 0) {
|
||||||
|
throw new FilesNotFoundError(
|
||||||
|
zipSpecification.flatMap(s => (s.sourcePath ? [s.sourcePath] : []))
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const contentType = getMimeType(artifactFileName)
|
const contentType = getMimeType(artifactFileName)
|
||||||
|
|
||||||
// get the IDs needed for the artifact creation
|
// get the IDs needed for the artifact creation
|
||||||
|
|||||||
Reference in New Issue
Block a user