|
| 1 | +import pytest |
| 2 | + |
1 | 3 | from commitizen.git import GitTag |
2 | 4 | from commitizen.tags import TagRules |
3 | 5 |
|
@@ -140,3 +142,81 @@ def test_is_version_tag_accepts_dotless_devrelease_in_custom_tag_format(): |
140 | 142 |
|
141 | 143 | extracted = rules.extract_version(_git_tag("version-1.2.3dev1")) |
142 | 144 | assert str(extracted) == "1.2.3.dev1" |
| 145 | + |
| 146 | + |
| 147 | +def test_monorepo_ignored_tag_formats_keep_own_tags(capsys: pytest.CaptureFixture): |
| 148 | + """Regression test for the monorepo workflow in |
| 149 | + ``docs/tutorials/monorepo_guidance.md``. |
| 150 | +
|
| 151 | + Each component configures a suffixed ``tag_format`` and ignores sibling |
| 152 | + component tags with a wildcard. |
| 153 | +
|
| 154 | + Ignoring sibling tags must not reject the component's own tags. Ignored |
| 155 | + tags are expected noise, so they must not emit "Invalid version tag" |
| 156 | + warnings; only truly unexpected tags warn. |
| 157 | + """ |
| 158 | + library_foo_rules = TagRules( |
| 159 | + tag_format="${version}-library-foo", |
| 160 | + ignored_tag_formats=["${version}-library-(?!foo$).*"], |
| 161 | + ) |
| 162 | + library_zoo_rules = TagRules( |
| 163 | + tag_format="${version}-library-zoo", |
| 164 | + ignored_tag_formats=["${version}-library-(?!zoo$).*"], |
| 165 | + ) |
| 166 | + |
| 167 | + # Own tags remain version tags, sibling tags are filtered out. |
| 168 | + assert library_foo_rules.is_version_tag("1.0.0-library-foo") is True |
| 169 | + assert library_foo_rules.is_version_tag("1.0.0-library-zoo") is False |
| 170 | + |
| 171 | + assert library_zoo_rules.is_version_tag("1.0.0-library-zoo") is True |
| 172 | + assert library_zoo_rules.is_version_tag("1.0.0-library-foo") is False |
| 173 | + |
| 174 | + # Check also for prefix |
| 175 | + assert library_foo_rules.is_ignored_tag("1.0.0-library-foobar") is True |
| 176 | + |
| 177 | + # The own tag is parseable, so a rejection above is a filtering problem, |
| 178 | + # not a parsing one. |
| 179 | + extracted = library_foo_rules.extract_version(_git_tag("1.0.0-library-foo")) |
| 180 | + assert str(extracted) == "1.0.0" |
| 181 | + |
| 182 | + # Ignored tags do not warn. Unknown tags still do. |
| 183 | + library_foo_rules.is_version_tag("1.0.0-library-zoo", warn=True) |
| 184 | + library_foo_rules.is_version_tag("unexpected-tag", warn=True) |
| 185 | + captured = capsys.readouterr() |
| 186 | + assert "1.0.0-library-zoo" not in captured.err |
| 187 | + assert "unexpected-tag" in captured.err |
| 188 | + |
| 189 | + |
| 190 | +def test_monorepo_get_version_tags_filters_sibling_components( |
| 191 | + capsys: pytest.CaptureFixture, |
| 192 | +): |
| 193 | + """``get_version_tags`` keeps only the component's own tags when the |
| 194 | + repository also contains sibling component tags, as configured in |
| 195 | + ``docs/tutorials/monorepo_guidance.md``. |
| 196 | +
|
| 197 | + The changelog and the ``scm`` version provider use this filtering, so the |
| 198 | + ignored wildcard must silence sibling tags without dropping this |
| 199 | + component's own tags. |
| 200 | + """ |
| 201 | + tags = [ |
| 202 | + _git_tag("1.0.0-library-b"), |
| 203 | + _git_tag("1.0.0-library-z"), |
| 204 | + _git_tag("1.1.0-library-b"), |
| 205 | + _git_tag("unexpected-tag"), |
| 206 | + ] |
| 207 | + rules = TagRules( |
| 208 | + tag_format="${version}-library-b", |
| 209 | + ignored_tag_formats=["${version}-library-(?!b$).*"], |
| 210 | + ) |
| 211 | + |
| 212 | + version_tags = rules.get_version_tags(tags, warn=True) |
| 213 | + |
| 214 | + assert [t.name for t in version_tags] == [ |
| 215 | + "1.0.0-library-b", |
| 216 | + "1.1.0-library-b", |
| 217 | + ] |
| 218 | + |
| 219 | + # Only the truly unexpected tag warns; sibling tags are known noise. |
| 220 | + captured = capsys.readouterr() |
| 221 | + assert "unexpected-tag" in captured.err |
| 222 | + assert "1.0.0-library-z" not in captured.err |
0 commit comments