mirror of
https://github.com/wagoid/commitlint-github-action.git
synced 2025-11-08 00:16:56 +00:00
Merge pull request #7 from wagoid/feat/add-ability-to-run-on-pulls
Feat/add ability to run on pushes
This commit is contained in:
commit
240ede8de1
9 changed files with 116 additions and 34 deletions
6
.dockerignore
Normal file
6
.dockerignore
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
node_modules
|
||||||
|
.commitlintrc.yml
|
||||||
|
commitlint.config.js
|
||||||
|
action.yml
|
||||||
|
.github
|
||||||
|
CHANGELOG.md
|
||||||
2
.github/workflows/commitlint.yml
vendored
2
.github/workflows/commitlint.yml
vendored
|
|
@ -8,6 +8,7 @@ jobs:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v1
|
||||||
|
- run: sed -i -E "s/([']docker:.+)/Dockerfile/" ./action.yml
|
||||||
- uses: ./
|
- uses: ./
|
||||||
commitlint-with-yml-file:
|
commitlint-with-yml-file:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
@ -15,6 +16,7 @@ jobs:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v1
|
||||||
|
- run: sed -i -E "s/([']docker:.+)/Dockerfile/" ./action.yml
|
||||||
- uses: ./
|
- uses: ./
|
||||||
with:
|
with:
|
||||||
configFile: './.commitlintrc.yml'
|
configFile: './.commitlintrc.yml'
|
||||||
|
|
|
||||||
12
.github/workflows/test.yml
vendored
Normal file
12
.github/workflows/test.yml
vendored
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
name: Test
|
||||||
|
on: [push]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
commitlint:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v1
|
||||||
|
- run: sed -i -E "s/([']docker:.+)/Dockerfile/" ./action.yml
|
||||||
|
- uses: ./
|
||||||
|
|
@ -1,3 +1,12 @@
|
||||||
|
<a name="1.2.0"></a>
|
||||||
|
|
||||||
|
## [1.2.1](https://github.com/wagoid/commitlint-github-action/compare/v1.1.1...v1.2.0) (2019-10-15)
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
- add ability to run commitlint on events that are not pull requests ([23cd801](https://github.com/wagoid/commitlint-github-action/commit/23cd801))
|
||||||
|
- add firstParent input to ignore errors from your default branch ([598e473](https://github.com/wagoid/commitlint-github-action/commit/598e473))
|
||||||
|
|
||||||
<a name="1.1.1"></a>
|
<a name="1.1.1"></a>
|
||||||
|
|
||||||
## [1.1.1](https://github.com/wagoid/commitlint-github-action/compare/v1.1.0...v1.1.1) (2019-10-08)
|
## [1.1.1](https://github.com/wagoid/commitlint-github-action/compare/v1.1.0...v1.1.1) (2019-10-08)
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,15 @@ jobs:
|
||||||
|
|
||||||
The path to your commitlint config file. Default `commitlint.config.js`.
|
The path to your commitlint config file. Default `commitlint.config.js`.
|
||||||
|
|
||||||
|
### `firstParent`
|
||||||
|
|
||||||
|
When set to true, we follow only the first parent commit when seeing a merge commit.
|
||||||
|
|
||||||
|
This helps to ignore errors in commits that were already present in your default branch (e.g. `master`) before adding conventional commit checks.
|
||||||
|
More info in [git-log docs](https://git-scm.com/docs/git-log#Documentation/git-log.txt---first-parent).
|
||||||
|
|
||||||
|
Default `true`
|
||||||
|
|
||||||
## 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:
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,12 @@ inputs:
|
||||||
configFile:
|
configFile:
|
||||||
description: 'commitlint config file'
|
description: 'commitlint config file'
|
||||||
default: './commitlint.config.js'
|
default: './commitlint.config.js'
|
||||||
|
firstParent:
|
||||||
|
description: 'when set to true, we follow only the first parent commit when seeing a merge commit. More info in git-log docs https://git-scm.com/docs/git-log#Documentation/git-log.txt---first-parent'
|
||||||
|
default: true
|
||||||
runs:
|
runs:
|
||||||
using: 'docker'
|
using: 'docker'
|
||||||
image: 'docker://wagoid/commitlint-github-action:1.1.1'
|
image: 'docker://wagoid/commitlint-github-action:1.2.0'
|
||||||
branding:
|
branding:
|
||||||
icon: 'check-square'
|
icon: 'check-square'
|
||||||
color: 'blue'
|
color: 'blue'
|
||||||
|
|
|
||||||
48
package-lock.json
generated
48
package-lock.json
generated
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "commitlint-github-action",
|
"name": "commitlint-github-action",
|
||||||
"version": "1.1.0",
|
"version": "1.1.1",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
@ -9,6 +9,11 @@
|
||||||
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.1.1.tgz",
|
||||||
"integrity": "sha512-O5G6EmlzTVsng7VSpNtszIoQq6kOgMGNTFB/hmwKNNA4V71JyxImCIrL27vVHCt2Cb3ImkaCr6o27C2MV9Ylwg=="
|
"integrity": "sha512-O5G6EmlzTVsng7VSpNtszIoQq6kOgMGNTFB/hmwKNNA4V71JyxImCIrL27vVHCt2Cb3ImkaCr6o27C2MV9Ylwg=="
|
||||||
},
|
},
|
||||||
|
"@actions/exec": {
|
||||||
|
"version": "1.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@actions/exec/-/exec-1.0.1.tgz",
|
||||||
|
"integrity": "sha512-nvFkxwiicvpzNiCBF4wFBDfnBvi7xp/as7LE1hBxBxKG2L29+gkIPBiLKMVORL+Hg3JNf07AKRfl0V5djoypjQ=="
|
||||||
|
},
|
||||||
"@actions/github": {
|
"@actions/github": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/@actions/github/-/github-1.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/@actions/github/-/github-1.1.0.tgz",
|
||||||
|
|
@ -156,6 +161,20 @@
|
||||||
"@marionebl/sander": "0.6.1",
|
"@marionebl/sander": "0.6.1",
|
||||||
"babel-runtime": "6.26.0",
|
"babel-runtime": "6.26.0",
|
||||||
"git-raw-commits": "1.3.6"
|
"git-raw-commits": "1.3.6"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"git-raw-commits": {
|
||||||
|
"version": "1.3.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/git-raw-commits/-/git-raw-commits-1.3.6.tgz",
|
||||||
|
"integrity": "sha512-svsK26tQ8vEKnMshTDatSIQSMDdz8CxIIqKsvPqbtV23Etmw6VNaFAitu8zwZ0VrOne7FztwPyRLxK7/DIUTQg==",
|
||||||
|
"requires": {
|
||||||
|
"dargs": "4.1.0",
|
||||||
|
"lodash.template": "4.5.0",
|
||||||
|
"meow": "4.0.1",
|
||||||
|
"split2": "2.2.0",
|
||||||
|
"through2": "2.0.5"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@commitlint/resolve-extends": {
|
"@commitlint/resolve-extends": {
|
||||||
|
|
@ -1322,31 +1341,23 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"git-raw-commits": {
|
"git-raw-commits": {
|
||||||
"version": "1.3.6",
|
"version": "2.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/git-raw-commits/-/git-raw-commits-1.3.6.tgz",
|
"resolved": "https://registry.npmjs.org/git-raw-commits/-/git-raw-commits-2.0.2.tgz",
|
||||||
"integrity": "sha512-svsK26tQ8vEKnMshTDatSIQSMDdz8CxIIqKsvPqbtV23Etmw6VNaFAitu8zwZ0VrOne7FztwPyRLxK7/DIUTQg==",
|
"integrity": "sha512-HVvl6J3dx7CS9fWTtyZXA2ejhdq9p/GSU9EEVlJPb2pSgMuD7IWK3dERcUPsJj9SZrJJ6IIB+3Rsjx9FUDdE1Q==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"dargs": "4.1.0",
|
"dargs": "4.1.0",
|
||||||
"lodash.template": "4.5.0",
|
"lodash.template": "4.5.0",
|
||||||
"meow": "4.0.1",
|
"meow": "4.0.1",
|
||||||
"split2": "2.2.0",
|
"split2": "2.2.0",
|
||||||
"through2": "2.0.5"
|
"through2": "3.0.1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"meow": {
|
"through2": {
|
||||||
"version": "4.0.1",
|
"version": "3.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/meow/-/meow-4.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/through2/-/through2-3.0.1.tgz",
|
||||||
"integrity": "sha512-xcSBHD5Z86zaOc+781KrupuHAzeGXSLtiAOmBsiLDiPSaYSB6hdew2ng9EBAnZ62jagG9MHAOdxpDi/lWBFJ/A==",
|
"integrity": "sha512-M96dvTalPT3YbYLaKaCuwu+j06D/8Jfib0o/PxbVt6Amhv3dUAtW6rTV1jPgJSBG83I/e04Y6xkVdVhSRhi0ww==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"camelcase-keys": "4.2.0",
|
"readable-stream": "2.3.6"
|
||||||
"decamelize-keys": "1.1.0",
|
|
||||||
"loud-rejection": "1.6.0",
|
|
||||||
"minimist": "1.2.0",
|
|
||||||
"minimist-options": "3.0.2",
|
|
||||||
"normalize-package-data": "2.5.0",
|
|
||||||
"read-pkg-up": "3.0.0",
|
|
||||||
"redent": "2.0.0",
|
|
||||||
"trim-newlines": "2.0.0"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1793,7 +1804,6 @@
|
||||||
"version": "4.0.1",
|
"version": "4.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/meow/-/meow-4.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/meow/-/meow-4.0.1.tgz",
|
||||||
"integrity": "sha512-xcSBHD5Z86zaOc+781KrupuHAzeGXSLtiAOmBsiLDiPSaYSB6hdew2ng9EBAnZ62jagG9MHAOdxpDi/lWBFJ/A==",
|
"integrity": "sha512-xcSBHD5Z86zaOc+781KrupuHAzeGXSLtiAOmBsiLDiPSaYSB6hdew2ng9EBAnZ62jagG9MHAOdxpDi/lWBFJ/A==",
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"camelcase-keys": "4.2.0",
|
"camelcase-keys": "4.2.0",
|
||||||
"decamelize-keys": "1.1.0",
|
"decamelize-keys": "1.1.0",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "commitlint-github-action",
|
"name": "commitlint-github-action",
|
||||||
"version": "1.1.1",
|
"version": "1.2.0",
|
||||||
"description": "commitlint github action",
|
"description": "commitlint github action",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
"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.1.1",
|
||||||
|
"@actions/exec": "1.0.1",
|
||||||
"@actions/github": "1.1.0",
|
"@actions/github": "1.1.0",
|
||||||
"@commitlint/config-angular": "8.2.0",
|
"@commitlint/config-angular": "8.2.0",
|
||||||
"@commitlint/config-conventional": "7.6.0",
|
"@commitlint/config-conventional": "7.6.0",
|
||||||
|
|
@ -24,9 +25,9 @@
|
||||||
"@commitlint/format": "8.2.0",
|
"@commitlint/format": "8.2.0",
|
||||||
"@commitlint/lint": "8.2.0",
|
"@commitlint/lint": "8.2.0",
|
||||||
"@commitlint/load": "8.2.0",
|
"@commitlint/load": "8.2.0",
|
||||||
"@commitlint/read": "8.2.0",
|
|
||||||
"commitlint-config-jira": "1.0.9",
|
"commitlint-config-jira": "1.0.9",
|
||||||
"conventional-changelog-lint-config-canonical": "1.0.0"
|
"conventional-changelog-lint-config-canonical": "1.0.0",
|
||||||
|
"git-raw-commits": "2.0.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"conventional-changelog-cli": "2.0.23",
|
"conventional-changelog-cli": "2.0.23",
|
||||||
|
|
|
||||||
52
run.js
52
run.js
|
|
@ -1,13 +1,16 @@
|
||||||
const { existsSync, readFileSync } = require('fs')
|
const { existsSync } = require('fs')
|
||||||
const { resolve } = require('path')
|
const { resolve } = require('path')
|
||||||
const core = require('@actions/core')
|
const core = require('@actions/core')
|
||||||
const github = require('@actions/github')
|
const github = require('@actions/github')
|
||||||
const read = require('@commitlint/read')
|
const exec = require('@actions/exec')
|
||||||
const lint = require('@commitlint/lint')
|
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 gitRawCommits = require('git-raw-commits')
|
||||||
|
|
||||||
const githubToken = process.env.GITHUB_TOKEN
|
const pullRequestEvent = 'pull_request'
|
||||||
|
|
||||||
|
const { GITHUB_TOKEN, GITHUB_EVENT_NAME, GITHUB_SHA } = process.env
|
||||||
|
|
||||||
const configPath = resolve(
|
const configPath = resolve(
|
||||||
process.env.GITHUB_WORKSPACE,
|
process.env.GITHUB_WORKSPACE,
|
||||||
|
|
@ -15,7 +18,9 @@ const configPath = resolve(
|
||||||
)
|
)
|
||||||
|
|
||||||
const getRangeFromPullRequest = async () => {
|
const getRangeFromPullRequest = async () => {
|
||||||
const octokit = new github.GitHub(githubToken)
|
if (GITHUB_EVENT_NAME !== pullRequestEvent) return [null, GITHUB_SHA]
|
||||||
|
|
||||||
|
const octokit = new github.GitHub(GITHUB_TOKEN)
|
||||||
const { owner, repo, number } = github.context.issue
|
const { owner, repo, number } = github.context.issue
|
||||||
const { data: commits } = await octokit.pulls.listCommits({
|
const { data: commits } = await octokit.pulls.listCommits({
|
||||||
owner,
|
owner,
|
||||||
|
|
@ -29,8 +34,34 @@ const getRangeFromPullRequest = async () => {
|
||||||
return [from, to]
|
return [from, to]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getHistoryCommits(from, to) {
|
||||||
|
const options = {
|
||||||
|
from,
|
||||||
|
to,
|
||||||
|
}
|
||||||
|
|
||||||
|
if (core.getInput('firstParent') === 'true') {
|
||||||
|
options.firstParent = true
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!from) {
|
||||||
|
options.maxCount = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const data = []
|
||||||
|
|
||||||
|
gitRawCommits(options)
|
||||||
|
.on('data', chunk => data.push(chunk.toString('utf-8')))
|
||||||
|
.on('error', reject)
|
||||||
|
.on('end', () => {
|
||||||
|
resolve(data)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const showLintResults = async ([from, to]) => {
|
const showLintResults = async ([from, to]) => {
|
||||||
const commits = await read({ from, to })
|
const commits = await getHistoryCommits(from, to)
|
||||||
const config = existsSync(configPath)
|
const config = existsSync(configPath)
|
||||||
? await load({}, { file: configPath })
|
? await load({}, { file: configPath })
|
||||||
: {}
|
: {}
|
||||||
|
|
@ -46,18 +77,17 @@ const showLintResults = async ([from, to]) => {
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
if (formattedResults.length) {
|
if (formattedResults) {
|
||||||
process.stderr.write(formattedResults)
|
core.setFailed(
|
||||||
process.exit(1)
|
`You have commit messages with errors\n\n${formattedResults}`,
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
console.log('Lint free! 🎉')
|
console.log('Lint free! 🎉')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const exitWithMessage = message => error => {
|
const exitWithMessage = message => error => {
|
||||||
console.log(message)
|
core.setFailed(`${message}\n${error}`)
|
||||||
console.error(error)
|
|
||||||
process.exit(1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const main = () =>
|
const main = () =>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue