Skip to content

Commit ebf8c5a

Browse files
authored
ci: Add conventional commits workflow
Merge pull request #25 from DSD-DBS/add-commits-workflow
2 parents 32f6da3 + e210047 commit ebf8c5a

3 files changed

Lines changed: 91 additions & 6 deletions

File tree

.commitlintrc.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# SPDX-FileCopyrightText: Copyright DB InfraGO AG contributors
2+
# SPDX-License-Identifier: CC0-1.0
3+
rules:
4+
body-leading-blank: [2, always]
5+
footer-leading-blank: [2, always]
6+
scope-case: [2, always, lower-case]
7+
subject-case: [2, always, sentence-case]
8+
subject-empty: [2, never]
9+
subject-full-stop: [2, never, .]
10+
subject-max-length: [2, always, 72]
11+
type-empty: [2, never]
12+
type-enum:
13+
[
14+
2,
15+
always,
16+
[build, chore, ci, docs, feat, fix, merge, perf, refactor, revert, test],
17+
]
18+
extends:
19+
- "@commitlint/config-conventional"

.github/workflows/commits.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# SPDX-FileCopyrightText: Copyright DB InfraGO AG
2+
# SPDX-License-Identifier: CC0-1.0
3+
4+
name: Commits
5+
6+
on:
7+
pull_request:
8+
branches: [main]
9+
10+
jobs:
11+
conventional-commits:
12+
runs-on: ubuntu-latest
13+
concurrency:
14+
group: commit-check-pr-${{ github.event.pull_request.number }}
15+
cancel-in-progress: true
16+
steps:
17+
- uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
- name: Install commitlint
21+
run: npm install @commitlint/cli @commitlint/config-conventional
22+
- name: Validate commit messages
23+
id: conventional-commits
24+
env:
25+
SHA_FROM: ${{ github.event.pull_request.base.sha }}
26+
SHA_TO: ${{ github.event.pull_request.head.sha }}
27+
run: |
28+
delim="_EOF_$(uuidgen)"
29+
echo "validation-result<<$delim" >> "$GITHUB_OUTPUT"
30+
r=0
31+
npx commitlint --from "$SHA_FROM" --to "$SHA_TO" >> "$GITHUB_OUTPUT" 2>&1 || r=$?
32+
echo "$delim" >> "$GITHUB_OUTPUT"
33+
exit $r
34+
- name: Find conventional commit comment on PR
35+
uses: peter-evans/find-comment@v3
36+
if: always() && steps.conventional-commits.outcome == 'failure'
37+
id: fc
38+
with:
39+
issue-number: ${{ github.event.pull_request.number }}
40+
comment-author: 'github-actions[bot]'
41+
body-includes: conventional commit
42+
- name: Post comment if validation failed
43+
uses: peter-evans/create-or-update-comment@v4
44+
if: always() && steps.conventional-commits.outcome == 'failure'
45+
with:
46+
comment-id: ${{ steps.fc.outputs.comment-id }}
47+
issue-number: ${{ github.event.pull_request.number }}
48+
edit-mode: replace
49+
body: |
50+
The pull request does not conform to the conventional commit specification. Please ensure that your commit messages follow the spec: <https://www.conventionalcommits.org/>.
51+
We also strongly recommend that you set up your development environment with pre-commit.
52+
53+
This is the commit validation log:
54+
```
55+
${{ steps.conventional-commits.outputs.validation-result }}
56+
```
57+
58+
Here are some examples of valid commit messages:
59+
```
60+
feat(model): Add realized_states to State and Mode
61+
fix(aird): Prevent creating circles with r=0
62+
docs(readme): Update project description
63+
```

.pre-commit-config.yaml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ default_install_hook_types: [commit-msg, pre-commit]
55
default_stages: [commit, merge-commit]
66
repos:
77
- repo: https://github.com/pre-commit/pre-commit-hooks
8-
rev: v4.4.0
8+
rev: v4.6.0
99
hooks:
1010
- id: check-added-large-files
1111
- id: check-builtin-literals
@@ -21,7 +21,7 @@ repos:
2121
- id: end-of-file-fixer
2222
- id: trailing-whitespace
2323
- repo: https://github.com/Lucas-C/pre-commit-hooks
24-
rev: v1.5.1
24+
rev: v1.5.5
2525
hooks:
2626
- id: insert-license
2727
name: Insert license headers (XML-style comments)
@@ -33,10 +33,13 @@ repos:
3333
- --comment-style
3434
- "<!--| ~| -->"
3535
- repo: https://github.com/fsfe/reuse-tool
36-
rev: v1.1.2
36+
rev: v4.0.3
3737
hooks:
3838
- id: reuse
39-
- repo: https://github.com/qoomon/git-conventional-commits
40-
rev: v2.6.4
39+
- repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook
40+
rev: v9.16.0
4141
hooks:
42-
- id: conventional-commits
42+
- id: commitlint
43+
stages: [commit-msg]
44+
additional_dependencies:
45+
- "@commitlint/config-conventional"

0 commit comments

Comments
 (0)