File tree Expand file tree Collapse file tree 2 files changed +41
-3
lines changed
Expand file tree Collapse file tree 2 files changed +41
-3
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ name: Bump Version
33on :
44 push :
55 branches :
6- - main # Adjust this to your default branch
6+ - main # Adjust to your default branch
77
88jobs :
99 bump-version :
2424 run : |
2525 git config --global user.name "GitHub Action"
2626 git config --global user.email "action@github.com"
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
Original file line number Diff line number Diff line change 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 ()
You can’t perform that action at this time.
0 commit comments