Skip to content

Commit

Permalink
Merge pull request #626 from tj-actions/feat/update-to-fail-the-job-i…
Browse files Browse the repository at this point in the history
…f-the-patterns-are-invalid

feat: update to fail the job if the patterns are invalid
  • Loading branch information
repo-ranger[bot] committed Jan 18, 2023
2 parents 70ce922 + f36ffdd commit 9923edc
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 20 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,17 @@ jobs:
- name: Run glob with invalid patterns
uses: ./
id: glob-invalid
continue-on-error: true
with:
files: |
- *.md
- name: Exit with 1 if no error is raised
if: steps.glob-invalid.outcome != 'failure'
run: |
echo "Expected: (failure) got ${{ steps.changed-files.outcome }}"
exit 1
- name: Show output
if: steps.glob-invalid.outputs.paths != '' || steps.glob-invalid.outputs.paths-output-file != ''
run: |
Expand Down
11 changes: 6 additions & 5 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

12 changes: 3 additions & 9 deletions src/__tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,18 +379,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)
})
3 changes: 1 addition & 2 deletions 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 All @@ -288,6 +288,5 @@ if (!process.env.TESTING) {
// eslint-disable-next-line github/no-then
run().catch(e => {
core.setFailed(e.message || e)
throw e
})
}
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

0 comments on commit 9923edc

Please sign in to comment.