Browse Source

Bump patch version in dependency change detector when tag exists

pull/25279/head
maliming 3 weeks ago
parent
commit
9d46030cb7
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 59
      .github/scripts/test_update_dependency_changes.py
  2. 43
      .github/scripts/update_dependency_changes.py
  3. 1
      .github/workflows/nuget-packages-version-change-detector.yml
  4. 2
      docs/en/package-version-changes.md

59
.github/scripts/test_update_dependency_changes.py

@ -14,7 +14,7 @@ import sys
import os
sys.path.insert(0, os.path.dirname(__file__))
from update_dependency_changes import merge_changes, render_section, normalize_version, extract_preamble
from update_dependency_changes import merge_changes, render_section, normalize_version, extract_preamble, bump_patch_if_released
def test_update_then_revert():
@ -438,6 +438,55 @@ def test_normalize_version_stable():
print("✓ Passed: stable versions unchanged\n")
def test_bump_patch_no_tag():
"""Test: version tag does not exist, should return as-is."""
print("Test 23: bump_patch_if_released - no tag exists")
tag_exists = lambda t: False
assert bump_patch_if_released("10.3.0", tag_exists) == "10.3.0"
assert bump_patch_if_released("10.2.0", tag_exists) == "10.2.0"
print("✓ Passed: version unchanged when tag does not exist\n")
def test_bump_patch_tag_exists():
"""Test: version tag exists, should bump patch."""
print("Test 24: bump_patch_if_released - tag exists")
existing_tags = {"10.3.0"}
tag_exists = lambda t: t in existing_tags
assert bump_patch_if_released("10.3.0", tag_exists) == "10.3.1", \
f"Expected '10.3.1', got: {bump_patch_if_released('10.3.0', tag_exists)}"
print("✓ Passed: version bumped to 10.3.1\n")
def test_bump_patch_multiple_tags():
"""Test: multiple consecutive tags exist, should bump past all."""
print("Test 25: bump_patch_if_released - multiple tags exist")
existing_tags = {"10.3.0", "10.3.1", "10.3.2"}
tag_exists = lambda t: t in existing_tags
assert bump_patch_if_released("10.3.0", tag_exists) == "10.3.3", \
f"Expected '10.3.3', got: {bump_patch_if_released('10.3.0', tag_exists)}"
print("✓ Passed: version bumped past all existing tags\n")
def test_bump_patch_prerelease_skipped():
"""Test: pre-release versions should not be bumped."""
print("Test 26: bump_patch_if_released - pre-release skipped")
tag_exists = lambda t: True # all tags "exist"
assert bump_patch_if_released("10.3.0-rc.1", tag_exists) == "10.3.0-rc.1"
assert bump_patch_if_released("10.3.0-rc.2", tag_exists) == "10.3.0-rc.2"
assert bump_patch_if_released("10.3.0-preview", tag_exists) == "10.3.0-preview"
print("✓ Passed: pre-release versions not bumped\n")
def test_bump_patch_non_zero_patch():
"""Test: version with non-zero patch, tag exists, should bump."""
print("Test 27: bump_patch_if_released - non-zero patch version")
existing_tags = {"10.3.1"}
tag_exists = lambda t: t in existing_tags
assert bump_patch_if_released("10.3.1", tag_exists) == "10.3.2", \
f"Expected '10.3.2', got: {bump_patch_if_released('10.3.1', tag_exists)}"
print("✓ Passed: non-zero patch correctly bumped\n")
def run_all_tests():
"""Run all test cases."""
print("=" * 70)
@ -466,9 +515,14 @@ def run_all_tests():
test_normalize_version_preview()
test_normalize_version_rc()
test_normalize_version_stable()
test_bump_patch_no_tag()
test_bump_patch_tag_exists()
test_bump_patch_multiple_tags()
test_bump_patch_prerelease_skipped()
test_bump_patch_non_zero_patch()
print("=" * 70)
print("All 22 tests passed! ✓")
print("All 27 tests passed! ✓")
print("=" * 70)
print("\nTest coverage summary:")
print(" ✓ Basic scenarios (update, add, remove)")
@ -478,6 +532,7 @@ def run_all_tests():
print(" ✓ Document format validation")
print(" ✓ Preamble extraction (SEO block, no preamble, no heading)")
print(" ✓ Version normalization (preview -> rc.1)")
print(" ✓ Patch version bump when tag already released")
print("=" * 70)

43
.github/scripts/update_dependency_changes.py

@ -25,6 +25,46 @@ def normalize_version(version):
return version
def check_tag_exists(tag):
"""Check if a git tag exists."""
result = subprocess.run(
["git", "tag", "-l", tag],
capture_output=True,
text=True,
)
return result.returncode == 0 and tag in result.stdout.strip().split("\n")
def bump_patch_if_released(version, tag_exists_fn=None):
"""If the version tag already exists, bump the patch version.
Only applies to stable versions (no pre-release suffix like -rc.N).
"""
if tag_exists_fn is None:
tag_exists_fn = check_tag_exists
# Only bump stable versions (no pre-release suffix)
if "-" in version:
return version
parts = version.split(".")
if len(parts) != 3:
return version
major, minor = parts[0], parts[1]
try:
patch = int(parts[2])
except ValueError:
return version
current = version
while tag_exists_fn(current):
patch += 1
current = f"{major}.{minor}.{patch}"
return current
def get_version():
"""Read the current version from common.props."""
try:
@ -296,6 +336,9 @@ def main():
print("Could not read version from common.props.")
sys.exit(1)
version = bump_patch_if_released(version)
print(f"Resolved version: {version}")
diff = get_diff(base_ref)
if not diff:
print("No diff found for Directory.Packages.props.")

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

@ -43,6 +43,7 @@ jobs:
with:
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 1
fetch-tags: true
- name: Fetch base branch
run: git fetch origin ${{ github.event.pull_request.base.ref }}:refs/remotes/origin/${{ github.event.pull_request.base.ref }} --depth=1

2
docs/en/package-version-changes.md

@ -7,7 +7,7 @@
# Package Version Changes
## 10.3.0
## 10.3.1
| Package | Old Version | New Version | PR |
|---------|-------------|-------------|-----|

Loading…
Cancel
Save