Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: enable commitlint for PRs #56

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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