Skip to content

Commit

Permalink
feat: add commitlint CI (LunarVim#1459)
Browse files Browse the repository at this point in the history
Co-authored-by: kylo252 <[email protected]>
  • Loading branch information
chaesngmin and kylo252 authored Sep 30, 2021
1 parent 35d5615 commit 346925f
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 14 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module.exports = {
rules: {
"body-leading-blank": [1, "always"],
"body-max-line-length": [2, "always", 100],
"footer-leading-blank": [1, "always"],
"footer-max-line-length": [2, "always", 100],
"header-max-length": [2, "always", 72],
"scope-case": [2, "always", "lower-case"],
"subject-case": [
2,
"never",
["upper-case", "pascal-case", "sentence-case", "start-case"],
],
"subject-empty": [2, "never"],
"subject-full-stop": [2, "never", "."],
"type-case": [2, "always", "lower-case"],
"type-empty": [2, "never"],
"type-enum": [
2,
"always",
[
"build",
"ci",
"docs",
"feat",
"fix",
"perf",
"refactor",
"revert",
"test",
],
],
},
};
15 changes: 15 additions & 0 deletions .github/workflows/commitlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: "Commit Linter"
on: pull_request
jobs:
lint-commits:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/[email protected]
with:
fetch-depth: 0
- uses: wagoid/commitlint-github-action@v4
with:
configFile: .github/workflows/commitlint.config.js
helpURL: https://github.com/LunarVim/LunarVim/blob/rolling/CONTRIBUTING.md#commit-messages
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@ repos:
entry: luacheck
types: [lua]
args: [.]
- id: commitlint
name: commitlint
language: system
entry: bash
args: [./utils/ci/run_commitlint.sh]
stages: [commit-msg]
72 changes: 58 additions & 14 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ One of the best ways to begin contributing in a meaningful way is by helping fin
3. Link your fork with the repository `git remote add upstream https://github.com/lunarvim/LunarVim.git`
4. That's it ! You can now `git fetch upstream` and `git rebase [-i] upstream/rolling` to update your branches with the latest contributions.

<br />

## Setting up development tools

### For editing Lua files
Expand All @@ -31,21 +33,9 @@ One of the best ways to begin contributing in a meaningful way is by helping fin

Install [pre-commit](https://github.com/pre-commit/pre-commit) which will run all linters and formatters for you as a pre-commit-hook.

## Some Guidelines

### Git Commit Messages

* Use the present tense ("Add feature" not "Added feature")
* Use the imperative mood ("Move cursor to..." not "Moves cursor to...")
* Limit the first line to 72 characters or less
* Reference issues and pull requests liberally after the first line
<br />

### Git Branch Naming

* Name your branches meaningfully,
ex: (feature|bugfix|hotfix)/what-my-pr-does

### Code
## Code Conventions

All lua code is formatted with [Stylua](https://github.com/JohnnyMorganz/StyLua).
* Use snake_case
Expand All @@ -60,6 +50,60 @@ All shell code is formatted according to [Google Shell Style Guide](https://goog
shfmt -i 2 -ci -l -d .
```

<br />

## Pull Requests (PRs)

To avoid duplicate work, create a draft pull request.

### Commit Messages
* Commit header is limited to 72 characters.
* Commit body and footer is limited to 100 characters per line.

**Commit header format:**
```
<type>(<scope>?): <summary>
│ │ │
│ │ └─> Present tense. 'add something...'(O) vs 'added something...'(X)
│ │ Imperative mood. 'move cursor to...'(O) vs 'moves cursor to...'(X)
│ │ Not capitalized.
│ │ No period at the end.
│ │
│ └─> Commit Scope is optional, but strongly recommended.
│ Use lower case.
│ 'plugin', 'file', or 'directory' name is suggested, but not limited.
└─> Commit Type: build|ci|docs|feat|fix|perf|refactor|test
```

##### Commit Type Guideline

* **build**: changes that affect the build system or external dependencies (example scopes: npm, pip, rg)
* **ci**: changes to CI configuration files and scripts (example scopes: format, lint, issue_templates)
* **docs**: changes to the documentation only
* **feat**: a new feature for the user
* **fix**: a bug fix
* **perf**: a performance improvement
* **refactor**: a code change that neither fixes a bug nor adds a feature
* **test**: Adding missing tests or correcting existing tests

**Real world examples:**
```
feat(quickfix): add 'q' binding to quit quickfix window when focused
```
```
fix(installer): add missing "HOME" variable
```


### Branch Naming

Name your branches meaningfully.

ex)
```(feature|bugfix|hotfix)/what-my-pr-does```

<br />

## Communication

Expand Down
10 changes: 10 additions & 0 deletions utils/ci/run_commitlint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
set -eo pipefail

REPO_DIR="$(git rev-parse --show-toplevel)"
HELP_URL="https://github.com/LunarVim/LunarVim/blob/rolling/CONTRIBUTING.md#commit-messages"
CONFIG="$REPO_DIR/.github/workflows/commitlint.config.js"

if ! npx commitlint --edit --verbose --help-url "$HELP_URL" --config "$CONFIG"; then
exit 1
fi

0 comments on commit 346925f

Please sign in to comment.