Fixes #32 Globber will now expand tilde and warn if no results are found

This commit is contained in:
Nick Cipollo
2021-03-12 12:39:55 -05:00
parent f7b694c6d5
commit 5b1448e480
6 changed files with 129 additions and 21 deletions

View File

@@ -1,5 +1,7 @@
import { Globber, FileGlobber } from "./Globber";
import { Artifact } from "./Artifact";
import * as core from '@actions/core';
import {Globber, FileGlobber} from "./Globber";
import {Artifact} from "./Artifact";
import untildify from "untildify";
export interface ArtifactGlobber {
globArtifactString(artifact: string, contentType: string): Artifact[]
@@ -14,9 +16,25 @@ export class FileArtifactGlobber implements ArtifactGlobber {
globArtifactString(artifact: string, contentType: string): Artifact[] {
return artifact.split(',')
.map((path) => this.globber.glob(path))
.map(path => FileArtifactGlobber.expandPath(path))
.map(pattern => this.globPattern(pattern))
.reduce((accumulated, current) => accumulated.concat(current))
.map((path) => new Artifact(path, contentType))
.map(path => new Artifact(path, contentType))
}
}
private globPattern(pattern: string): string[] {
const paths = this.globber.glob(pattern)
if (paths.length == 0) {
FileArtifactGlobber.reportGlobWarning(pattern)
}
return paths
}
private static reportGlobWarning(pattern: string) {
core.warning(`Artifact pattern :${pattern} did not match any files`)
}
private static expandPath(path: string): string {
return untildify(path)
}
}