Skip to content

Commit 9d46030

Browse files
committed
Bump patch version in dependency change detector when tag exists
1 parent b90ee16 commit 9d46030

4 files changed

Lines changed: 102 additions & 3 deletions

File tree

.github/scripts/test_update_dependency_changes.py

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import os
1515
sys.path.insert(0, os.path.dirname(__file__))
1616

17-
from update_dependency_changes import merge_changes, render_section, normalize_version, extract_preamble
17+
from update_dependency_changes import merge_changes, render_section, normalize_version, extract_preamble, bump_patch_if_released
1818

1919

2020
def test_update_then_revert():
@@ -438,6 +438,55 @@ def test_normalize_version_stable():
438438
print("✓ Passed: stable versions unchanged\n")
439439

440440

441+
def test_bump_patch_no_tag():
442+
"""Test: version tag does not exist, should return as-is."""
443+
print("Test 23: bump_patch_if_released - no tag exists")
444+
tag_exists = lambda t: False
445+
assert bump_patch_if_released("10.3.0", tag_exists) == "10.3.0"
446+
assert bump_patch_if_released("10.2.0", tag_exists) == "10.2.0"
447+
print("✓ Passed: version unchanged when tag does not exist\n")
448+
449+
450+
def test_bump_patch_tag_exists():
451+
"""Test: version tag exists, should bump patch."""
452+
print("Test 24: bump_patch_if_released - tag exists")
453+
existing_tags = {"10.3.0"}
454+
tag_exists = lambda t: t in existing_tags
455+
assert bump_patch_if_released("10.3.0", tag_exists) == "10.3.1", \
456+
f"Expected '10.3.1', got: {bump_patch_if_released('10.3.0', tag_exists)}"
457+
print("✓ Passed: version bumped to 10.3.1\n")
458+
459+
460+
def test_bump_patch_multiple_tags():
461+
"""Test: multiple consecutive tags exist, should bump past all."""
462+
print("Test 25: bump_patch_if_released - multiple tags exist")
463+
existing_tags = {"10.3.0", "10.3.1", "10.3.2"}
464+
tag_exists = lambda t: t in existing_tags
465+
assert bump_patch_if_released("10.3.0", tag_exists) == "10.3.3", \
466+
f"Expected '10.3.3', got: {bump_patch_if_released('10.3.0', tag_exists)}"
467+
print("✓ Passed: version bumped past all existing tags\n")
468+
469+
470+
def test_bump_patch_prerelease_skipped():
471+
"""Test: pre-release versions should not be bumped."""
472+
print("Test 26: bump_patch_if_released - pre-release skipped")
473+
tag_exists = lambda t: True # all tags "exist"
474+
assert bump_patch_if_released("10.3.0-rc.1", tag_exists) == "10.3.0-rc.1"
475+
assert bump_patch_if_released("10.3.0-rc.2", tag_exists) == "10.3.0-rc.2"
476+
assert bump_patch_if_released("10.3.0-preview", tag_exists) == "10.3.0-preview"
477+
print("✓ Passed: pre-release versions not bumped\n")
478+
479+
480+
def test_bump_patch_non_zero_patch():
481+
"""Test: version with non-zero patch, tag exists, should bump."""
482+
print("Test 27: bump_patch_if_released - non-zero patch version")
483+
existing_tags = {"10.3.1"}
484+
tag_exists = lambda t: t in existing_tags
485+
assert bump_patch_if_released("10.3.1", tag_exists) == "10.3.2", \
486+
f"Expected '10.3.2', got: {bump_patch_if_released('10.3.1', tag_exists)}"
487+
print("✓ Passed: non-zero patch correctly bumped\n")
488+
489+
441490
def run_all_tests():
442491
"""Run all test cases."""
443492
print("=" * 70)
@@ -466,9 +515,14 @@ def run_all_tests():
466515
test_normalize_version_preview()
467516
test_normalize_version_rc()
468517
test_normalize_version_stable()
518+
test_bump_patch_no_tag()
519+
test_bump_patch_tag_exists()
520+
test_bump_patch_multiple_tags()
521+
test_bump_patch_prerelease_skipped()
522+
test_bump_patch_non_zero_patch()
469523

470524
print("=" * 70)
471-
print("All 22 tests passed! ✓")
525+
print("All 27 tests passed! ✓")
472526
print("=" * 70)
473527
print("\nTest coverage summary:")
474528
print(" ✓ Basic scenarios (update, add, remove)")
@@ -478,6 +532,7 @@ def run_all_tests():
478532
print(" ✓ Document format validation")
479533
print(" ✓ Preamble extraction (SEO block, no preamble, no heading)")
480534
print(" ✓ Version normalization (preview -> rc.1)")
535+
print(" ✓ Patch version bump when tag already released")
481536
print("=" * 70)
482537

483538

.github/scripts/update_dependency_changes.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,46 @@ def normalize_version(version):
2525
return version
2626

2727

28+
def check_tag_exists(tag):
29+
"""Check if a git tag exists."""
30+
result = subprocess.run(
31+
["git", "tag", "-l", tag],
32+
capture_output=True,
33+
text=True,
34+
)
35+
return result.returncode == 0 and tag in result.stdout.strip().split("\n")
36+
37+
38+
def bump_patch_if_released(version, tag_exists_fn=None):
39+
"""If the version tag already exists, bump the patch version.
40+
41+
Only applies to stable versions (no pre-release suffix like -rc.N).
42+
"""
43+
if tag_exists_fn is None:
44+
tag_exists_fn = check_tag_exists
45+
46+
# Only bump stable versions (no pre-release suffix)
47+
if "-" in version:
48+
return version
49+
50+
parts = version.split(".")
51+
if len(parts) != 3:
52+
return version
53+
54+
major, minor = parts[0], parts[1]
55+
try:
56+
patch = int(parts[2])
57+
except ValueError:
58+
return version
59+
60+
current = version
61+
while tag_exists_fn(current):
62+
patch += 1
63+
current = f"{major}.{minor}.{patch}"
64+
65+
return current
66+
67+
2868
def get_version():
2969
"""Read the current version from common.props."""
3070
try:
@@ -296,6 +336,9 @@ def main():
296336
print("Could not read version from common.props.")
297337
sys.exit(1)
298338

339+
version = bump_patch_if_released(version)
340+
print(f"Resolved version: {version}")
341+
299342
diff = get_diff(base_ref)
300343
if not diff:
301344
print("No diff found for Directory.Packages.props.")

.github/workflows/nuget-packages-version-change-detector.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ jobs:
4343
with:
4444
ref: ${{ github.event.pull_request.head.ref }}
4545
fetch-depth: 1
46+
fetch-tags: true
4647

4748
- name: Fetch base branch
4849
run: git fetch origin ${{ github.event.pull_request.base.ref }}:refs/remotes/origin/${{ github.event.pull_request.base.ref }} --depth=1

docs/en/package-version-changes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
# Package Version Changes
99

10-
## 10.3.0
10+
## 10.3.1
1111

1212
| Package | Old Version | New Version | PR |
1313
|---------|-------------|-------------|-----|

0 commit comments

Comments
 (0)