Skip to content

Commit 3ee045b

Browse files
committed
test(release): check the version bump touches only the skill frontmatter
1 parent 9309dc3 commit 3ee045b

1 file changed

Lines changed: 28 additions & 1 deletion

File tree

‎tests/test_cli_ops_skill.py‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
Path(ops.__file__).resolve().parent.parent / "skills" / "osl-tasks" / "SKILL.md"
2828
)
2929
PYPROJECT_PATH = Path(__file__).resolve().parent.parent / "pyproject.toml"
30+
SKILL_VERSION_ENTRY = "src/osw/skills/osl-tasks/SKILL.md:version"
3031

3132

3233
def _skill_frontmatter() -> dict:
@@ -113,4 +114,30 @@ def test_skill_is_registered_for_the_release_version_bump():
113114
"""
114115
variables = _pyproject()["tool"]["semantic_release"]["version_variables"]
115116

116-
assert "src/osw/skills/osl-tasks/SKILL.md:version" in variables
117+
assert SKILL_VERSION_ENTRY in variables
118+
119+
120+
def test_release_bump_rewrites_only_the_frontmatter_version(monkeypatch):
121+
"""python-semantic-release rewrites every match of its pattern in the file.
122+
123+
A body line such as 'version: 1.2.3' or 'osw version 1.2.3' would be
124+
rewritten on every release without any test failing, so run the release
125+
tool's own replacement and check that it changes exactly one line.
126+
"""
127+
from semantic_release.version.declarations.pattern import (
128+
PatternVersionDeclaration,
129+
)
130+
from semantic_release.version.version import Version
131+
132+
# The entry's path is relative to the repository root, where the release
133+
# tool runs.
134+
monkeypatch.chdir(PYPROJECT_PATH.parent)
135+
declaration = PatternVersionDeclaration.from_string_definition(
136+
SKILL_VERSION_ENTRY, "v{version}"
137+
)
138+
before = SKILL_MD_PATH.read_text(encoding="utf-8").splitlines()
139+
after = declaration.replace(Version.parse("99.99.99")).splitlines()
140+
141+
assert len(after) == len(before)
142+
changed = [new for old, new in zip(before, after) if old != new]
143+
assert changed == [' version: "99.99.99"']

0 commit comments

Comments
 (0)