-
Notifications
You must be signed in to change notification settings - Fork 222
Expand file tree
/
Copy pathtest_check_version_bumps.py
More file actions
137 lines (109 loc) · 4.19 KB
/
test_check_version_bumps.py
File metadata and controls
137 lines (109 loc) · 4.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
"""Tests for the version bump guard script."""
from __future__ import annotations
import importlib.util
import subprocess
import sys
from pathlib import Path
def _load_prod_module():
repo_root = Path(__file__).resolve().parents[2]
script_path = repo_root / ".github" / "scripts" / "check_version_bumps.py"
name = "check_version_bumps"
spec = importlib.util.spec_from_file_location(name, script_path)
assert spec and spec.loader
mod = importlib.util.module_from_spec(spec)
sys.modules[name] = mod
spec.loader.exec_module(mod)
return mod
_prod = _load_prod_module()
VersionChange = _prod.VersionChange
find_version_changes = _prod.find_version_changes
get_release_pr_version = _prod.get_release_pr_version
validate_version_changes = _prod.validate_version_changes
def _write_version(pyproject: Path, version: str) -> None:
pyproject.write_text(
f'[project]\nname = "{pyproject.parent.name}"\nversion = "{version}"\n'
)
def _init_repo_with_versions(tmp_path: Path, version: str) -> Path:
repo_root = tmp_path / "repo"
repo_root.mkdir()
for package_dir in (
"openhands-sdk",
"openhands-tools",
"openhands-workspace",
"openhands-agent-server",
):
package_path = repo_root / package_dir
package_path.mkdir()
_write_version(package_path / "pyproject.toml", version)
subprocess.run(["git", "init", "-b", "main"], cwd=repo_root, check=True)
subprocess.run(["git", "config", "user.name", "test"], cwd=repo_root, check=True)
subprocess.run(
["git", "config", "user.email", "test@example.com"],
cwd=repo_root,
check=True,
)
subprocess.run(["git", "add", "."], cwd=repo_root, check=True)
subprocess.run(["git", "commit", "-m", "base"], cwd=repo_root, check=True)
subprocess.run(["git", "branch", "origin/main", "HEAD"], cwd=repo_root, check=True)
return repo_root
def test_get_release_pr_version_accepts_title_or_branch():
assert get_release_pr_version("Release v1.15.0", "feature/foo") == ("1.15.0", [])
assert get_release_pr_version("chore: test", "rel-1.15.0") == ("1.15.0", [])
def test_get_release_pr_version_rejects_mismatched_markers():
version, errors = get_release_pr_version("Release v1.15.0", "rel-1.16.0")
assert version is None
assert errors == [
"Release PR markers disagree: title requests v1.15.0 but branch is rel-1.16.0."
]
def test_validate_version_changes_rejects_agent_server_bump_in_non_release_pr():
changes = [
VersionChange(
package="openhands-agent-server",
path=Path("openhands-agent-server/pyproject.toml"),
previous_version="1.14.0",
current_version="1.15.0",
)
]
errors = validate_version_changes(
changes,
pr_title="chore(agent-server): bump version",
pr_head_ref="fix/agent-server-version-bump",
)
assert errors == [
"Package version changes are only allowed in release PRs. Detected "
"changes: openhands-agent-server (1.14.0 -> 1.15.0). Use the Prepare "
"Release workflow so the PR title is 'Release vX.Y.Z' or the branch is "
"'rel-X.Y.Z'."
]
def test_validate_version_changes_accepts_matching_release_version():
changes = [
VersionChange(
package="openhands-agent-server",
path=Path("openhands-agent-server/pyproject.toml"),
previous_version="1.14.0",
current_version="1.15.0",
)
]
assert (
validate_version_changes(
changes,
pr_title="Release v1.15.0",
pr_head_ref="rel-1.15.0",
)
== []
)
def test_find_version_changes_detects_agent_server_package(tmp_path: Path):
repo_root = _init_repo_with_versions(tmp_path, "1.14.0")
_write_version(
repo_root / "openhands-agent-server" / "pyproject.toml",
"1.15.0",
)
changes = find_version_changes(repo_root, "main")
assert changes == [
VersionChange(
package="openhands-agent-server",
path=Path("openhands-agent-server/pyproject.toml"),
previous_version="1.14.0",
current_version="1.15.0",
)
]