Skip to content

Commit

Permalink
Apply the template from pulp-cli
Browse files Browse the repository at this point in the history
[noissue]
  • Loading branch information
lubosmj committed Apr 30, 2024
1 parent d565e60 commit 5e6d0ec
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 73 deletions.
21 changes: 0 additions & 21 deletions .bumpversion.cfg

This file was deleted.

20 changes: 16 additions & 4 deletions .ci/scripts/collect_changes.py
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -21,23 +24,32 @@
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 = (
"("
+ re.escape(
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)
+ ")"
)


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):
Expand Down
4 changes: 2 additions & 2 deletions .ci/scripts/create_release_branch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}"
6 changes: 3 additions & 3 deletions .ci/scripts/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"* ]]
Expand All @@ -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}"
8 changes: 4 additions & 4 deletions .ci/scripts/validate_commit_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/collect_changes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
git config user.email [email protected]
- 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"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release_branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
git config user.email [email protected]
- 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
Expand Down
28 changes: 14 additions & 14 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 5 additions & 2 deletions CHANGES/.TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -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() %}
Expand Down
66 changes: 46 additions & 20 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)(\\.(?P<release>[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}\""

0 comments on commit 5e6d0ec

Please sign in to comment.