Skip to content

Commit 5403047

Browse files
committed
chore: add pr format rules
1 parent 9a0a5ed commit 5403047

File tree

2 files changed

+138
-0
lines changed

2 files changed

+138
-0
lines changed

.commitlintrc.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# If updating this file, please also review `docs/release-process.md` and
2+
# `.github/workflows/pr_title.yml` and update the summary of these rules
3+
# in those files accordingly.
4+
5+
rules:
6+
# Body may be empty
7+
body-empty:
8+
level: ignore
9+
10+
# Description must not be empty
11+
description-empty:
12+
level: error
13+
14+
# Description should be <70 chars
15+
description-max-length:
16+
level: warning
17+
length: 70
18+
19+
# Subject line should exist
20+
subject-empty:
21+
level: error
22+
23+
# Type must be one of these options
24+
type:
25+
level: error
26+
options:
27+
- build
28+
- chore
29+
- ci
30+
- docs
31+
- feat
32+
- fix
33+
- perf
34+
- refactor
35+
- revert
36+
- style
37+
- test
38+
- update

.github/workflows/pr_title.yml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
name: PR title
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened, edited]
6+
7+
jobs:
8+
title_cc_validation:
9+
name: Conventional commits validation
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v4
15+
16+
# If changing this, please also see `.commitlintrc` and
17+
# `docs/release-process.md`.
18+
19+
- name: Check PR title
20+
env:
21+
PR_TITLE: ${{ github.event.pull_request.title }}
22+
run: |
23+
# If this step fails, please expand this step for more information.
24+
#
25+
# You will need to revise this pull request's title to
26+
# match the "summary" (first) line of a Conventional Commit message.
27+
# This enables us to automatically generate a meaningful changelog.
28+
#
29+
# The summary line (and thus the PR title) must have this exact format
30+
# (including punctuation):
31+
#
32+
# type: description
33+
#
34+
# `type` describes the nature of changes you are making. This project
35+
# requires the type to be one of these exact names:
36+
#
37+
# * fix
38+
# * feat (will cause a minor version bump)
39+
# * chore (will be omitted from changelog)
40+
# * update
41+
# * doc
42+
#
43+
# `description` is a short human-readable summary of the changes being made.
44+
# It is required.
45+
#
46+
# This project does not currently enforce the following items, but
47+
# we ask that you observe the following preferences in `description`:
48+
#
49+
# * The entire description should be written and capitalized as
50+
# an English-language sentence, except that the trailing period
51+
# should be omitted.
52+
# * Any acronyms such as JSON or YAML should be capitalized as per
53+
# common usage in English-language sentences.
54+
#
55+
# After you edit the PR title, this task will run again and the
56+
# warning should go away if you have made acceptable changes.
57+
#
58+
# For more information on Conventional Commits, please see:
59+
#
60+
# https://www.conventionalcommits.org/en/v1.0.0/
61+
#
62+
# ------------ (end of message) ------------
63+
64+
if echo "$PR_TITLE" | grep -E '^chore(\(.*\))?: release '; then
65+
echo "Exception / OK: chore release pattern"
66+
exit 0;
67+
fi
68+
69+
if echo "$PR_TITLE" | grep -E '^chore: release'; then
70+
echo "Exception / OK: chore release pattern"
71+
exit 0;
72+
fi
73+
74+
if echo "$PR_TITLE" | grep -E '^chore(\(deps\))?: bump '; then
75+
echo "Exception / OK: Dependabot update pattern"
76+
exit 0;
77+
fi
78+
79+
if echo "$PR_TITLE" | grep -E '^update: update '; then
80+
echo "Exception / OK: Dependabot update pattern"
81+
exit 0;
82+
fi
83+
84+
if echo "$PR_TITLE" | grep -E '^update: bump '; then
85+
echo "Exception / OK: Dependabot update pattern"
86+
exit 0;
87+
fi
88+
89+
echo "Installing commitlint-rs. Please wait 30-40 seconds ..."
90+
cargo install --quiet commitlint-rs
91+
set -e
92+
93+
echo  
94+
echo  
95+
echo --- commitlint results for PR title \"$PR_TITLE\" ---
96+
echo  
97+
98+
echo "$PR_TITLE" | commitlint -g .commitlintrc.yml
99+
100+
echo "✅ PR title matches all enforced rules."

0 commit comments

Comments
 (0)