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

Merge pull request #1 from wagoid/feat/create-action

Feat/create action
This commit is contained in:
Wagner Santos 2019-10-02 09:22:04 -03:00 committed by GitHub
commit 2e8e9a49ef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 2163 additions and 1 deletions

11
.github/workflows/commitlint.yml vendored Normal file
View file

@ -0,0 +1,11 @@
name: Commitlint
on: [pull_request]
jobs:
commitlint:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v1
- uses: ./

6
.prettierrc Normal file
View file

@ -0,0 +1,6 @@
{
"trailingComma": "all",
"tabWidth": 2,
"semi": false,
"singleQuote": true
}

9
Dockerfile Normal file
View file

@ -0,0 +1,9 @@
FROM node:10
COPY package*.json /
RUN npm ci --production
COPY . .
ENTRYPOINT ["/entrypoint.sh"]

View file

@ -1,2 +1,40 @@
# commitlint-pr-action # Commitlint Github Action
Lints Pull Request commits with commitlint Lints Pull Request commits with commitlint
## Usage
Create a github workflow in the `.github` folder, e.g. `.github/workflows/commitlint.yml`:
```yaml
name: Commitlint
on: [pull_request]
jobs:
commitlint:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v1
- uses: wagoid/commitlint-github-action@v1.0.0
```
## Inputs
### `configFile`
The path to your commitlint config file. Default `commitlint.config.js`.
## 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:
- [@commitlint/config-angular](./@commitlint/config-angular)
- [@commitlint/config-conventional](./@commitlint/config-conventional)
- [@commitlint/config-lerna-scopes](./@commitlint/config-lerna-scopes)
- [@commitlint/config-patternplate](./@commitlint/config-patternplate)
- [conventional-changelog-lint-config-canonical](https://github.com/gajus/conventional-changelog-lint-config-canonical)
- [commitlint-config-jira](https://github.com/Gherciu/commitlint-jira)
If you have a custom shared config that lies in a private registry, let us know! We will be happy to cover this case if necessary.

13
action.yml Normal file
View 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'

3
commitlint.config.js Normal file
View file

@ -0,0 +1,3 @@
module.exports = {
extends: ['@commitlint/config-conventional'],
}

7
entrypoint.sh Executable file
View file

@ -0,0 +1,7 @@
#!/bin/sh
set -e
cd ${GITHUB_WORKSPACE}
NODE_PATH=/node_modules node /run.js

1962
package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

44
package.json Normal file
View file

@ -0,0 +1,44 @@
{
"name": "commitlint-gh-actions",
"version": "1.0.0",
"description": "commitlint github action",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"commitlint": "NODE_PATH=/home/wagner/workdir/moteefe/easynvest-crawler/.github/actions/commitlint/node_modules commitlint"
},
"repository": {
"type": "git",
"url": "git+https://github.com/bennypowers/commitlint-gh-actions.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/bennypowers/commitlint-gh-actions/issues"
},
"homepage": "https://github.com/bennypowers/commitlint-gh-actions#readme",
"dependencies": {
"@actions/core": "1.1.1",
"@actions/github": "1.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",
"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"
}
}
}

69
run.js Normal file
View file

@ -0,0 +1,69 @@
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 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('Lint free! 🎉')
}
}
const exitWithMessage = message => error => {
console.log(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()