Skip to content

Commit 50c276a

Browse files
committed
Add --bump-only flag to release_version script
1 parent af493ed commit 50c276a

File tree

1 file changed

+48
-32
lines changed

1 file changed

+48
-32
lines changed

scripts/release_version.py

Lines changed: 48 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44
# updates the npm package versions of the editor extensions,
55
# updates the changelog and creates an annotated Git tag.
66

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
118
import subprocess
129
import re
1310
import os
1411
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
1517

1618
class Version:
1719
def __init__(self, major, minor, patch):
@@ -62,6 +64,11 @@ def git_working_dir_is_clean(repo_path):
6264
PROJECT_VERSION_KEY = "projectVersion"
6365

6466
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+
6572
title("Project Version Updater")
6673

6774
if not git_working_dir_is_clean(PROJECT_DIR):
@@ -71,46 +78,55 @@ def main():
7178
print("Switch to the master branch first!")
7279
return
7380

74-
increment = None
7581
properties = PropertiesFile(str(PROJECT_DIR / "gradle.properties"))
7682
version = parse_version(properties[PROJECT_VERSION_KEY])
7783

78-
print()
79-
print(f"Releasing version {version}.")
80-
print()
84+
# Current version
8185

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()
8590

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()
9494

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
97103

98-
subprocess.call([EDITOR, str(temp_path)])
104+
with open(temp_path, "w") as temp_contents:
105+
temp_contents.write("\n".join(initial_message))
99106

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)])
102108

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]
105111

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()
109114

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
113118

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
114130
while increment not in INCREMENTS.keys():
115131
increment = input("How do you want to increment? [major/minor/patch] ")
116132

0 commit comments

Comments
 (0)