Skip to content

Commit e1d95cf

Browse files
committed
removed suffix, removed release label,and added new variables with added exception if Label is invalid
1 parent 22bef15 commit e1d95cf

File tree

2 files changed

+25
-29
lines changed

2 files changed

+25
-29
lines changed

.github/workflows/version-bump.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ jobs:
99
if: >
1010
github.event.label.name == 'patch' ||
1111
github.event.label.name == 'minor' ||
12-
github.event.label.name == 'major' ||
13-
github.event.label.name == 'release'
12+
github.event.label.name == 'major'
1413
runs-on: ubuntu-latest
1514

1615
steps:

tools/bump_version.py

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import sys
22

3-
# The GitHub label passed as an argument: patch, minor, major, release
3+
# The GitHub label passed as an argument: patch, minor, major
44
LABEL = sys.argv[1]
55

66
# The file that stores the current version
@@ -21,20 +21,16 @@ def parse_version(v):
2121
Parse a version string like "0.5.0-draft" into parts:
2222
major, minor, patch, and optional suffix (e.g., "-draft").
2323
"""
24-
parts = v.split(".") # Split into ['0', '5', '0-draft']
24+
# Remove suffix if present
25+
v = v.split("-", 1)[0]
26+
27+
parts = v.split(".") # Split into ['0', '5', '0']
28+
2529
major = int(parts[0])
2630
minor = int(parts[1])
31+
patch = int(parts[2])
2732

28-
# Handle patch number and suffix(if exist)
29-
if "-" in parts[2]:
30-
patch_str, suffix = parts[2].split("-", 1)
31-
patch = int(patch_str)
32-
suffix = "-" + suffix # Keep the dash in the suffix
33-
else:
34-
patch = int(parts[2])
35-
suffix = ""
36-
37-
return major, minor, patch, suffix
33+
return major, minor, patch
3834

3935

4036
def bump_version(major, minor, patch):
@@ -44,31 +40,32 @@ def bump_version(major, minor, patch):
4440
- minor: increment minor, reset patch
4541
- major: increment major, reset minor and patch
4642
"""
43+
new_major = major
44+
new_minor = minor
45+
new_patch = patch
46+
4747
if LABEL == "patch":
48-
patch = patch + 1
48+
new_patch = patch + 1
4949
elif LABEL == "minor":
50-
minor = minor + 1
51-
patch = 0
50+
new_minor = minor + 1
51+
new_patch = 0
5252
elif LABEL == "major":
53-
major = major + 1
54-
minor = 0
55-
patch = 0
56-
return major, minor, patch
53+
new_major = major + 1
54+
new_minor = 0
55+
new_patch = 0
56+
else:
57+
raise ValueError(f"Invalid Label: {LABEL}")
58+
return new_major, new_minor, new_patch
5759

5860
def main():
5961
# Read current version
6062
old_version = read_version()
6163

6264
# Parse current version
63-
major, minor, patch, suffix = parse_version(old_version)
65+
major, minor, patch = parse_version(old_version)
6466

65-
# If label is release, remove the "-draft" suffix
66-
if LABEL == "release":
67-
new_version = f"{major}.{minor}.{patch}"
68-
else:
69-
# Otherwise, bump version according to label
70-
new_major, new_minor, new_patch = bump_version(major, minor, patch)
71-
new_version = f"{new_major}.{new_minor}.{new_patch}-draft"
67+
new_major, new_minor, new_patch = bump_version(major, minor, patch)
68+
new_version = f"{new_major}.{new_minor}.{new_patch}"
7269

7370
# Prevent race conditions by only writing if version changed
7471
if new_version != old_version:

0 commit comments

Comments
 (0)