Fixes #55 Add artifact validation which check to ensure it's not a directory

This commit is contained in:
Nick Cipollo
2021-05-24 11:03:30 -04:00
parent 616708020f
commit 15abc13cc4
7 changed files with 198 additions and 12 deletions

View File

@@ -2,9 +2,10 @@ import * as core from '@actions/core';
import {Globber, FileGlobber} from "./Globber";
import {Artifact} from "./Artifact";
import untildify from "untildify";
import {ArtifactPathValidator} from "./ArtifactPathValidator";
export interface ArtifactGlobber {
globArtifactString(artifact: string, contentType: string, throwsWhenNoFiles: boolean): Artifact[]
globArtifactString(artifact: string, contentType: string, errorsFailBuild: boolean): Artifact[]
}
export class FileArtifactGlobber implements ArtifactGlobber {
@@ -14,24 +15,30 @@ export class FileArtifactGlobber implements ArtifactGlobber {
this.globber = globber
}
globArtifactString(artifact: string, contentType: string, throwsWhenNoFiles: boolean): Artifact[] {
globArtifactString(artifact: string, contentType: string, errorsFailBuild: boolean): Artifact[] {
return artifact.split(',')
.map(path => FileArtifactGlobber.expandPath(path))
.map(pattern => this.globPattern(pattern, throwsWhenNoFiles))
.map(pattern => this.globPattern(pattern, errorsFailBuild))
.map((globResult) => FileArtifactGlobber.validatePattern(errorsFailBuild, globResult[1], globResult[0]))
.reduce((accumulated, current) => accumulated.concat(current))
.map(path => new Artifact(path, contentType))
}
private globPattern(pattern: string, throwsWhenNoFiles: boolean): string[] {
private globPattern(pattern: string, errorsFailBuild: boolean): [string, string[]] {
const paths = this.globber.glob(pattern)
if (paths.length == 0) {
if (throwsWhenNoFiles) {
if (errorsFailBuild) {
FileArtifactGlobber.throwGlobError(pattern)
} else {
FileArtifactGlobber.reportGlobWarning(pattern)
}
}
return paths
return [pattern, paths]
}
private static validatePattern(errorsFailBuild: boolean, paths: string[], pattern: string): string[] {
const validator = new ArtifactPathValidator(errorsFailBuild, paths, pattern)
return validator.validate()
}
private static reportGlobWarning(pattern: string) {