Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions .github/bump_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
import sys
from pathlib import Path

from policyengine_us_data.utils.run_context import (
_REPO_ROOT = Path(__file__).resolve().parent.parent
if str(_REPO_ROOT) not in sys.path:
sys.path.insert(0, str(_REPO_ROOT))

from policyengine_us_data.utils.run_context import ( # noqa: E402
build_candidate_scope,
release_version_from_bump,
)
Expand Down Expand Up @@ -63,9 +67,8 @@ def write_publication_scope(path: Path, payload: dict[str, str]) -> None:


def main():
root = Path(__file__).resolve().parent.parent
pyproject = root / "pyproject.toml"
changelog_dir = root / "changelog.d"
pyproject = _REPO_ROOT / "pyproject.toml"
changelog_dir = _REPO_ROOT / "changelog.d"

current = get_current_version(pyproject)
bump = infer_bump(changelog_dir)
Expand All @@ -78,7 +81,7 @@ def main():
print(f"Would release as at build time: {would_release_as}")

write_publication_scope(
root / PUBLICATION_SCOPE_PATH,
_REPO_ROOT / PUBLICATION_SCOPE_PATH,
{
"base_release_version": current,
"release_bump": bump,
Expand Down
1 change: 1 addition & 0 deletions changelog.d/978.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed publication candidate versioning when the GitHub Actions script is invoked directly from `.github/`.
49 changes: 49 additions & 0 deletions tests/unit/test_publication_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import importlib.util
import json
import os
import shutil
import subprocess
import sys
import types
from pathlib import Path
Expand Down Expand Up @@ -61,6 +64,52 @@ def test_bump_version_computes_candidate_scope_without_mutating_pyproject(
assert module.infer_bump(changelog_dir) == "minor"


def test_bump_version_script_runs_from_github_directory_without_installed_package(
tmp_path,
):
repo = tmp_path / "repo"
script_dir = repo / ".github"
package_utils_dir = repo / "policyengine_us_data" / "utils"
changelog_dir = repo / "changelog.d"
script_dir.mkdir(parents=True)
package_utils_dir.mkdir(parents=True)
changelog_dir.mkdir()
shutil.copyfile(
REPO_ROOT / ".github" / "bump_version.py", script_dir / "bump_version.py"
)
shutil.copyfile(
REPO_ROOT / "policyengine_us_data" / "utils" / "run_context.py",
package_utils_dir / "run_context.py",
)
shutil.copyfile(
REPO_ROOT / "policyengine_us_data" / "utils" / "canonical_json.py",
package_utils_dir / "canonical_json.py",
)
(repo / "policyengine_us_data" / "__init__.py").write_text("")
(package_utils_dir / "__init__.py").write_text("")
_write_pyproject(repo, "1.73.0")
(changelog_dir / "123.added").write_text("Added a thing.\n")
env = os.environ.copy()
env.pop("PYTHONPATH", None)

result = subprocess.run(
[sys.executable, str(script_dir / "bump_version.py")],
cwd=repo,
env=env,
text=True,
capture_output=True,
check=False,
)

assert result.returncode == 0, result.stderr
assert json.loads((script_dir / "publication_scope.json").read_text()) == {
"base_release_version": "1.73.0",
"candidate_scope": "1.73.0-minor",
"release_bump": "minor",
"would_release_as_at_build_time": "1.74.0",
}


def test_fetch_publication_scope_prints_requested_field(
tmp_path,
monkeypatch,
Expand Down