Skip to content

Commit

Permalink
Cleanup .bumpversion.cfg
Browse files Browse the repository at this point in the history
This config file is deprecated. To support older branches, we consult
it as a fallback only.
  • Loading branch information
mdellweg committed Nov 18, 2024
1 parent 0e700c1 commit c863cf4
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ jobs:
- name: "Install python dependencies"
run: |
echo ::group::PYDEPS
pip install towncrier twine wheel httpie docker netaddr boto3 'ansible~=10.3.0' mkdocs jq jsonpatch
pip install towncrier twine wheel httpie docker netaddr boto3 'ansible~=10.3.0' mkdocs jq jsonpatch bump-my-version
echo "HTTPIE_CONFIG_DIR=$GITHUB_WORKSPACE/pulp_catdog/.ci/assets/httpie/" >> $GITHUB_ENV
echo ::endgroup::
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
__pycache__
ci-structure.pdf
.requests_cache.sqlite
13 changes: 1 addition & 12 deletions plugin-template
Original file line number Diff line number Diff line change
Expand Up @@ -315,18 +315,7 @@ def main():
# the config. (note: uses .copy() to avoid a self reference)
config["config"] = config.copy()

# Determine the current version as needed by some templates
try:
b2v_config_path = os.path.join(plugin_root_dir, ".bumpversion.cfg")
with open(b2v_config_path) as b2v_config_file:
for line in b2v_config_file.readlines():
if line.startswith("current_version = "):
config["current_version"] = line[18:].strip()
break
except Exception:
config["current_version"] = "0.1.0a1.dev"

# Determine if plugin is a member of Pulp managed documentation
config["current_version"] = utils.current_version(plugin_root_dir)
config["is_pulpdocs_member"] = config["plugin_name"] in utils.get_pulpdocs_members()

sections = [
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
jinja2
pyyaml
requests~=2.32.3
requests_cache
25 changes: 16 additions & 9 deletions templates/github/.ci/scripts/check_release.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import argparse
import re
import os
import tomllib
import yaml
from tempfile import TemporaryDirectory
from packaging.version import Version
Expand All @@ -17,6 +18,17 @@ Y_CHANGELOG_EXTS = [".feature", ".removal", ".deprecation"]
Z_CHANGELOG_EXTS = [".bugfix", ".doc", ".misc"]


def current_version(repo):
try:
pyproject_toml = tomllib.loads(repo.git.show(f"{DEFAULT_BRANCH}:pyproject.toml"))
current_version = pyproject_toml["project"]["version"]
except Exception:
current_version = repo.git.grep(
"current_version", DEFAULT_BRANCH, "--", ".bumpversion.cfg"
).split("=")[-1]
return Version(current_version)


def main():
"""Check which branches need a release."""
parser = argparse.ArgumentParser()
Expand Down Expand Up @@ -108,15 +120,10 @@ def main():
for change in changes.split("\n"):
_, ext = os.path.splitext(change)
if ext in Y_CHANGELOG_EXTS:
# We don't put Y release bumps in the commit message, check file instead
# The 'current_version' is always the next version to release
next_version = repo.git.grep(
"current_version", DEFAULT_BRANCH, "--", ".bumpversion.cfg"
).split("=")[-1]
next_version = Version(next_version)
print(
f"A new Y-release is needed! New Version: {next_version.base_version}"
)
# We don't put Y release bumps in the commit message, check file instead.
# The 'current_version' is always the dev of the next version to release.
next_version = current_version(repo).base_version
print(f"A new Y-release is needed! New Version: {next_version}")
releases.append(next_version)
break

Expand Down
2 changes: 1 addition & 1 deletion templates/github/.github/workflows/scripts/install.sh.j2
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ set -euv

source .github/workflows/scripts/utils.sh

PLUGIN_VERSION="$(sed -n -e 's/^\s*current_version\s*=\s*//p' .bumpversion.cfg | python -c 'from packaging.version import Version; print(Version(input()))')"
PLUGIN_VERSION="$(bump-my-version show current_version | tail -n -1 | python -c 'from packaging.version import Version; print(Version(input()))')"
PLUGIN_SOURCE="./{{ plugin_name }}/dist/{{ plugin_name | snake }}-${PLUGIN_VERSION}-py3-none-any.whl"

export PULP_API_ROOT="{{ api_root }}"
Expand Down
2 changes: 1 addition & 1 deletion templates/github/.github/workflows/test.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jobs:
{%- endfor %}
{%- endif %}

{{ install_python_deps(["towncrier", "twine", "wheel", "httpie", "docker", "netaddr", "boto3", "ansible~=10.3.0", "mkdocs", "jq", "jsonpatch"]) | indent(6) }}
{{ install_python_deps(["towncrier", "twine", "wheel", "httpie", "docker", "netaddr", "boto3", "ansible~=10.3.0", "mkdocs", "jq", "jsonpatch", "bump-my-version"]) | indent(6) }}

{{ setup_env() | indent(6) }}

Expand Down
1 change: 1 addition & 0 deletions test_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ mock
git+https://github.com/pulp/pulp-smash.git#egg=pulp-smash
pytest
pyyaml
requests_cache
36 changes: 32 additions & 4 deletions utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
#!/usr/bin/env python3
from datetime import timedelta
import itertools
import pathlib
import re
import requests
import requests_cache
import tomllib
import yaml


def current_version(plugin_root_dir):
plugin_root_dir = pathlib.Path(plugin_root_dir)
try:
path = plugin_root_dir / "pyproject.toml"
pyproject_toml = tomllib.loads(path.read_text())
current_version = pyproject_toml["project"]["version"]
except Exception:
try:
path = plugin_root_dir / ".bumpversion.cfg"
for line in path.read_text().splitlines():
if line.startswith("current_version = "):
current_version = line[18:].strip()
break
except Exception:
current_version = "0.1.0a1.dev"
return current_version


def is_valid(name):
Expand Down Expand Up @@ -48,7 +70,8 @@ def get_pulpdocs_members() -> list[str]:
Raises if can't get the authoritative file.
"""
response = requests.get(
session = requests_cache.CachedSession(".requests_cache", expire_after=timedelta(days=1))
response = session.get(
"https://raw.githubusercontent.com/pulp/pulp-docs/main/src/pulp_docs/data/repolist.yml"
)
if response.status_code != 200:
Expand All @@ -57,4 +80,9 @@ def get_pulpdocs_members() -> list[str]:
"This mean we can't know if we should manage the doc-related workflows."
)

return [line.strip()[8:] for line in response.content.decode().split("\n") if "- name:" in line]
repolist = yaml.safe_load(response.content.decode())
return [
repo["name"]
for repo in itertools.chain(*repolist["repos"].values())
if "subpackage_of" not in repo
]

0 comments on commit c863cf4

Please sign in to comment.