Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update to fail the job if the patterns are invalid #626

Merged
13 changes: 4 additions & 9 deletions src/__tests__/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {ExitCode} from '@actions/core'
jackton1 marked this conversation as resolved.
Show resolved Hide resolved
import * as core from '@actions/core'
import {run} from '../main'

Expand Down Expand Up @@ -379,18 +380,12 @@ test('matched file patterns with braces are expanded', async () => {
expect(core.setOutput).toHaveBeenNthCalledWith(2, 'paths', EXPECTED_FILENAMES)
})

test('warnings are logged when files are not found', async () => {
test('error raised when files are not found', async () => {
mockedEnv({
...defaultEnv,
INPUT_FILES: 'src/__tests__/not-found.txt'
})

// @ts-ignore
core.warning = jest.fn()

await run()

expect(core.warning).toHaveBeenCalledWith(
'No paths found using the specified patterns'
)
const expectedError = new Error('No paths found using the specified patterns')
await expect(run()).rejects.toThrow(expectedError)
})
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ export async function run(): Promise<void> {
core.saveState('paths-output-file', pathsOutputFile)
core.info(`Successfully created paths-output-file: ${pathsOutputFile}`)
} else if (hasCustomPatterns) {
core.warning('No paths found using the specified patterns')
throw new Error('No paths found using the specified patterns')
}

core.setOutput('paths', pathsOutput)
Expand Down
8 changes: 5 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export async function deletedGitFiles({
})

if (topDirStderr || topDirExitCode !== 0) {
core.setFailed(topDirStderr || 'An unexpected error occurred')
throw new Error(topDirStderr || 'An unexpected error occurred')
}

const topLevelDir = topDirStdout.trim()
Expand All @@ -63,7 +63,7 @@ export async function deletedGitFiles({
)

if (stderr || exitCode !== 0) {
core.setFailed(stderr || 'An unexpected error occurred')
throw new Error(stderr || 'An unexpected error occurred')
}

const deletedFiles = stdout
Expand Down Expand Up @@ -150,7 +150,9 @@ async function* lineOfFileGenerator({
excludedFiles: boolean
}): AsyncIterableIterator<string> {
const fileStream = createReadStream(filePath)
fileStream.on('error', (error: string | Error) => core.setFailed(error))
fileStream.on('error', error => {
throw error
})
const rl = createInterface({
input: fileStream,
crlfDelay: Infinity
Expand Down