Skip to content

Commit fa31349

Browse files
committed
Added script
1 parent 0624caa commit fa31349

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

.github/workflows/bump-version.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Bump Version
33
on:
44
push:
55
branches:
6-
- main # Adjust this to your default branch
6+
- main # Adjust to your default branch
77

88
jobs:
99
bump-version:
@@ -24,6 +24,6 @@ jobs:
2424
run: |
2525
git config --global user.name "GitHub Action"
2626
git config --global user.email "[email protected]"
27-
git add version.txt # Or version.py
28-
git commit -m "Bump version" || echo "No changes to commit"
27+
git add setup.py
28+
git commit -m "Bump version in setup.py [skip ci]" || echo "No changes to commit"
2929
git push

bump_version.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# bump_version.py
2+
import re
3+
4+
def increment_version(version):
5+
# Split version into major, minor, patch
6+
major, minor, patch = map(int, version.split('.'))
7+
# Increment patch version by 1 (you can adjust to minor/major if needed)
8+
patch += 1
9+
return f"{major}.{minor}.{patch}"
10+
11+
def update_setup_py():
12+
# Read the current setup.py content
13+
with open("setup.py", "r") as f:
14+
content = f.read()
15+
16+
# Find the current version using regex
17+
version_match = re.search(r'version="(\d+\.\d+\.\d+)"', content)
18+
if not version_match:
19+
raise ValueError("Version not found in setup.py")
20+
21+
current_version = version_match.group(1)
22+
new_version = increment_version(current_version)
23+
24+
# Replace the old version with the new one
25+
new_content = re.sub(
26+
r'version="\d+\.\d+\.\d+"',
27+
f'version="{new_version}"',
28+
content
29+
)
30+
31+
# Write the updated content back to setup.py
32+
with open("setup.py", "w") as f:
33+
f.write(new_content)
34+
35+
print(f"Updated version from {current_version} to {new_version}")
36+
37+
if __name__ == "__main__":
38+
update_setup_py()

0 commit comments

Comments
 (0)