Skip to content
Closed
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
38 changes: 38 additions & 0 deletions .github/workflows/.commitlintrc.cjs
Original file line number Diff line number Diff line change
@@ -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'],
},
};
56 changes: 56 additions & 0 deletions .github/workflows/commitlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
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: 24

- name: Lint pull request commits
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
set -o pipefail
printf '## Commit message lint\n\n' >> "$GITHUB_STEP_SUMMARY"
output_file="$(mktemp)"
trap 'rm -f "$output_file"' EXIT
# Lint only commits introduced by this pull request.
if npx --yes --package @commitlint/cli@19.8.1 -- commitlint \
--config .github/workflows/.commitlintrc.cjs \
--from="$BASE_SHA" \
--to="$HEAD_SHA" 2>&1 | tee "$output_file"; then
if [[ -s "$output_file" ]]; then
printf 'Commit message lint passed with warnings.\n\n' \
>> "$GITHUB_STEP_SUMMARY"
while IFS= read -r line; do
printf ' %s\n' "$line" >> "$GITHUB_STEP_SUMMARY"
done < "$output_file"
else
printf 'All pull request commit messages passed.\n' \
>> "$GITHUB_STEP_SUMMARY"
fi
else
printf 'Commit message lint failed.\n\n' >> "$GITHUB_STEP_SUMMARY"
while IFS= read -r line; do
printf ' %s\n' "$line" >> "$GITHUB_STEP_SUMMARY"
done < "$output_file"
exit 1
fi
Loading