From 732d8ef0bba9d23c731611dbed25e2e24a8a30d2 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Wed, 13 Dec 2023 19:07:28 +0000 Subject: build: Integrate Commitizen to check commit messages and generate changelog The commit messages are checked against the Conventional Commits (https://www.conventionalcommits.org) specification, along with minor customizations (eg, capitalized header, some irrelevant commit types removed Checking messages is integrated into `tox -e lint`. Changelog generation is integrated into "tox -e changelog", which runs `cz changelog` command underneath and incrementally updates RELEASES.md. Change-Id: I86f21f6c78a166d3bb92450a027a2d7e71ce22cf Signed-off-by: Gergely Nagy --- .pre-commit-config.yaml | 6 ++++++ CONTRIBUTING.md | 4 ++++ pyproject.toml | 22 +++++++++++++++++++++- tox.ini | 7 +++++++ 4 files changed, 38 insertions(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 81e0acb..67bd90b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -118,3 +118,9 @@ repos: entry: pylint language: system types: [python] + +- repo: https://github.com/commitizen-tools/commitizen + rev: v3.13.0 + hooks: + - id: commitizen-branch + args: [--rev-range, HEAD~1..HEAD] diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index df12003..de70378 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -38,6 +38,10 @@ Below is an overview on contributing code to MLIA. git commit -s ``` +- For the commit messages, the codebase follows [Conventional Commits](https://www.conventionalcommits.org), + with some customizations. Header description is be capitalized, and the following + commit types are allowed: build, ci, docs, feat, fix, perf, refactor, style, test. + - Push patch for code review ```bash diff --git a/pyproject.toml b/pyproject.toml index 827ae30..0c4cc8c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: Copyright 2022, Arm Limited and/or its affiliates. +# SPDX-FileCopyrightText: Copyright 2022-2023, Arm Limited and/or its affiliates. # SPDX-FileCopyrightText: Copyright (c) 2012-2022 Jukka Lehtosalo and contributors # SPDX-FileCopyrightText: Copyright (c) 2015-2022 Dropbox, Inc. # SPDX-License-Identifier: Apache-2.0 AND MIT @@ -73,3 +73,23 @@ module = [ "requests" ] ignore_missing_imports = true + +[tool.commitizen] +# This simply signifies that we want to customize the commitizen configuration +name = "cz_customize" +# name = "cz_conventional_commits" +tag_format = "$version" +version_scheme = "semver" +version_provider = "scm" +update_changelog_on_bump = true + +[tool.commitizen.customize] +# Schema pattern is used by `cz check`, and `tox -e lint` in turn. Builtin CC pattern: +# (?s)(build|ci|docs|feat|fix|perf|refactor|style|test|chore|revert|bump)(\\(\\S+\\))?!?:( [^\\n\\r]+)((\\n\\n.*)|(\\s*))?$ +# We customize this slightly by removing types that don't seem relevant now: +schema_pattern = "(?s)(build|ci|docs|feat|fix|perf|refactor|style|test)(\\(\\S+\\))?!?:( [A-Z][^\\n\\r]+)((\\n\\n.*)|(\\s*))?$" +schema = "(): \n\n\n\n(BREAKING CHANGE: )