From 4e820a0255517c12cff78100bc258227c0abfa82 Mon Sep 17 00:00:00 2001 From: ewuerger Date: Thu, 18 Jul 2024 11:02:14 +0200 Subject: [PATCH 1/2] ci: Add conventional commits workflow --- .github/workflows/commits.yml | 63 +++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 .github/workflows/commits.yml diff --git a/.github/workflows/commits.yml b/.github/workflows/commits.yml new file mode 100644 index 0000000..16c5992 --- /dev/null +++ b/.github/workflows/commits.yml @@ -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: . + 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 + ``` From e2100472b10754e128bc02b50c0ac85c236ed2a2 Mon Sep 17 00:00:00 2001 From: ewuerger Date: Thu, 18 Jul 2024 11:15:29 +0200 Subject: [PATCH 2/2] ci: Add missing config --- .commitlintrc.yml | 19 +++++++++++++++++++ .pre-commit-config.yaml | 15 +++++++++------ 2 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 .commitlintrc.yml diff --git a/.commitlintrc.yml b/.commitlintrc.yml new file mode 100644 index 0000000..ad62e02 --- /dev/null +++ b/.commitlintrc.yml @@ -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" diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 797b77a..ece996a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 @@ -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) @@ -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"