Add commitlint workflow for testing

This commit is contained in:
Max Becker 2026-10-13 10:38:45 +02:00
parent 0d7ed3b1a4
commit 7612928ca1
2 changed files with 73 additions and 0 deletions

38
.github/workflows/.commitlintrc.cjs vendored Normal file
View File

@ -0,0 +1,38 @@
// Parse UHD's area-prefixed subjects and apply repository message limits.
module.exports = {
parserPreset: {
parserOpts: {
headerPattern: /^(\S(?:.*\S)?): (\S(?:.*\S)?)$/,
headerCorrespondence: ['scope', 'subject'],
},
},
plugins: [
{
rules: {
'header-ideal-length': (parsed, when, value) => {
const isValid = parsed.header.length <= value;
return [
when === 'never' ? !isValid : isValid,
`header should be ${value} characters or fewer`,
];
},
'no-fixup-commit': (parsed) => [
!/^fixup!\s/i.test(parsed.header)
&& !/:\s*fixup!\s/i.test(parsed.header),
'fixup commits are not allowed',
],
},
},
],
defaultIgnores: false,
rules: {
'scope-empty': [2, 'never'],
'subject-empty': [2, 'never'],
'header-ideal-length': [1, 'always', 50],
'header-max-length': [2, 'always', 72],
'body-empty': [2, 'never'],
'body-leading-blank': [2, 'always'],
'body-max-line-length': [2, 'always', 72],
'no-fixup-commit': [2, 'always'],
},
};

35
.github/workflows/commitlint.yml vendored Normal file
View File

@ -0,0 +1,35 @@
name: Commit Message Lint
on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
permissions:
contents: read
jobs:
commitlint:
runs-on: ubuntu-latest
steps:
- name: Check out pull request head
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
persist-credentials: false
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Lint pull request commits
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
# Lint only commits introduced by this pull request.
npx --yes --package @commitlint/cli@19.8.1 -- commitlint \
--config .github/workflows/.commitlintrc.cjs \
--from="$BASE_SHA" \
--to="$HEAD_SHA"