|
27 | 27 | Path(ops.__file__).resolve().parent.parent / "skills" / "osl-tasks" / "SKILL.md" |
28 | 28 | ) |
29 | 29 | PYPROJECT_PATH = Path(__file__).resolve().parent.parent / "pyproject.toml" |
| 30 | +SKILL_VERSION_ENTRY = "src/osw/skills/osl-tasks/SKILL.md:version" |
30 | 31 |
|
31 | 32 |
|
32 | 33 | def _skill_frontmatter() -> dict: |
@@ -113,4 +114,30 @@ def test_skill_is_registered_for_the_release_version_bump(): |
113 | 114 | """ |
114 | 115 | variables = _pyproject()["tool"]["semantic_release"]["version_variables"] |
115 | 116 |
|
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