Skip to content

Commit ae1466d

Browse files
authored
Merge pull request #56 from cbgbt/commitlint
ci: enable commitlint for PRs
2 parents cebbd4c + 2c08f13 commit ae1466d

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

.commitlint.config.mjs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* [commitlint](https://github.com/conventional-changelog/commitlint) configuration */
2+
import {
3+
RuleConfigSeverity,
4+
} from '@commitlint/types';
5+
6+
export default {
7+
parserPreset: 'conventional-changelog-conventionalcommits',
8+
rules: {
9+
'header-max-length': [RuleConfigSeverity.Error, 'always', 72], // Header should be 72 characters or shorter
10+
'header-trim': [RuleConfigSeverity.Error, 'always'], // No leading/trailing whitespace in header
11+
'subject-empty': [RuleConfigSeverity.Error, 'never'], // No empty subject
12+
'subject-case': [ // Subject line should be lowercase
13+
RuleConfigSeverity.Error,
14+
'never',
15+
['sentence-case', 'start-case', 'pascal-case', 'upper-case']],
16+
'subject-full-stop': [RuleConfigSeverity.Error, 'never'], // No full-stop at end of subject
17+
'body-max-line-length': [RuleConfigSeverity.Error, 'always', 72], // Body lines should be 72 characteres or shorter
18+
'body-leading-blank': [RuleConfigSeverity.Error, 'always'], // Empty line before body
19+
'type-empty': [RuleConfigSeverity.Error, 'never'], // Commit type must be present
20+
'type-case': [RuleConfigSeverity.Error, 'always', 'lower-case'], // Commit type should be lowercase
21+
'type-enum': [ // Commit type allowlist
22+
RuleConfigSeverity.Error,
23+
'always',
24+
[
25+
'build',
26+
'chore',
27+
'ci',
28+
'docs',
29+
'feat',
30+
'fix',
31+
'perf',
32+
'refactor',
33+
'revert',
34+
'style',
35+
'test',
36+
],
37+
],
38+
},
39+
ignores: [
40+
(message) => message.includes("Merge pull request #"), // PR merges are allowed
41+
],
42+
};

.github/workflows/commitlint.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Lint Commit Messages
2+
on:
3+
pull_request:
4+
types:
5+
- opened
6+
- edited
7+
- reopened
8+
- synchronize
9+
10+
jobs:
11+
commitlint:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
with:
16+
fetch-depth: 0
17+
- name: Setup Node
18+
uses: actions/setup-node@v4
19+
- name: Install dependencies
20+
run: npm install commitlint @commitlint/config-conventional
21+
- name: Run commitlint against commits in PR
22+
run: |
23+
npx commitlint \
24+
-g ${{ github.workspace }}/.commitlint.config.mjs \
25+
--from ${{ github.event.pull_request.base.sha }} \
26+
--to ${{ github.event.pull_request.head.sha }} \
27+
--help-url="https://github.com/${GITHUB_REPOSITORY}/blob/${GITHUB_BASE_REF}/CONTRIBUTING.md" \
28+
--verbose

0 commit comments

Comments
 (0)