5
0
Fork 0
mirror of https://github.com/wagoid/commitlint-github-action.git synced 2025-11-07 08:06:54 +00:00

fix: stop trying to issue commands on failures

Commands are disabled, so we should not use `core.setFailed` on errors anymore.

Closes #70
This commit is contained in:
Wagner Santos 2021-01-28 19:26:01 -03:00
parent 15aa3a746a
commit 1128358de3
2 changed files with 35 additions and 32 deletions

View file

@ -109,7 +109,9 @@ const hasOnlyWarnings = lintedCommits =>
lintedCommits.some(({ lintResult }) => lintResult.warnings.length)
const setFailed = formattedResults => {
core.setFailed(`You have commit messages with errors\n\n${formattedResults}`)
process.exitCode = 1
console.error(`You have commit messages with errors\n\n${formattedResults}`)
}
const handleOnlyWarnings = formattedResults => {
@ -153,7 +155,9 @@ const showLintResults = async ([from, to]) => {
}
const exitWithMessage = message => error => {
core.setFailed(`${message}\n${error.message}\n${error.stack}`)
process.exitCode = 1
console.error(`${message}\n${error.message}\n${error.stack}`)
}
const commitLinterAction = () =>

View file

@ -44,8 +44,9 @@ describe('Commit Linter action', () => {
beforeEach(() => {
core = require('@actions/core')
td.replace(core, 'getInput')
td.replace(core, 'setFailed')
td.replace(core, 'setOutput')
td.replace(console, 'log')
td.replace(console, 'error')
td.when(core.getInput('configFile')).thenReturn('./commitlint.config.js')
td.when(core.getInput('firstParent')).thenReturn('true')
td.when(core.getInput('failOnWarnings')).thenReturn('false')
@ -71,7 +72,8 @@ describe('Commit Linter action', () => {
await runAction()
td.verify(core.setFailed(contains('You have commit messages with errors')))
td.verify(console.error(contains('You have commit messages with errors')))
expect(process.exitCode).toBe(1)
})
it('should fail for single push with incorrect message', async () => {
@ -84,7 +86,7 @@ describe('Commit Linter action', () => {
await runAction()
td.verify(core.setFailed(contains('You have commit messages with errors')))
td.verify(console.error(contains('You have commit messages with errors')))
})
it('should fail for push range with wrong messages', async () => {
@ -99,8 +101,8 @@ describe('Commit Linter action', () => {
await runAction()
td.verify(core.setFailed(contains('wrong message 1')))
td.verify(core.setFailed(contains('wrong message 2')))
td.verify(console.error(contains('wrong message 1')))
td.verify(console.error(contains('wrong message 2')))
})
it('should pass for push range with correct messages', async () => {
@ -116,7 +118,7 @@ describe('Commit Linter action', () => {
await runAction()
td.verify(core.setFailed(), { times: 0, ignoreExtraArgs: true })
td.verify(console.error(), { times: 0, ignoreExtraArgs: true })
td.verify(console.log('Lint free! 🎉'))
})
@ -138,8 +140,8 @@ describe('Commit Linter action', () => {
'Commit was forced, checking only the latest commit from push instead of a range of commit messages',
),
)
td.verify(core.setFailed(contains('wrong message 1')), { times: 0 })
td.verify(core.setFailed(contains('wrong message 2')))
td.verify(console.error(contains('wrong message 1')), { times: 0 })
td.verify(console.error(contains('wrong message 2')))
})
it('should lint only last commit when "before" field is an empty sha', async () => {
@ -155,8 +157,8 @@ describe('Commit Linter action', () => {
await runAction()
td.verify(core.setFailed(contains('wrong message 1')), { times: 0 })
td.verify(core.setFailed(contains('chore(WRONG): message 2')))
td.verify(console.error(contains('wrong message 1')), { times: 0 })
td.verify(console.error(contains('chore(WRONG): message 2')))
})
it('should fail for commit with scope that is not a lerna package', async () => {
@ -171,7 +173,7 @@ describe('Commit Linter action', () => {
await runAction()
td.verify(
core.setFailed(contains('chore(wrong): not including package scope')),
console.error(contains('chore(wrong): not including package scope')),
)
})
@ -201,23 +203,21 @@ describe('Commit Linter action', () => {
await runAction()
td.verify(console.error(contains('ib-21212121212121: without jira ticket')))
td.verify(
core.setFailed(contains('ib-21212121212121: without jira ticket')),
)
td.verify(
core.setFailed(
console.error(
contains(
'ib-21212121212121 taskId must not be loonger than 9 characters',
),
),
)
td.verify(
core.setFailed(
console.error(
contains('ib-21212121212121 taskId must be uppercase case'),
),
)
td.verify(
core.setFailed(
console.error(
contains('ib-21212121212121 commitStatus must be uppercase case'),
),
)
@ -258,7 +258,7 @@ describe('Commit Linter action', () => {
await runAction()
td.verify(core.setFailed(contains('wrong commit from another branch')))
td.verify(console.error(contains('wrong commit from another branch')))
})
describe('when there are multiple commits failing in the pull request', () => {
@ -307,7 +307,7 @@ describe('Commit Linter action', () => {
it('should NOT show errors for a message from before the push', async () => {
await runAction()
td.verify(core.setFailed(contains('message from before push')), {
td.verify(console.error(contains('message from before push')), {
times: 0,
})
})
@ -315,13 +315,13 @@ describe('Commit Linter action', () => {
it('should show errors for the first wrong message', async () => {
await runAction()
td.verify(core.setFailed(contains(firstMessage)))
td.verify(console.error(contains(firstMessage)))
})
it('should show errors for the second wrong message', async () => {
await runAction()
td.verify(core.setFailed(contains(secondMessage)))
td.verify(console.error(contains(secondMessage)))
})
it('should generate a JSON output of the errors', async () => {
@ -352,8 +352,9 @@ describe('Commit Linter action', () => {
it('should show an error message', async () => {
await runAction()
expect(process.exitCode).toBe(1)
td.verify(
core.setFailed(
console.error(
contains("error trying to get list of pull request's commits"),
),
)
@ -362,7 +363,7 @@ describe('Commit Linter action', () => {
it('should show the original error message', async () => {
await runAction()
td.verify(core.setFailed(contains('HttpError: Bad credentials')))
td.verify(console.error(contains('HttpError: Bad credentials')))
})
})
@ -383,7 +384,7 @@ describe('Commit Linter action', () => {
it('should pass', async () => {
await runAction()
td.verify(core.setFailed(), { times: 0, ignoreExtraArgs: true })
td.verify(console.error(), { times: 0, ignoreExtraArgs: true })
})
it('should show success message', async () => {
@ -448,7 +449,7 @@ describe('Commit Linter action', () => {
it('should pass and show that warnings exist', async () => {
await runAction()
td.verify(core.setFailed(), { times: 0, ignoreExtraArgs: true })
td.verify(console.error(), { times: 0, ignoreExtraArgs: true })
td.verify(console.log(contains('You have commit messages with warnings')))
})
@ -467,7 +468,7 @@ describe('Commit Linter action', () => {
await runAction()
td.verify(
core.setFailed(contains('You have commit messages with errors')),
console.error(contains('You have commit messages with errors')),
)
})
@ -503,9 +504,7 @@ describe('Commit Linter action', () => {
it('should fail', async () => {
await runAction()
td.verify(
core.setFailed(contains('You have commit messages with errors')),
)
td.verify(console.error(contains('You have commit messages with errors')))
})
it('should show the results in an output', async () => {
@ -541,7 +540,7 @@ describe('Commit Linter action', () => {
await runAction()
td.verify(
core.setFailed(contains('You have commit messages with errors')),
console.error(contains('You have commit messages with errors')),
)
})
})