mirror of
https://github.com/wagoid/commitlint-github-action.git
synced 2025-11-07 08:06:54 +00:00
Merge pull request #711 from cmitzel-ncino/failonerrors-cmitzel
feat(action): adds flag to optionally fail on errors
This commit is contained in:
commit
3b6f002df9
4 changed files with 60 additions and 6 deletions
|
|
@ -52,6 +52,12 @@ Whether you want to fail on warnings or not.
|
||||||
|
|
||||||
Default: `false`
|
Default: `false`
|
||||||
|
|
||||||
|
### `failOnErrors`
|
||||||
|
|
||||||
|
Whether you want to fail on errors or not. Still outputs the results, just forces the action to pass even if errors are detected.
|
||||||
|
|
||||||
|
Default: `true`
|
||||||
|
|
||||||
### `helpURL`
|
### `helpURL`
|
||||||
|
|
||||||
Link to a page explaining your commit message convention.
|
Link to a page explaining your commit message convention.
|
||||||
|
|
|
||||||
13
action.yml
13
action.yml
|
|
@ -3,7 +3,8 @@ description: Lints Pull Request commit messages with commitlint
|
||||||
author: Wagner Santos
|
author: Wagner Santos
|
||||||
inputs:
|
inputs:
|
||||||
configFile:
|
configFile:
|
||||||
description: Commitlint config file. If the file doesn't exist, config-conventional settings will be
|
description:
|
||||||
|
Commitlint config file. If the file doesn't exist, config-conventional settings will be
|
||||||
loaded as a fallback.
|
loaded as a fallback.
|
||||||
default: ./commitlint.config.js
|
default: ./commitlint.config.js
|
||||||
required: false
|
required: false
|
||||||
|
|
@ -12,19 +13,23 @@ inputs:
|
||||||
When set to true, we follow only the first parent commit when seeing a merge commit.
|
When set to true, we follow only the first parent commit when seeing a merge commit.
|
||||||
More info in git-log docs
|
More info in git-log docs
|
||||||
https://git-scm.com/docs/git-log#Documentation/git-log.txt---first-parent
|
https://git-scm.com/docs/git-log#Documentation/git-log.txt---first-parent
|
||||||
default: "true"
|
default: 'true'
|
||||||
required: false
|
required: false
|
||||||
failOnWarnings:
|
failOnWarnings:
|
||||||
description: Whether you want to fail on warnings or not
|
description: Whether you want to fail on warnings or not
|
||||||
default: "false"
|
default: 'false'
|
||||||
required: false
|
required: false
|
||||||
|
failOnErrors:
|
||||||
|
description: Whether you want to fail on errors or not
|
||||||
|
default: 'true'
|
||||||
|
required: true
|
||||||
helpURL:
|
helpURL:
|
||||||
description: Link to a page explaining your commit message convention
|
description: Link to a page explaining your commit message convention
|
||||||
default: https://github.com/conventional-changelog/commitlint/#what-is-commitlint
|
default: https://github.com/conventional-changelog/commitlint/#what-is-commitlint
|
||||||
required: false
|
required: false
|
||||||
commitDepth:
|
commitDepth:
|
||||||
description: When set to a valid Integer value - X, considers only the latest X number of commits.
|
description: When set to a valid Integer value - X, considers only the latest X number of commits.
|
||||||
default: ""
|
default: ''
|
||||||
required: false
|
required: false
|
||||||
token:
|
token:
|
||||||
description: >
|
description: >
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { existsSync } from 'fs'
|
import { existsSync } from 'fs'
|
||||||
import { resolve } from 'path'
|
import { resolve } from 'path'
|
||||||
import { getInput, setFailed } from '@actions/core'
|
import { getInput, setFailed, setOutput } from '@actions/core'
|
||||||
import { context as eventContext, getOctokit } from '@actions/github'
|
import { context as eventContext, getOctokit } from '@actions/github'
|
||||||
import lint from '@commitlint/lint'
|
import lint from '@commitlint/lint'
|
||||||
import { format } from '@commitlint/format'
|
import { format } from '@commitlint/format'
|
||||||
|
|
@ -145,6 +145,12 @@ const showLintResults = async ([from, to]) => {
|
||||||
|
|
||||||
if (hasOnlyWarnings(lintedCommits)) {
|
if (hasOnlyWarnings(lintedCommits)) {
|
||||||
handleOnlyWarnings(formattedResults)
|
handleOnlyWarnings(formattedResults)
|
||||||
|
} else if (formattedResults && getInput('failOnErrors') === 'false') {
|
||||||
|
// https://github.com/actions/toolkit/tree/master/packages/core#exit-codes
|
||||||
|
// this would be a good place to implement the setNeutral() when it's eventually implimented.
|
||||||
|
// for now it can pass with a check mark.
|
||||||
|
console.log('Passing despite errors ✅')
|
||||||
|
setOutput(`You have commit messages with errors\n\n${formattedResults}`)
|
||||||
} else if (formattedResults) {
|
} else if (formattedResults) {
|
||||||
setFailedAction(formattedResults)
|
setFailedAction(formattedResults)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -109,11 +109,48 @@ describe('Commit Linter action', () => {
|
||||||
td.replace(process, 'cwd', () => cwd)
|
td.replace(process, 'cwd', () => cwd)
|
||||||
|
|
||||||
await runAction()
|
await runAction()
|
||||||
|
|
||||||
td.verify(core.setFailed(contains('wrong message 1')))
|
td.verify(core.setFailed(contains('wrong message 1')))
|
||||||
td.verify(core.setFailed(contains('wrong message 2')))
|
td.verify(core.setFailed(contains('wrong message 2')))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should pass for push range with wrong messages with failOnErrors set to false', async () => {
|
||||||
|
td.when(core.getInput('failOnErrors')).thenReturn('false')
|
||||||
|
cwd = await git.bootstrap('fixtures/conventional')
|
||||||
|
await gitEmptyCommit(cwd, 'message from before push')
|
||||||
|
await gitEmptyCommit(cwd, 'wrong message 1')
|
||||||
|
await gitEmptyCommit(cwd, 'wrong message 2')
|
||||||
|
const [before, , to] = await getCommitHashes(cwd)
|
||||||
|
await createPushEventPayload(cwd, { before, to })
|
||||||
|
updatePushEnvVars(cwd, to)
|
||||||
|
td.replace(process, 'cwd', () => cwd)
|
||||||
|
td.replace(console, 'log')
|
||||||
|
|
||||||
|
await runAction()
|
||||||
|
|
||||||
|
td.verify(core.setFailed(), { times: 0, ignoreExtraArgs: true })
|
||||||
|
td.verify(console.log(contains('Passing despite errors ✅')))
|
||||||
|
td.verify(core.setOutput(contains('wrong message 1')))
|
||||||
|
td.verify(core.setOutput(contains('wrong message 2')))
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should pass for push range with correct messages with failOnErrors set to false', async () => {
|
||||||
|
td.when(core.getInput('failOnErrors')).thenReturn('false')
|
||||||
|
cwd = await git.bootstrap('fixtures/conventional')
|
||||||
|
await gitEmptyCommit(cwd, 'message from before push')
|
||||||
|
await gitEmptyCommit(cwd, 'chore: correct message 1')
|
||||||
|
await gitEmptyCommit(cwd, 'chore: correct message 2')
|
||||||
|
const [before, , to] = await getCommitHashes(cwd)
|
||||||
|
await createPushEventPayload(cwd, { before, to })
|
||||||
|
updatePushEnvVars(cwd, to)
|
||||||
|
td.replace(process, 'cwd', () => cwd)
|
||||||
|
td.replace(console, 'log')
|
||||||
|
|
||||||
|
await runAction()
|
||||||
|
|
||||||
|
td.verify(core.setFailed(), { times: 0, ignoreExtraArgs: true })
|
||||||
|
td.verify(console.log('Lint free! 🎉'))
|
||||||
|
})
|
||||||
|
|
||||||
it('should pass for push range with correct messages', async () => {
|
it('should pass for push range with correct messages', async () => {
|
||||||
cwd = await git.bootstrap('fixtures/conventional')
|
cwd = await git.bootstrap('fixtures/conventional')
|
||||||
await gitEmptyCommit(cwd, 'message from before push')
|
await gitEmptyCommit(cwd, 'message from before push')
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue