From 1d0ce8cfc02fd1a982669d0509d42b482fd4b6f7 Mon Sep 17 00:00:00 2001 From: Michael Hanke Date: Fri, 20 Sep 2024 10:47:43 +0200 Subject: [PATCH] chore: add conventional commit setup This includes a GitHub workflow to check PR commit messages, and also a local hatch environment to check all messages via ``` hatch run cz:check ``` --- .github/workflows/conventional-commits.yml | 23 ++++++++++++++++++++++ pyproject.toml | 19 ++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 .github/workflows/conventional-commits.yml diff --git a/.github/workflows/conventional-commits.yml b/.github/workflows/conventional-commits.yml new file mode 100644 index 0000000..8c86ddc --- /dev/null +++ b/.github/workflows/conventional-commits.yml @@ -0,0 +1,23 @@ +name: Conventional commits + +on: pull_request + +jobs: + check-messages: + runs-on: ubuntu-latest + steps: + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: 3.11 + architecture: x64 + - name: Checkout + uses: actions/checkout@v4 + with: + # we need all the history to be able to resolve revision ranges properly + fetch-depth: 0 + - name: Install commitizen + run: python -m pip install commitizen + - name: Run commit message checks + run: | + cz check --rev-range ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }} diff --git a/pyproject.toml b/pyproject.toml index a20f2ef..dee9f84 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -69,6 +69,15 @@ clean = [ "make -C docs clean", ] +[tool.hatch.envs.cz] +extra-dependencies = [ + "commitizen", +] +[tool.hatch.envs.cz.scripts] +check = [ + # check all commit messages since the (before) beginning + "cz check --rev-range 4b825dc642cb6eb9a060e54bf8d69288fbee4904..HEAD", +] [tool.coverage.run] source_pkgs = ["datalad_core", "tests"] @@ -92,3 +101,13 @@ exclude_lines = [ "raise NotImplementedError", ] + +[tool.commitizen] +name = "cz_customize" + +[tool.commitizen.customize] +commit_parser = "^((?Pfeat|fix|rf|perf|test|doc|BREAKING CHANGE)(?:\\((?P[^()\r\n]*)\\)|\\()?(?P!)?|\\w+!):\\s(?P.*)?(?P.*)?" +change_type_order = ["BREAKING CHANGE", "feat", "fix", "rf", "perf", "doc", "test"] +schema_pattern = "(?s)(ci|doc|feat|fix|perf|rf|style|test|chore|revert|bump)(\\(\\S+\\))?!?:( [^\\n\\r]+)((\\n\\n.*)|(\\s*))?$" + +