mirror of
https://github.com/wagoid/commitlint-github-action.git
synced 2025-11-07 08:06:54 +00:00
parent
4b0886537a
commit
550792f0ca
7 changed files with 137 additions and 5 deletions
44
README.md
44
README.md
|
|
@ -54,6 +54,50 @@ 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`
|
||||||
|
|
||||||
|
## Outputs
|
||||||
|
|
||||||
|
### `results`
|
||||||
|
|
||||||
|
The error and warning messages for each one of the analyzed commits. This is useful if you want to use the commitlint results in a JSON format in other jobs. See [the documentation](https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#fromjson) on how to read JSON information from outputs.
|
||||||
|
|
||||||
|
Below you can see an example text output together with its corresponding JSON output:
|
||||||
|
|
||||||
|
```
|
||||||
|
You have commit messages with errors
|
||||||
|
|
||||||
|
⧗ input: wrong message
|
||||||
|
✖ subject may not be empty [subject-empty]
|
||||||
|
✖ type may not be empty [type-empty]
|
||||||
|
|
||||||
|
✖ found 2 problems, 0 warnings
|
||||||
|
ⓘ Get help: https://github.com/conventional-changelog/commitlint/#what-is-commitlint
|
||||||
|
|
||||||
|
⧗ input: chore: my message
|
||||||
|
⚠ body must have leading blank line [body-leading-blank]
|
||||||
|
|
||||||
|
⚠ found 0 problems, 1 warnings
|
||||||
|
ⓘ Get help: https://github.com/conventional-changelog/commitlint/#what-is-commitlint
|
||||||
|
```
|
||||||
|
|
||||||
|
```JSON
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"hash": "cb0f846f13b490c2fd17bd5ed0b6f65ba9b86c75",
|
||||||
|
"message": "wrong message",
|
||||||
|
"valid": false,
|
||||||
|
"errors": ["subject may not be empty", "type may not be empty"],
|
||||||
|
"warnings": [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hash": "cb14483cbde23b61322ffb8d3fcdc87f514a3141",
|
||||||
|
"message": "chore: my message\n\nsome context without leading blank line",
|
||||||
|
"valid": true,
|
||||||
|
"errors": [],
|
||||||
|
"warnings": ["body must have leading blank line"],
|
||||||
|
},
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
## About `extends` in your config file
|
## About `extends` in your config file
|
||||||
|
|
||||||
This is a [`Docker` action](https://github.com/actions/toolkit/blob/e2adf403d6d14a9ca7474976ccaca20f72ff8209/docs/action-types.md#why-would-i-choose-a-docker-action), and was made like this so that you can run it with minimum setup, regardless of your repo's environment. It comes packed with the most famous shared configurations that you can use in your commitlint config's `extends` field:
|
This is a [`Docker` action](https://github.com/actions/toolkit/blob/e2adf403d6d14a9ca7474976ccaca20f72ff8209/docs/action-types.md#why-would-i-choose-a-docker-action), and was made like this so that you can run it with minimum setup, regardless of your repo's environment. It comes packed with the most famous shared configurations that you can use in your commitlint config's `extends` field:
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ const lint = require('@commitlint/lint')
|
||||||
const { format } = require('@commitlint/format')
|
const { format } = require('@commitlint/format')
|
||||||
const load = require('@commitlint/load')
|
const load = require('@commitlint/load')
|
||||||
const gitCommits = require('./gitCommits')
|
const gitCommits = require('./gitCommits')
|
||||||
|
const generateOutputs = require('./generateOutputs')
|
||||||
|
|
||||||
const pullRequestEvent = 'pull_request'
|
const pullRequestEvent = 'pull_request'
|
||||||
|
|
||||||
|
|
@ -134,6 +135,8 @@ const showLintResults = async ([from, to]) => {
|
||||||
)
|
)
|
||||||
const formattedResults = formatErrors(lintedCommits)
|
const formattedResults = formatErrors(lintedCommits)
|
||||||
|
|
||||||
|
generateOutputs(lintedCommits)
|
||||||
|
|
||||||
if (hasOnlyWarnings(lintedCommits)) {
|
if (hasOnlyWarnings(lintedCommits)) {
|
||||||
handleOnlyWarnings(formattedResults)
|
handleOnlyWarnings(formattedResults)
|
||||||
} else if (formattedResults) {
|
} else if (formattedResults) {
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,8 @@ const {
|
||||||
updatePullRequestEnvVars,
|
updatePullRequestEnvVars,
|
||||||
} = require('./testUtils')
|
} = require('./testUtils')
|
||||||
|
|
||||||
|
const resultsOutputId = 'results'
|
||||||
|
|
||||||
const {
|
const {
|
||||||
matchers: { contains },
|
matchers: { contains },
|
||||||
} = td
|
} = td
|
||||||
|
|
@ -43,6 +45,7 @@ describe('Commit Linter action', () => {
|
||||||
core = require('@actions/core')
|
core = require('@actions/core')
|
||||||
td.replace(core, 'getInput')
|
td.replace(core, 'getInput')
|
||||||
td.replace(core, 'setFailed')
|
td.replace(core, 'setFailed')
|
||||||
|
td.replace(core, 'setOutput')
|
||||||
td.when(core.getInput('configFile')).thenReturn('./commitlint.config.js')
|
td.when(core.getInput('configFile')).thenReturn('./commitlint.config.js')
|
||||||
td.when(core.getInput('firstParent')).thenReturn('true')
|
td.when(core.getInput('firstParent')).thenReturn('true')
|
||||||
td.when(core.getInput('failOnWarnings')).thenReturn('false')
|
td.when(core.getInput('failOnWarnings')).thenReturn('false')
|
||||||
|
|
@ -317,6 +320,8 @@ describe('Commit Linter action', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('when all errors are just warnings', () => {
|
describe('when all errors are just warnings', () => {
|
||||||
|
let expectedResultsOutput
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
cwd = await git.bootstrap('fixtures/conventional')
|
cwd = await git.bootstrap('fixtures/conventional')
|
||||||
await gitEmptyCommit(
|
await gitEmptyCommit(
|
||||||
|
|
@ -328,6 +333,17 @@ describe('Commit Linter action', () => {
|
||||||
updatePushEnvVars(cwd, to)
|
updatePushEnvVars(cwd, to)
|
||||||
td.replace(process, 'cwd', () => cwd)
|
td.replace(process, 'cwd', () => cwd)
|
||||||
td.replace(console, 'log')
|
td.replace(console, 'log')
|
||||||
|
|
||||||
|
expectedResultsOutput = [
|
||||||
|
{
|
||||||
|
hash: to,
|
||||||
|
message:
|
||||||
|
'chore: correct message\n\nsome context without leading blank line',
|
||||||
|
valid: true,
|
||||||
|
errors: [],
|
||||||
|
warnings: ['body must have leading blank line'],
|
||||||
|
},
|
||||||
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should pass and show that warnings exist', async () => {
|
it('should pass and show that warnings exist', async () => {
|
||||||
|
|
@ -337,6 +353,12 @@ describe('Commit Linter action', () => {
|
||||||
td.verify(console.log(contains('You have commit messages with warnings')))
|
td.verify(console.log(contains('You have commit messages with warnings')))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should show the results in an output', async () => {
|
||||||
|
await runAction()
|
||||||
|
|
||||||
|
td.verify(core.setOutput(resultsOutputId, expectedResultsOutput))
|
||||||
|
})
|
||||||
|
|
||||||
describe('and failOnWarnings is set to true', () => {
|
describe('and failOnWarnings is set to true', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
td.when(core.getInput('failOnWarnings')).thenReturn('true')
|
td.when(core.getInput('failOnWarnings')).thenReturn('true')
|
||||||
|
|
@ -349,18 +371,30 @@ describe('Commit Linter action', () => {
|
||||||
core.setFailed(contains('You have commit messages with errors')),
|
core.setFailed(contains('You have commit messages with errors')),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should show the results in an output', async () => {
|
||||||
|
await runAction()
|
||||||
|
|
||||||
|
td.verify(core.setOutput(resultsOutputId, expectedResultsOutput))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('when a subset of errors are just warnings', () => {
|
describe('when a subset of errors are just warnings', () => {
|
||||||
|
let firstHash
|
||||||
|
let secondHash
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
cwd = await git.bootstrap('fixtures/conventional')
|
cwd = await git.bootstrap('fixtures/conventional')
|
||||||
|
await gitEmptyCommit(cwd, 'message from before push')
|
||||||
await gitEmptyCommit(
|
await gitEmptyCommit(
|
||||||
cwd,
|
cwd,
|
||||||
'chore: correct message\nsome context without leading blank line',
|
'chore: correct message\nsome context without leading blank line',
|
||||||
)
|
)
|
||||||
await gitEmptyCommit(cwd, 'wrong message')
|
await gitEmptyCommit(cwd, 'wrong message')
|
||||||
const [before, to] = await getCommitHashes(cwd)
|
const [before, firstCommit, to] = await getCommitHashes(cwd)
|
||||||
|
firstHash = firstCommit
|
||||||
|
secondHash = to
|
||||||
await createPushEventPayload(cwd, { before, to })
|
await createPushEventPayload(cwd, { before, to })
|
||||||
updatePushEnvVars(cwd, to)
|
updatePushEnvVars(cwd, to)
|
||||||
td.replace(process, 'cwd', () => cwd)
|
td.replace(process, 'cwd', () => cwd)
|
||||||
|
|
@ -375,6 +409,30 @@ describe('Commit Linter action', () => {
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should show the results in an output', async () => {
|
||||||
|
await runAction()
|
||||||
|
|
||||||
|
const expectedResultsOutput = [
|
||||||
|
{
|
||||||
|
hash: secondHash,
|
||||||
|
message: 'wrong message',
|
||||||
|
valid: false,
|
||||||
|
errors: ['subject may not be empty', 'type may not be empty'],
|
||||||
|
warnings: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
hash: firstHash,
|
||||||
|
message:
|
||||||
|
'chore: correct message\n\nsome context without leading blank line',
|
||||||
|
valid: true,
|
||||||
|
errors: [],
|
||||||
|
warnings: ['body must have leading blank line'],
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
td.verify(core.setOutput(resultsOutputId, expectedResultsOutput))
|
||||||
|
})
|
||||||
|
|
||||||
describe('and failOnWarnings is set to true', () => {
|
describe('and failOnWarnings is set to true', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
td.when(core.getInput('failOnWarnings')).thenReturn('true')
|
td.when(core.getInput('failOnWarnings')).thenReturn('true')
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,9 @@ inputs:
|
||||||
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
|
||||||
|
outputs:
|
||||||
|
results:
|
||||||
|
description: The error and warning messages for each one of the analyzed commits
|
||||||
runs:
|
runs:
|
||||||
using: 'docker'
|
using: 'docker'
|
||||||
image: 'docker://wagoid/commitlint-github-action:1.7.0'
|
image: 'docker://wagoid/commitlint-github-action:1.7.0'
|
||||||
|
|
|
||||||
24
generateOutputs.js
Normal file
24
generateOutputs.js
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
const core = require('@actions/core')
|
||||||
|
|
||||||
|
const resultsOutputId = 'results'
|
||||||
|
|
||||||
|
const mapMessageValidation = item => item.message
|
||||||
|
|
||||||
|
const mapResultOutput = ({
|
||||||
|
hash,
|
||||||
|
lintResult: { valid, errors, warnings, input },
|
||||||
|
}) => ({
|
||||||
|
hash,
|
||||||
|
message: input,
|
||||||
|
valid,
|
||||||
|
errors: errors.map(mapMessageValidation),
|
||||||
|
warnings: warnings.map(mapMessageValidation),
|
||||||
|
})
|
||||||
|
|
||||||
|
const generateOutputs = lintedCommits => {
|
||||||
|
const resultsOutput = lintedCommits.map(mapResultOutput)
|
||||||
|
|
||||||
|
core.setOutput(resultsOutputId, resultsOutput)
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = generateOutputs
|
||||||
6
package-lock.json
generated
6
package-lock.json
generated
|
|
@ -5,9 +5,9 @@
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": {
|
"@actions/core": {
|
||||||
"version": "1.1.1",
|
"version": "1.2.4",
|
||||||
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.4.tgz",
|
||||||
"integrity": "sha512-O5G6EmlzTVsng7VSpNtszIoQq6kOgMGNTFB/hmwKNNA4V71JyxImCIrL27vVHCt2Cb3ImkaCr6o27C2MV9Ylwg=="
|
"integrity": "sha512-YJCEq8BE3CdN8+7HPZ/4DxJjk/OkZV2FFIf+DlZTC/4iBlzYCD5yjRR6eiOS5llO11zbRltIRuKAjMKaWTE6cg=="
|
||||||
},
|
},
|
||||||
"@actions/github": {
|
"@actions/github": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"homepage": "https://github.com/wagoid/commitlint-github-action",
|
"homepage": "https://github.com/wagoid/commitlint-github-action",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.1.1",
|
"@actions/core": "^1.2.4",
|
||||||
"@actions/github": "^1.1.0",
|
"@actions/github": "^1.1.0",
|
||||||
"@commitlint/config-angular": "^8.3.4",
|
"@commitlint/config-angular": "^8.3.4",
|
||||||
"@commitlint/config-conventional": "^8.3.4",
|
"@commitlint/config-conventional": "^8.3.4",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue