Skip to content

Commit

Permalink
Update version script to support backport branches
Browse files Browse the repository at this point in the history
  • Loading branch information
Skyedra committed Aug 19, 2024
1 parent 41a2bd6 commit e52cc50
Showing 1 changed file with 30 additions and 12 deletions.
42 changes: 30 additions & 12 deletions Tools/version.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#!/usr/bin/env python3

# Tools/version.py 1.2.3
# Tools/version.py April2024 1.2.3

# This version of the script adds support for engine branches
# As of current writing, this is only for backport branches and otherwise main branch doesn't use a branch identifier
# ex:
# mv-1.0.0 is the mainline branch
# mv-April2024-1.0.0 is April2024 backports branch

import subprocess
import sys
Expand All @@ -11,20 +17,28 @@

def main():
parser = argparse.ArgumentParser(description = "Tool for versioning RobustToolbox: commits the version config update and sets your local tag.")
parser.add_argument("branch", help = "Branch that will be written to tag. Ex: April2024")
parser.add_argument("version", help = "Version that will be written to tag. Format: x.x.x")
parser.add_argument("--file-only", action = "store_true", help = "Does not perform the Git part of the update (for writes only, not undos!)")
parser.add_argument("--undo", action = "store_true", help = "Macro to rebase over last commit and remove version tag. Version still required.")

result = parser.parse_args()

version: str = result.version
branch: str = result.branch
undo: bool = result.undo
file_only: bool = result.file_only

tagName = "mv-" + branch + "-" + version

if branch == None:
print("Branch required in this version of script (try --help)")
sys.exit(1)

if undo:
undo_version(version)
undo_version(tagName)
else:
write_version(version, file_only)
write_version(version, file_only, tagName)


def verify_version(version: str):
Expand All @@ -36,7 +50,7 @@ def verify_version(version: str):
# this verifies parsability, exceptions here are expected for bad input
int(v)

def write_version(version: str, file_only: bool):
def write_version(version: str, file_only: bool, tagName:bool):
# Writing operation
if version == None:
print("Version required for a writing operation (try --help)")
Expand All @@ -45,7 +59,7 @@ def write_version(version: str, file_only: bool):
# Verify
verify_version(version)

update_release_notes(version)
update_release_notes(tagName)

# Update
with open("MSBuild/Robust.Engine.Version.props", "w") as file:
Expand All @@ -59,13 +73,13 @@ def write_version(version: str, file_only: bool):
subprocess.run(["git", "commit", "--allow-empty", "-m", "Version: " + version, "MSBuild/Robust.Engine.Version.props", "RELEASE-NOTES-SSMV.md"], check=True)

# Tag
subprocess.run(["git", "tag", "mv-" + version], check=True)
print("Tagged as mv-" + version)
subprocess.run(["git", "tag", tagName], check=True)
print("Tagged as " + tagName)
else:
print("Did not tag " + version)
print("Did not tag " + tagName)


def update_release_notes(version: str):
def update_release_notes(tagName: str):
with open("RELEASE-NOTES-SSMV.md", "r") as file:
lines = file.readlines()

Expand All @@ -87,7 +101,7 @@ def update_release_notes(version: str):
i -= 3

# Replace current "master" header with the new version to tag.
lines[master_header] = f"## {version}\n"
lines[master_header] = f"## {tagName}\n"

# Insert template above newest version.
lines[master_header : master_header] = template_lines
Expand All @@ -96,14 +110,18 @@ def update_release_notes(version: str):
file.writelines(lines)


def undo_version(version: str):
def undo_version(tagName: str):
# Might want to work out some magic here to auto-identify the version from the commit
if version == None:
print("Version required for undo operation (try --help)")
sys.exit(1)

if branch == None:
print("branch required for undo operation (try --help)")
sys.exit(1)

# Delete the version (good verification all by itself really)
subprocess.run(["git", "tag", "-d", "mv-" + version], check=True)
subprocess.run(["git", "tag", "-d", tagName], check=True)
# Tag the commit we're about to delete because we could be deleting the wrong thing.
savename = "version-undo-backup-" + str(int(time.time()))
subprocess.run(["git", "tag", savename], check=True)
Expand Down

0 comments on commit e52cc50

Please sign in to comment.