5b478d2831
Version bumps and release tags were entirely manual; the only CI automation was sync-version-on-tag, which corrects pyproject.toml if a hand-pushed tag drifted. This flips that: a new bump-version job (needs the four existing checks, gated to actual merge commits on master via HEAD^@'s parent count so direct/squash/rebase pushes are untouched) uses bump-my-version to auto-bump the patch version when a merged branch didn't already bump it itself, then generates a changelog entry with git-cliff and pushes a matching vX.Y.Z tag. git-cliff's cliff.toml is tuned to this repo's plain imperative commit style (no feat:/fix: prefixes): commits are grouped Added/Fixed/Removed/Changed by leading verb, "(gitea #N)" is linkified, and merge/[skip ci] commits are dropped. Per user decision during planning: the changelog generator folds in @lars's comment on the issue (asking to fold in changelog generation rather than deferring it), and CHANGELOG.md starts fresh with no backfill of v0.2.0-v0.3.3. sync-version-on-tag is left untouched as the safety net for hand-tagging. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
78 lines
2.7 KiB
Python
78 lines
2.7 KiB
Python
"""Config-correctness tests for the CI version-bump/tag/changelog automation
|
|
(gitea #50). The workflow YAML itself can only be exercised by a real push to
|
|
master, so these check the two config files it drives (.bumpversion.toml,
|
|
cliff.toml) against real repo content instead.
|
|
"""
|
|
|
|
import re
|
|
import shutil
|
|
import subprocess
|
|
import tomllib
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
_ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
|
|
def test_bumpversion_search_pattern_matches_pyproject():
|
|
bump_config = tomllib.loads((_ROOT / ".bumpversion.toml").read_text())["tool"]["bumpversion"]
|
|
current_version = bump_config["current_version"]
|
|
search = bump_config["files"][0]["search"].format(current_version=current_version)
|
|
|
|
pyproject = (_ROOT / "pyproject.toml").read_text()
|
|
assert search in pyproject, (
|
|
f"bumpversion search pattern {search!r} (rendered from .bumpversion.toml's "
|
|
f"current_version={current_version!r}) not found in pyproject.toml — "
|
|
"the bump would silently edit nothing"
|
|
)
|
|
|
|
|
|
@pytest.mark.skipif(shutil.which("git-cliff") is None, reason="git-cliff binary not on PATH")
|
|
def test_cliff_config_groups_and_links_commits(tmp_path):
|
|
repo = tmp_path / "repo"
|
|
repo.mkdir()
|
|
subprocess.run(["git", "init", "-q"], cwd=repo, check=True)
|
|
subprocess.run(["git", "config", "user.name", "test"], cwd=repo, check=True)
|
|
subprocess.run(["git", "config", "user.email", "test@example.com"], cwd=repo, check=True)
|
|
|
|
_commit(repo, "Add class-balanced secondary particle-type loss (gitea #44)")
|
|
_commit(repo, "Fix leaking secondary energy budget")
|
|
_commit(repo, "Merge pull request 'Add X' (#1) from fix/issue-1 into master")
|
|
_commit(repo, "chore: bump version 0.3.3 -> 0.3.4 [skip ci]")
|
|
|
|
result = subprocess.run(
|
|
[
|
|
"git-cliff",
|
|
"--config",
|
|
str(_ROOT / "cliff.toml"),
|
|
"--repository",
|
|
str(repo),
|
|
"--tag",
|
|
"v0.3.4",
|
|
"--unreleased",
|
|
],
|
|
capture_output=True,
|
|
text=True,
|
|
check=True,
|
|
)
|
|
changelog = result.stdout
|
|
|
|
assert "## [0.3.4]" in changelog
|
|
assert "### Added" in changelog
|
|
assert "### Fixed" in changelog
|
|
assert re.search(
|
|
r"\[gitea #44\]\(https://git\.larsbogner\.de/lars/giant/issues/44\)",
|
|
changelog,
|
|
)
|
|
assert "Add class-balanced secondary particle-type loss" in changelog
|
|
assert "Fix leaking secondary energy budget" in changelog
|
|
assert "Merge pull request" not in changelog
|
|
assert "skip ci" not in changelog
|
|
|
|
|
|
def _commit(repo: Path, message: str) -> None:
|
|
(repo / "f.txt").write_text(message)
|
|
subprocess.run(["git", "add", "f.txt"], cwd=repo, check=True)
|
|
subprocess.run(["git", "commit", "-q", "-m", message], cwd=repo, check=True)
|