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: Add conventional commits workflow #25

Merged
merged 2 commits into from
Jul 18, 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
19 changes: 19 additions & 0 deletions .commitlintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# SPDX-FileCopyrightText: Copyright DB InfraGO AG contributors
# SPDX-License-Identifier: CC0-1.0
rules:
body-leading-blank: [2, always]
footer-leading-blank: [2, always]
scope-case: [2, always, lower-case]
subject-case: [2, always, sentence-case]
subject-empty: [2, never]
subject-full-stop: [2, never, .]
subject-max-length: [2, always, 72]
type-empty: [2, never]
type-enum:
[
2,
always,
[build, chore, ci, docs, feat, fix, merge, perf, refactor, revert, test],
]
extends:
- "@commitlint/config-conventional"
63 changes: 63 additions & 0 deletions .github/workflows/commits.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# SPDX-FileCopyrightText: Copyright DB InfraGO AG
# SPDX-License-Identifier: CC0-1.0

name: Commits

on:
pull_request:
branches: [main]

jobs:
conventional-commits:
runs-on: ubuntu-latest
concurrency:
group: commit-check-pr-${{ github.event.pull_request.number }}
cancel-in-progress: true
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install commitlint
run: npm install @commitlint/cli @commitlint/config-conventional
- name: Validate commit messages
id: conventional-commits
env:
SHA_FROM: ${{ github.event.pull_request.base.sha }}
SHA_TO: ${{ github.event.pull_request.head.sha }}
run: |
delim="_EOF_$(uuidgen)"
echo "validation-result<<$delim" >> "$GITHUB_OUTPUT"
r=0
npx commitlint --from "$SHA_FROM" --to "$SHA_TO" >> "$GITHUB_OUTPUT" 2>&1 || r=$?
echo "$delim" >> "$GITHUB_OUTPUT"
exit $r
- name: Find conventional commit comment on PR
uses: peter-evans/find-comment@v3
if: always() && steps.conventional-commits.outcome == 'failure'
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: conventional commit
- name: Post comment if validation failed
uses: peter-evans/create-or-update-comment@v4
if: always() && steps.conventional-commits.outcome == 'failure'
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
edit-mode: replace
body: |
The pull request does not conform to the conventional commit specification. Please ensure that your commit messages follow the spec: <https://www.conventionalcommits.org/>.
We also strongly recommend that you set up your development environment with pre-commit.

This is the commit validation log:
```
${{ steps.conventional-commits.outputs.validation-result }}
```

Here are some examples of valid commit messages:
```
feat(model): Add realized_states to State and Mode
fix(aird): Prevent creating circles with r=0
docs(readme): Update project description
```
15 changes: 9 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ default_install_hook_types: [commit-msg, pre-commit]
default_stages: [commit, merge-commit]
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.6.0
hooks:
- id: check-added-large-files
- id: check-builtin-literals
Expand All @@ -21,7 +21,7 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.5.1
rev: v1.5.5
hooks:
- id: insert-license
name: Insert license headers (XML-style comments)
Expand All @@ -33,10 +33,13 @@ repos:
- --comment-style
- "<!--| ~| -->"
- repo: https://github.com/fsfe/reuse-tool
rev: v1.1.2
rev: v4.0.3
hooks:
- id: reuse
- repo: https://github.com/qoomon/git-conventional-commits
rev: v2.6.4
- repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook
rev: v9.16.0
hooks:
- id: conventional-commits
- id: commitlint
stages: [commit-msg]
additional_dependencies:
- "@commitlint/config-conventional"
Loading