Add commitlint configuration and compliance checks #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # SPDX-FileCopyrightText: 2026 Institute for Automation of Complex Power Systems, RWTH Aachen University | |
| # SPDX-License-Identifier: Apache-2.0 | |
| name: Compliance checks | |
| on: | |
| pull_request: | |
| branches: [master, main] | |
| permissions: | |
| contents: read | |
| jobs: | |
| conventional-commits: | |
| name: Conventional commit messages | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v7 | |
| with: | |
| fetch-depth: 0 | |
| - uses: actions/setup-node@v5 | |
| with: | |
| node-version: "20" | |
| - name: Install commitlint | |
| run: npm install --no-save @commitlint/cli @commitlint/config-conventional | |
| # The merge commit takes the PR title, so that is what Release Please reads. | |
| - name: Fail if the pull request title is not a conventional commit | |
| env: | |
| PR_TITLE: ${{ github.event.pull_request.title }} | |
| run: | | |
| if ! printf '%s\n' "$PR_TITLE" | npx commitlint --verbose; then | |
| echo "" | |
| echo "The pull request title becomes the merge commit subject on master." | |
| echo "Use a conventional commit subject, for example:" | |
| echo "" | |
| echo " fix: Coding style" | |
| echo "" | |
| exit 1 | |
| fi | |
| - name: Fail if a commit in this branch is not a conventional commit | |
| run: | | |
| BASE=${{ github.event.pull_request.base.sha }} | |
| HEAD=${{ github.event.pull_request.head.sha }} | |
| if ! npx commitlint --from "$BASE" --to "$HEAD" --verbose; then | |
| echo "" | |
| echo "Rewrite the offending commit messages, then force-push:" | |
| echo "" | |
| echo " git rebase -i $BASE" | |
| echo " git push --force-with-lease" | |
| echo "" | |
| echo "Or install the pre-commit hooks (see CONTRIBUTING.md) to catch this locally." | |
| exit 1 | |
| fi |