Skip to content

Commit

Permalink
reset pre num for tagged version (#467)
Browse files Browse the repository at this point in the history
  • Loading branch information
AllyW authored Aug 30, 2024
1 parent 562ad15 commit 5d9ca38
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 2 deletions.
4 changes: 4 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
Release History
===============
0.1.77
++++++
* `azdev extension cal-next-version`: Fix pre_num when tagged preview version with `major`, `minor`, `patch`.

0.1.76
++++++
* `azdev extension cal-next-version`: Fix preview to stable version case.
Expand Down
2 changes: 1 addition & 1 deletion azdev/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
# license information.
# -----------------------------------------------------------------------------

__VERSION__ = '0.1.76'
__VERSION__ = '0.1.77'
7 changes: 6 additions & 1 deletion azdev/operations/extensions/version_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,16 @@ def update_next_version(self):
self.next_version.major = self.version.major + 1
self.next_version.minor = 0
self.next_version.patch = 0
self.next_version.pre_num = 1
elif self.next_version_segment_tag == VERSION_MINOR_TAG:
self.next_version.minor = self.version.minor + 1
self.next_version.patch = 0
self.next_version.pre_num = 1
elif self.next_version_segment_tag == VERSION_PATCH_TAG:
self.next_version.patch = self.version.micro + 1
self.next_version.pre_num = 1
elif self.next_version_segment_tag == VERSION_PRE_TAG:
self.next_version.patch = (self.version.pre and self.version.pre[1] or 0) + 1
self.next_version.pre_num = (self.version.pre and self.version.pre[1] or 0) + 1
else:
raise ValueError("Unsupported segment tag: {0}".format(self.next_version_segment_tag))
return
Expand All @@ -159,6 +162,8 @@ def update_version_from_differs(self):
self.next_version.major = self.version.major + 1
self.next_version.minor = 0
self.next_version.patch = 0
if self.is_preview:
self.next_version.pre_num = 1
elif len(self.diffs) > 0:
if self.is_preview:
self.next_version.pre_num = self.version.pre[1] + 1
Expand Down
40 changes: 40 additions & 0 deletions azdev/operations/tests/test_extension_versioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,30 @@ def test_version_upgrade_to_normal_version(self):
self.assertEqual(False, version_test.get("is_stable"), "Version tag error")
self.assertEqual(False, version_test.get("preview_tag", False), "Version tag error")

def test_version_upgrade_major_tagged_from_preview(self):
# preview version update pre num but user tagged major
version_test = cal_next_version(base_meta_file=os.path.join(TEST_DIR, "jsons", "az_monitor_meta_before.json"),
diff_meta_file=os.path.join(TEST_DIR, "jsons", "az_monitor_meta_after.json"),
current_version="3.11.0b7", next_version_segment_tag="major")
self.assertEqual("4.0.0b1", version_test.get("version"), "Version cal error")
self.assertEqual(False, version_test.get("is_stable"), "Version tag error")

def test_version_upgrade_minor_tagged_from_preview(self):
# preview version update pre num but user tagged minor
version_test = cal_next_version(base_meta_file=os.path.join(TEST_DIR, "jsons", "az_monitor_meta_before.json"),
diff_meta_file=os.path.join(TEST_DIR, "jsons", "az_monitor_meta_after.json"),
current_version="3.11.0b7", next_version_segment_tag="minor")
self.assertEqual("3.12.0b1", version_test.get("version"), "Version cal error")
self.assertEqual(False, version_test.get("is_stable"), "Version tag error")

def test_version_upgrade_patch_tagged_from_preview(self):
# preview version update pre num but user tagged patch
version_test = cal_next_version(base_meta_file=os.path.join(TEST_DIR, "jsons", "az_monitor_meta_before.json"),
diff_meta_file=os.path.join(TEST_DIR, "jsons", "az_monitor_meta_after.json"),
current_version="3.11.0b7", next_version_segment_tag="patch")
self.assertEqual("3.11.1b1", version_test.get("version"), "Version cal error")
self.assertEqual(False, version_test.get("is_stable"), "Version tag error")

def test_version_upgrade_minor_tagged(self):
# stable version update minor as user tagged
version_test = cal_next_version(base_meta_file=os.path.join(TEST_DIR, "jsons", "az_monitor_meta_before.json"),
Expand All @@ -83,6 +107,22 @@ def test_version_upgrade_patch_tagged(self):
current_version="3.11.0", next_version_segment_tag="patch")
self.assertEqual("3.11.1", version_test.get("version"), "Version cal error")

def test_version_upgrade_pre_tagged(self):
# preview version update major but user tagged pre
version_test = cal_next_version(base_meta_file=os.path.join(TEST_DIR, "jsons", "az_monitor_meta_before.json"),
diff_meta_file=os.path.join(TEST_DIR, "jsons", "az_monitor_meta_after.json"),
current_version="3.11.0b7", next_version_segment_tag="pre")
self.assertEqual("3.11.0b8", version_test.get("version"), "Version cal error")
self.assertEqual(False, version_test.get("is_stable"), "Version tag error")

def test_version_upgrade_pre_untagged(self):
# preview version update major, no tag, follow no major update more than once from last stable version rule
version_test = cal_next_version(base_meta_file=os.path.join(TEST_DIR, "jsons", "az_monitor_meta_before.json"),
diff_meta_file=os.path.join(TEST_DIR, "jsons", "az_monitor_meta_after.json"),
current_version="3.11.0b7")
self.assertEqual("4.0.0b1", version_test.get("version"), "Version cal error")
self.assertEqual(False, version_test.get("is_stable"), "Version tag error")

def test_version_upgrade_patch(self):
# stable version update patch as breaking change detects empty
version_test = cal_next_version(base_meta_file=os.path.join(TEST_DIR, "jsons", "az_ams_meta_before.json"),
Expand Down

0 comments on commit 5d9ca38

Please sign in to comment.