4
4
# updates the npm package versions of the editor extensions,
5
5
# updates the changelog and creates an annotated Git tag.
6
6
7
- from utils .cli import prompt_by , title
8
- from utils .properties import PropertiesFile
9
- from utils .changelog import ChangelogFile
10
- from pathlib import Path
7
+ import argparse
11
8
import subprocess
12
9
import re
13
10
import os
14
11
import tempfile
12
+ from pathlib import Path
13
+
14
+ from utils .cli import prompt_by , title
15
+ from utils .properties import PropertiesFile
16
+ from utils .changelog import ChangelogFile
15
17
16
18
class Version :
17
19
def __init__ (self , major , minor , patch ):
@@ -62,6 +64,11 @@ def git_working_dir_is_clean(repo_path):
62
64
PROJECT_VERSION_KEY = "projectVersion"
63
65
64
66
def main ():
67
+ parser = argparse .ArgumentParser (description = "A small utility for updating the project's version and creating tags." )
68
+ parser .add_argument ("--bump-only" , action = "store_true" , help = "Whether only the version should be bumped, without tagging the current version." )
69
+
70
+ args = parser .parse_args ()
71
+
65
72
title ("Project Version Updater" )
66
73
67
74
if not git_working_dir_is_clean (PROJECT_DIR ):
@@ -71,46 +78,55 @@ def main():
71
78
print ("Switch to the master branch first!" )
72
79
return
73
80
74
- increment = None
75
81
properties = PropertiesFile (str (PROJECT_DIR / "gradle.properties" ))
76
82
version = parse_version (properties [PROJECT_VERSION_KEY ])
77
83
78
- print ()
79
- print (f"Releasing version { version } ." )
80
- print ()
84
+ # Current version
81
85
82
- # Fetch new changelog message from user
83
- temp = tempfile .NamedTemporaryFile (delete = False )
84
- temp_path = Path (temp .name ).absolute ()
86
+ if not args .bump_only :
87
+ print ()
88
+ print (f"Releasing version { version } ." )
89
+ print ()
85
90
86
- history = git_history_since_last_tag (PROJECT_DIR )
87
- formatted_history = [f"# { commit } " for commit in history ]
88
- initial_message = [
89
- "" ,
90
- "" ,
91
- "# Please enter a changelog/release message." ,
92
- f"# This is the history since the last tag:"
93
- ] + formatted_history
91
+ # Fetch new changelog message from user
92
+ temp = tempfile .NamedTemporaryFile (delete = False )
93
+ temp_path = Path (temp .name ).absolute ()
94
94
95
- with open (temp_path , "w" ) as temp_contents :
96
- temp_contents .write ("\n " .join (initial_message ))
95
+ history = git_history_since_last_tag (PROJECT_DIR )
96
+ formatted_history = [f"# { commit } " for commit in history ]
97
+ initial_message = [
98
+ "" ,
99
+ "" ,
100
+ "# Please enter a changelog/release message." ,
101
+ f"# This is the history since the last tag:"
102
+ ] + formatted_history
97
103
98
- subprocess .call ([EDITOR , str (temp_path )])
104
+ with open (temp_path , "w" ) as temp_contents :
105
+ temp_contents .write ("\n " .join (initial_message ))
99
106
100
- with open (temp_path , "r" ) as temp_contents :
101
- changelog_message = [line .strip () for line in temp_contents .readlines () if not line .startswith ("#" ) and len (line .strip ()) > 0 ]
107
+ subprocess .call ([EDITOR , str (temp_path )])
102
108
103
- temp . close ()
104
- temp_path . unlink ()
109
+ with open ( temp_path , "r" ) as temp_contents :
110
+ changelog_message = [ line . strip () for line in temp_contents . readlines () if not line . startswith ( "#" ) and len ( line . strip ()) > 0 ]
105
111
106
- print ("Updating changelog..." )
107
- changelog = ChangelogFile (PROJECT_DIR / "CHANGELOG.md" )
108
- changelog .prepend_version (version , changelog_message )
112
+ temp .close ()
113
+ temp_path .unlink ()
109
114
110
- print ( "Creating Git tag..." )
111
- tag_message = " \n " . join ([ f"Version { version } " , "" ] + changelog_message )
112
- subprocess . run ([ "git" , "tag" , "-a" , f" { version } " , "-m" , tag_message ], cwd = PROJECT_DIR )
115
+ if not changelog_message :
116
+ print ( "No message, exiting..." )
117
+ return
113
118
119
+ print ("Updating changelog..." )
120
+ changelog = ChangelogFile (PROJECT_DIR / "CHANGELOG.md" )
121
+ changelog .prepend_version (version , changelog_message )
122
+
123
+ print ("Creating Git tag..." )
124
+ tag_message = "\n " .join ([f"Version { version } " , "" ] + changelog_message )
125
+ subprocess .run (["git" , "tag" , "-a" , f"{ version } " , "-m" , tag_message ], cwd = PROJECT_DIR )
126
+
127
+ # Next version
128
+
129
+ increment = None
114
130
while increment not in INCREMENTS .keys ():
115
131
increment = input ("How do you want to increment? [major/minor/patch] " )
116
132
0 commit comments