mirror of
https://github.com/wagoid/commitlint-github-action.git
synced 2025-11-07 08:06:54 +00:00
feat: add commitlint action
This commit is contained in:
parent
083d21442d
commit
478fbaff69
7 changed files with 2185 additions and 0 deletions
6
.prettierrc
Normal file
6
.prettierrc
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"trailingComma": "all",
|
||||||
|
"tabWidth": 2,
|
||||||
|
"semi": false,
|
||||||
|
"singleQuote": true
|
||||||
|
}
|
||||||
9
Dockerfile
Normal file
9
Dockerfile
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
FROM node:10
|
||||||
|
|
||||||
|
COPY package*.json /
|
||||||
|
|
||||||
|
RUN npm ci --production
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
ENTRYPOINT ["/entrypoint.sh"]
|
||||||
13
action.yml
Normal file
13
action.yml
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
name: 'Commitlint'
|
||||||
|
description: 'Lints commit messages with commitlint'
|
||||||
|
author: 'Wagner Santos'
|
||||||
|
inputs:
|
||||||
|
configFile:
|
||||||
|
description: 'commitlint config file'
|
||||||
|
default: './commitlint.config.js'
|
||||||
|
runs:
|
||||||
|
using: 'docker'
|
||||||
|
image: 'Dockerfile'
|
||||||
|
branding:
|
||||||
|
icon: 'check-square'
|
||||||
|
color: 'blue'
|
||||||
7
entrypoint.sh
Executable file
7
entrypoint.sh
Executable file
|
|
@ -0,0 +1,7 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
cd ${GITHUB_WORKSPACE}
|
||||||
|
|
||||||
|
NODE_PATH=/node_modules node /run.js
|
||||||
2037
package-lock.json
generated
Normal file
2037
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
43
package.json
Normal file
43
package.json
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
{
|
||||||
|
"name": "commitlint-github-action",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "commitlint github action",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/wagoid/commitlint-github-action.git"
|
||||||
|
},
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"homepage": "https://github.com/wagoid/commitlint-github-action",
|
||||||
|
"dependencies": {
|
||||||
|
"@actions/core": "1.1.1",
|
||||||
|
"@actions/exec": "1.0.1",
|
||||||
|
"@actions/github": "1.1.0",
|
||||||
|
"@commitlint/cli": "8.1.0",
|
||||||
|
"@commitlint/config-angular": "8.2.0",
|
||||||
|
"@commitlint/config-conventional": "7.6.0",
|
||||||
|
"@commitlint/config-lerna-scopes": "8.2.0",
|
||||||
|
"@commitlint/config-patternplate": "8.2.0",
|
||||||
|
"@commitlint/format": "8.2.0",
|
||||||
|
"@commitlint/lint": "8.2.0",
|
||||||
|
"@commitlint/load": "8.2.0",
|
||||||
|
"@commitlint/read": "8.2.0",
|
||||||
|
"chalk": "2.4.2",
|
||||||
|
"commitlint-config-jira": "1.0.9",
|
||||||
|
"conventional-changelog-lint-config-canonical": "1.0.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"husky": "3.0.7",
|
||||||
|
"prettier": "1.18.2",
|
||||||
|
"pretty-quick": "1.11.1"
|
||||||
|
},
|
||||||
|
"husky": {
|
||||||
|
"hooks": {
|
||||||
|
"pre-commit": "pretty-quick --staged"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
70
run.js
Normal file
70
run.js
Normal file
|
|
@ -0,0 +1,70 @@
|
||||||
|
const { existsSync } = require('fs')
|
||||||
|
const { resolve } = require('path')
|
||||||
|
const core = require('@actions/core')
|
||||||
|
const github = require('@actions/github')
|
||||||
|
const read = require('@commitlint/read')
|
||||||
|
const lint = require('@commitlint/lint')
|
||||||
|
const { format } = require('@commitlint/format')
|
||||||
|
const load = require('@commitlint/load')
|
||||||
|
const chalk = require('chalk')
|
||||||
|
|
||||||
|
const githubToken = process.env.GITHUB_TOKEN
|
||||||
|
|
||||||
|
const configPath = resolve(
|
||||||
|
process.env.GITHUB_WORKSPACE,
|
||||||
|
core.getInput('configFile'),
|
||||||
|
)
|
||||||
|
|
||||||
|
const getRangeFromPullRequest = async () => {
|
||||||
|
const octokit = new github.GitHub(githubToken)
|
||||||
|
const { owner, repo, number } = github.context.issue
|
||||||
|
const { data: commits } = await octokit.pulls.listCommits({
|
||||||
|
owner,
|
||||||
|
repo,
|
||||||
|
pull_number: number,
|
||||||
|
})
|
||||||
|
const commitShas = commits.map(commit => commit.sha)
|
||||||
|
const [from] = commitShas
|
||||||
|
const to = commitShas[commitShas.length - 1]
|
||||||
|
|
||||||
|
return [from, to]
|
||||||
|
}
|
||||||
|
|
||||||
|
const showLintResults = async ([from, to]) => {
|
||||||
|
const commits = await read({ from, to })
|
||||||
|
const config = existsSync(configPath) ? await load(require(configPath)) : {}
|
||||||
|
const results = await Promise.all(
|
||||||
|
commits.map(commit => lint(commit, config.rules)),
|
||||||
|
)
|
||||||
|
const formattedResults = format(
|
||||||
|
{ results },
|
||||||
|
{
|
||||||
|
color: true,
|
||||||
|
helpUrl:
|
||||||
|
'https://github.com/conventional-changelog/commitlint/#what-is-commitlint',
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
if (formattedResults.length) {
|
||||||
|
process.stderr.write(formattedResults)
|
||||||
|
process.exit(1)
|
||||||
|
} else {
|
||||||
|
console.log(chalk.green('Lint free! 🎉'))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const exitWithMessage = message => error => {
|
||||||
|
console.log(chalk.red(message))
|
||||||
|
console.error(error)
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
const main = () =>
|
||||||
|
getRangeFromPullRequest()
|
||||||
|
.catch(
|
||||||
|
exitWithMessage("error trying to get list of pull request's commits"),
|
||||||
|
)
|
||||||
|
.then(showLintResults)
|
||||||
|
.catch(exitWithMessage('error running commitlint'))
|
||||||
|
|
||||||
|
main()
|
||||||
Loading…
Reference in a new issue