From 5e6d0ec49d44e9c4417f63b55566fac0a9bdcbd8 Mon Sep 17 00:00:00 2001 From: Lubos Mjachky Date: Tue, 30 Apr 2024 09:25:28 +0200 Subject: [PATCH] Apply the template from pulp-cli [noissue] --- .bumpversion.cfg | 21 -------- .ci/scripts/collect_changes.py | 20 ++++++-- .ci/scripts/create_release_branch.sh | 4 +- .ci/scripts/release.sh | 6 +-- .ci/scripts/validate_commit_message.py | 8 ++-- .github/workflows/collect_changes.yml | 2 +- .github/workflows/release.yml | 2 +- .github/workflows/release_branch.yml | 2 +- .github/workflows/test.yml | 28 +++++------ CHANGES/.TEMPLATE.md | 7 ++- pyproject.toml | 66 ++++++++++++++++++-------- 11 files changed, 93 insertions(+), 73 deletions(-) delete mode 100644 .bumpversion.cfg diff --git a/.bumpversion.cfg b/.bumpversion.cfg deleted file mode 100644 index af97132..0000000 --- a/.bumpversion.cfg +++ /dev/null @@ -1,21 +0,0 @@ -[bumpversion] -current_version = 0.4.0.dev -commit = False -tag = False -parse = (?P\d+)\.(?P\d+)\.(?P\d+)(\.(?P[a-z]+))? -serialize = - {major}.{minor}.{patch}.{release} - {major}.{minor}.{patch} - -[bumpversion:part:release] -optional_value = prod -first_value = dev -values = - dev - prod - -[bumpversion:file:./pulpcore/cli/ostree/__init__.py] - -[bumpversion:file:./pulp-glue-ostree/pyproject.toml] - -[bumpversion:file:./pyproject.toml] diff --git a/.ci/scripts/collect_changes.py b/.ci/scripts/collect_changes.py index 3565db4..c1fd047 100755 --- a/.ci/scripts/collect_changes.py +++ b/.ci/scripts/collect_changes.py @@ -1,13 +1,16 @@ +#!/bin/env python3 + import itertools import os import re +import tomllib -import toml from git import GitCommandError, Repo from packaging.version import parse as parse_version # Read Towncrier settings -tc_settings = toml.load("pyproject.toml")["tool"]["towncrier"] +with open("pyproject.toml", "rb") as fp: + tc_settings = tomllib.load(fp)["tool"]["towncrier"] CHANGELOG_FILE = tc_settings.get("filename", "NEWS.rst") START_STRING = tc_settings.get( @@ -21,8 +24,12 @@ TITLE_FORMAT = tc_settings.get("title_format", "{name} {version} ({project_date})") +# Build a regex to find the header of a changelog section. +# It must have a single capture group to single out the version. +# see help(re.split) for more info. NAME_REGEX = r".*" -VERSION_REGEX = r"([0-9]+\.[0-9]+\.[0-9][0-9ab]*)" +VERSION_REGEX = r"[0-9]+\.[0-9]+\.[0-9][0-9ab]*" +VERSION_CAPTURE_REGEX = rf"({VERSION_REGEX})" DATE_REGEX = r"[0-9]{4}-[0-9]{2}-[0-9]{2}" TITLE_REGEX = ( "(" @@ -30,6 +37,7 @@ TITLE_FORMAT.format(name="NAME_REGEX", version="VERSION_REGEX", project_date="DATE_REGEX") ) .replace("NAME_REGEX", NAME_REGEX) + .replace("VERSION_REGEX", VERSION_CAPTURE_REGEX, 1) .replace("VERSION_REGEX", VERSION_REGEX) .replace("DATE_REGEX", DATE_REGEX) + ")" @@ -37,7 +45,11 @@ def get_changelog(repo, branch): - return repo.git.show(f"{branch}:{CHANGELOG_FILE}") + "\n" + branch_tc_settings = tomllib.loads(repo.git.show(f"{branch}:pyproject.toml"))["tool"][ + "towncrier" + ] + branch_changelog_file = branch_tc_settings.get("filename", "NEWS.rst") + return repo.git.show(f"{branch}:{branch_changelog_file}") + "\n" def _tokenize_changes(splits): diff --git a/.ci/scripts/create_release_branch.sh b/.ci/scripts/create_release_branch.sh index 13989c8..7b01419 100755 --- a/.ci/scripts/create_release_branch.sh +++ b/.ci/scripts/create_release_branch.sh @@ -10,7 +10,7 @@ then exit 1 fi -NEW_BRANCH="$(bump2version --dry-run --list release | sed -Ene 's/^new_version=([[:digit:]]+\.[[:digit:]]+)\..*$/\1/p')" +NEW_BRANCH="$(bump-my-version show new_version --increment release | sed -Ene 's/^([[:digit:]]+\.[[:digit:]]+)\.[[:digit:]]+$/\1/p')" if [[ -z "${NEW_BRANCH}" ]] then @@ -23,6 +23,6 @@ git branch "${NEW_BRANCH}" # Clean changelog snippets. find CHANGES/ \( -name "*.feature" -o -name "*.bugfix" -o -name "*.removal" -o -name "*.doc" -o -name "*.translation" -o -name "*.devel" -o -name "*.misc" \) -exec git rm -f \{\} + -bump2version minor --commit --message $'Bump version to {new_version}\n\n[noissue]' --allow-dirty +bump-my-version bump minor --commit --message $'Bump version to {new_version}\n\n[noissue]' --allow-dirty git push origin "${NEW_BRANCH}" diff --git a/.ci/scripts/release.sh b/.ci/scripts/release.sh index 9525f22..a9c3644 100755 --- a/.ci/scripts/release.sh +++ b/.ci/scripts/release.sh @@ -10,7 +10,7 @@ then exit 1 fi -NEW_VERSION="$(bump2version --dry-run --list release | sed -ne 's/^new_version=//p')" +NEW_VERSION="$(bump-my-version show new_version --increment release)" echo "Release ${NEW_VERSION}" if ! [[ "${NEW_VERSION}" == "${BRANCH}"* ]] @@ -20,7 +20,7 @@ then fi towncrier build --yes --version "${NEW_VERSION}" -bump2version release --commit --message "Release {new_version}" --tag --tag-name "{new_version}" --tag-message "Release {new_version}" --allow-dirty -bump2version patch --commit +bump-my-version bump release --commit --message "Release {new_version}" --tag --tag-name "{new_version}" --tag-message "Release {new_version}" --allow-dirty +bump-my-version bump patch --commit git push origin "${BRANCH}" "${NEW_VERSION}" diff --git a/.ci/scripts/validate_commit_message.py b/.ci/scripts/validate_commit_message.py index 7f585ce..6127f73 100644 --- a/.ci/scripts/validate_commit_message.py +++ b/.ci/scripts/validate_commit_message.py @@ -2,11 +2,13 @@ import re import subprocess import sys +import tomllib from pathlib import Path -import toml from github import Github +with open("pyproject.toml", "rb") as fp: + PYPROJECT_TOML = tomllib.load(fp) KEYWORDS = ["fixes", "closes"] BLOCKING_REGEX = [ "DRAFT", @@ -16,9 +18,7 @@ "EXPERIMENT", ] NO_ISSUE = "[noissue]" -CHANGELOG_EXTS = [ - f".{item['directory']}" for item in toml.load("pyproject.toml")["tool"]["towncrier"]["type"] -] +CHANGELOG_EXTS = [f".{item['directory']}" for item in PYPROJECT_TOML["tool"]["towncrier"]["type"]] sha = sys.argv[1] message = subprocess.check_output(["git", "log", "--format=%B", "-n 1", sha]).decode("utf-8") diff --git a/.github/workflows/collect_changes.yml b/.github/workflows/collect_changes.yml index a175b73..808249d 100644 --- a/.github/workflows/collect_changes.yml +++ b/.github/workflows/collect_changes.yml @@ -20,7 +20,7 @@ jobs: git config user.email pulp-infra@redhat.com - name: "Collect changes" run: | - pip install GitPython packaging toml + pip install GitPython packaging python3 .ci/scripts/collect_changes.py - name: "Create Pull Request" uses: "peter-evans/create-pull-request@v6" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7534d7b..6432d80 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,7 +18,7 @@ jobs: - name: "Install dependencies" run: | python -m pip install --upgrade pip - pip install bump2version towncrier~=23.11.0 + pip install bump-my-version~=0.20.0 towncrier~=23.11.0 - name: "Setup git" run: | git config user.name pulpbot diff --git a/.github/workflows/release_branch.yml b/.github/workflows/release_branch.yml index 1932aea..9a2ae6c 100644 --- a/.github/workflows/release_branch.yml +++ b/.github/workflows/release_branch.yml @@ -18,7 +18,7 @@ jobs: git config user.email pulp-infra@redhat.com - name: "Install python dependencies" run: | - pip install bump2version + pip install bump-my-version~=0.20.0 - name: "Create Release Branch" run: | .ci/scripts/create_release_branch.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b3198ec..7d1216a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,24 +16,24 @@ jobs: fail-fast: false matrix: include: - - python: "3.11" - image_tag: "nightly" + - image_tag: "nightly" pulp_api_root: "/relocated/djnd/" - - python: "3.8" - image_tag: "3.28" + python: "3.11" + - image_tag: "3.28" lower_bounds: true - - python: "3.12" - image_tag: "3.26" - - python: "3.8" - image_tag: "3.25" - - python: "3.9" - image_tag: "3.24" + python: "3.8" + - image_tag: "3.26" + python: "3.12" + - image_tag: "3.25" + python: "3.8" + - image_tag: "3.24" pulp_api_root: "/relocated/djnd/" - - python: "3.10" - image_tag: "3.35" - - python: "3.11" - image_tag: "latest" + python: "3.9" + - image_tag: "3.35" + python: "3.10" + - image_tag: "latest" lower_bounds: true + python: "3.11" steps: - uses: "actions/checkout@v4" - uses: "actions/cache@v4" diff --git a/CHANGES/.TEMPLATE.md b/CHANGES/.TEMPLATE.md index 00bafbd..1b9b356 100644 --- a/CHANGES/.TEMPLATE.md +++ b/CHANGES/.TEMPLATE.md @@ -1,13 +1,16 @@ {# TOWNCRIER TEMPLATE #} {% for section, _ in sections.items() %} -{% if section %}### {{section}} +{%- set section_slug = "-" + section|replace(" ", "-")|replace("_", "-")|lower %} +{% if section %}### {{section}} {: #{{versiondata.version}}{{section_slug}} } +{% else %} +{%- set section_slug = "" %} {% endif %} {% if sections[section] %} {% for category, val in definitions.items() if category in sections[section]%} -#### {{ definitions[category]['name'] }} +#### {{ definitions[category]['name'] }} {: #{{versiondata.version}}{{section_slug}}-{{category}} } {% if definitions[category]['showcontent'] %} {% for text, values in sections[section][category].items() %} diff --git a/pyproject.toml b/pyproject.toml index 2b4b466..97d0b52 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,30 +43,13 @@ namespaces = true "*" = ["py.typed", "locale/*/LC_MESSAGES/*.mo"] [tool.pulp_cli_template] +# This section is co-managed by the cookiecutter templates. +# Changes to existing keys should be preserved. app_label = "ostree" glue = true docs = false translations = false -test_matrix = """ -- python: "3.11" - image_tag: "nightly" - pulp_api_root: "/relocated/djnd/" -- python: "3.8" - image_tag: "3.28" - lower_bounds: true -- python: "3.12" - image_tag: "3.26" -- python: "3.8" - image_tag: "3.25" -- python: "3.9" - image_tag: "3.24" - pulp_api_root: "/relocated/djnd/" -- python: "3.10" - image_tag: "3.35" -- python: "3.11" - image_tag: "latest" - lower_bounds: true -""" +main_package = "ostree" [tool.towncrier] filename = "CHANGES.md" @@ -147,3 +130,46 @@ module = [ "schema.*", ] ignore_missing_imports = true + +[tool.bumpversion] +# This section is managed by the cookiecutter templates. +current_version = "0.4.0.dev" +commit = false +tag = false +parse = "(?P\\d+)\\.(?P\\d+)\\.(?P\\d+)(\\.(?P[a-z]+))?" +serialize = [ + "{major}.{minor}.{patch}.{release}", + "{major}.{minor}.{patch}", +] + +[tool.bumpversion.parts.release] +optional_value = "prod" +values = [ + "dev", + "prod", +] + +[[tool.bumpversion.files]] +filename = "./pulp-glue-ostree/pulp_glue/ostree/__init__.py" +search = "__version__ = \"{current_version}\"" +replace = "__version__ = \"{new_version}\"" + +[[tool.bumpversion.files]] +filename = "./pulpcore/cli/ostree/__init__.py" +search = "__version__ = \"{current_version}\"" +replace = "__version__ = \"{new_version}\"" + +[[tool.bumpversion.files]] +filename = "./pulp-glue-ostree/pyproject.toml" +search = "version = \"{current_version}\"" +replace = "version = \"{new_version}\"" + +[[tool.bumpversion.files]] +filename = "./pyproject.toml" +search = "version = \"{current_version}\"" +replace = "version = \"{new_version}\"" + +[[tool.bumpversion.files]] +filename = "./pyproject.toml" +search = "\"pulp-glue-ostree=={current_version}\"" +replace = "\"pulp-glue-ostree=={new_version}\""