Skip to content

Commit

Permalink
Merge pull request #56 from cbgbt/commitlint
Browse files Browse the repository at this point in the history
ci: enable commitlint for PRs
  • Loading branch information
cbgbt authored Aug 28, 2024
2 parents cebbd4c + 2c08f13 commit ae1466d
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
42 changes: 42 additions & 0 deletions .commitlint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* [commitlint](https://github.com/conventional-changelog/commitlint) configuration */
import {
RuleConfigSeverity,
} from '@commitlint/types';

export default {
parserPreset: 'conventional-changelog-conventionalcommits',
rules: {
'header-max-length': [RuleConfigSeverity.Error, 'always', 72], // Header should be 72 characters or shorter
'header-trim': [RuleConfigSeverity.Error, 'always'], // No leading/trailing whitespace in header
'subject-empty': [RuleConfigSeverity.Error, 'never'], // No empty subject
'subject-case': [ // Subject line should be lowercase
RuleConfigSeverity.Error,
'never',
['sentence-case', 'start-case', 'pascal-case', 'upper-case']],
'subject-full-stop': [RuleConfigSeverity.Error, 'never'], // No full-stop at end of subject
'body-max-line-length': [RuleConfigSeverity.Error, 'always', 72], // Body lines should be 72 characteres or shorter
'body-leading-blank': [RuleConfigSeverity.Error, 'always'], // Empty line before body
'type-empty': [RuleConfigSeverity.Error, 'never'], // Commit type must be present
'type-case': [RuleConfigSeverity.Error, 'always', 'lower-case'], // Commit type should be lowercase
'type-enum': [ // Commit type allowlist
RuleConfigSeverity.Error,
'always',
[
'build',
'chore',
'ci',
'docs',
'feat',
'fix',
'perf',
'refactor',
'revert',
'style',
'test',
],
],
},
ignores: [
(message) => message.includes("Merge pull request #"), // PR merges are allowed
],
};
28 changes: 28 additions & 0 deletions .github/workflows/commitlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Lint Commit Messages
on:
pull_request:
types:
- opened
- edited
- reopened
- synchronize

jobs:
commitlint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node
uses: actions/setup-node@v4
- name: Install dependencies
run: npm install commitlint @commitlint/config-conventional
- name: Run commitlint against commits in PR
run: |
npx commitlint \
-g ${{ github.workspace }}/.commitlint.config.mjs \
--from ${{ github.event.pull_request.base.sha }} \
--to ${{ github.event.pull_request.head.sha }} \
--help-url="https://github.com/${GITHUB_REPOSITORY}/blob/${GITHUB_BASE_REF}/CONTRIBUTING.md" \
--verbose

0 comments on commit ae1466d

Please sign in to comment.