Add if-no-files-found option to merge action

This commit is contained in:
Charlie Croom 2024-02-13 12:16:53 -05:00
parent 4c0ff1c489
commit 03a6dff9d4
No known key found for this signature in database
14 changed files with 202 additions and 44 deletions

View file

@ -57,6 +57,7 @@ const mockInputs = (overrides?: Partial<{[K in Inputs]?: any}>) => {
const inputs = {
[Inputs.Name]: 'my-merged-artifact',
[Inputs.Pattern]: '*',
[Inputs.IfNoFilesFound]: 'error',
[Inputs.SeparateDirectories]: false,
[Inputs.RetentionDays]: 0,
[Inputs.CompressionLevel]: 6,
@ -122,11 +123,44 @@ describe('merge', () => {
)
})
it('fails if no artifacts found', async () => {
it('supports error (by default) if no artifacts found', async () => {
mockInputs({[Inputs.Pattern]: 'this-does-not-match'})
expect(run()).rejects.toThrow()
await run()
expect(core.setFailed).toHaveBeenCalledWith(
`No artifacts were found with the provided pattern: this-does-not-match.`
)
expect(artifact.uploadArtifact).not.toBeCalled()
expect(artifact.downloadArtifact).not.toBeCalled()
})
it('supports warn if no artifacts found', async () => {
mockInputs({
[Inputs.Pattern]: 'this-does-not-match',
[Inputs.IfNoFilesFound]: 'warn'
})
await run()
expect(core.warning).toHaveBeenCalledWith(
`No artifacts were found with the provided pattern: this-does-not-match.`
)
expect(artifact.uploadArtifact).not.toBeCalled()
expect(artifact.downloadArtifact).not.toBeCalled()
})
it('supports ignore if no artifacts found', async () => {
mockInputs({
[Inputs.Pattern]: 'this-does-not-match',
[Inputs.IfNoFilesFound]: 'ignore'
})
await run()
expect(core.info).toHaveBeenCalledWith(
`No artifacts were found with the provided pattern: this-does-not-match.`
)
expect(artifact.uploadArtifact).not.toBeCalled()
expect(artifact.downloadArtifact).not.toBeCalled()
})