Skip to content

Commit

Permalink
Fixes #136 Globber now also supports new line as separator.
Browse files Browse the repository at this point in the history
  • Loading branch information
ncipollo committed Oct 25, 2021
1 parent 15ede53 commit 01e1051
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
17 changes: 16 additions & 1 deletion __tests__/ArtifactGlobber.test.ts
Expand Up @@ -54,7 +54,7 @@ describe("ArtifactGlobber", () => {
expect(warnMock).not.toBeCalled()
})

it("splits multiple paths", () => {
it("splits multiple paths with comma separator", () => {
const globber = createArtifactGlobber()

const expectedArtifacts =
Expand All @@ -69,6 +69,21 @@ describe("ArtifactGlobber", () => {
expect(warnMock).not.toBeCalled()
})

it("splits multiple paths with new line separator and trims start", () => {
const globber = createArtifactGlobber()

const expectedArtifacts =
globResults
.concat(globResults)
.map((path) => new Artifact(path, contentType))

expect(globber.globArtifactString('path1\n path2', 'raw', false))
.toEqual(expectedArtifacts)
expect(globMock).toBeCalledWith('path1')
expect(globMock).toBeCalledWith('path2')
expect(warnMock).not.toBeCalled()
})

it("warns when no glob results are produced and empty results shouldn't throw", () => {
const globber = createArtifactGlobber([])

Expand Down
4 changes: 3 additions & 1 deletion lib/ArtifactGlobber.js
Expand Up @@ -33,7 +33,9 @@ class FileArtifactGlobber {
this.globber = globber;
}
globArtifactString(artifact, contentType, errorsFailBuild) {
return artifact.split(',')
const split = /[,\n]/;
return artifact.split(split)
.map(path => path.trimStart())
.map(path => FileArtifactGlobber.expandPath(path))
.map(pattern => this.globPattern(pattern, errorsFailBuild))
.map((globResult) => FileArtifactGlobber.validatePattern(errorsFailBuild, globResult[1], globResult[0]))
Expand Down
4 changes: 3 additions & 1 deletion src/ArtifactGlobber.ts
Expand Up @@ -16,7 +16,9 @@ export class FileArtifactGlobber implements ArtifactGlobber {
}

globArtifactString(artifact: string, contentType: string, errorsFailBuild: boolean): Artifact[] {
return artifact.split(',')
const split = /[,\n]/
return artifact.split(split)
.map(path => path.trimStart())
.map(path => FileArtifactGlobber.expandPath(path))
.map(pattern => this.globPattern(pattern, errorsFailBuild))
.map((globResult) => FileArtifactGlobber.validatePattern(errorsFailBuild, globResult[1], globResult[0]))
Expand Down

0 comments on commit 01e1051

Please sign in to comment.