From 6b7147e72bfaee1f074d0e70f254add6abc50bba Mon Sep 17 00:00:00 2001 From: voluntas Date: Sun, 13 Oct 2024 10:06:39 +0900 Subject: [PATCH 1/2] =?UTF-8?q?canary.py=20=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- canary.py | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 canary.py diff --git a/canary.py b/canary.py new file mode 100644 index 00000000..40c748a8 --- /dev/null +++ b/canary.py @@ -0,0 +1,100 @@ +import argparse +import re +import subprocess + +VERSION_FILE = "VERSION" +EXAMPLES_VERSION_FILE = "examples/VERSION" + + +def update_version(version_content): + updated_content = [] + sora_version_updated = False + + for line in version_content: + if line.startswith("SORA_CPP_SDK_VERSION="): + version_match = re.match( + r"SORA_CPP_SDK_VERSION=(\d{4}\.\d+\.\d+)(-canary\.(\d+))?", line + ) + if version_match: + major_minor_patch = version_match.group(1) + canary_suffix = version_match.group(2) + if canary_suffix is None: + new_version = f"{major_minor_patch}-canary.0" + else: + canary_number = int(version_match.group(3)) + new_version = f"{major_minor_patch}-canary.{canary_number + 1}" + + updated_content.append(f"SORA_CPP_SDK_VERSION={new_version}") + sora_version_updated = True + else: + updated_content.append(line) + else: + updated_content.append(line) + + if not sora_version_updated: + raise ValueError("SORA_CPP_SDK_VERSION not found in VERSION file.") + + return updated_content + + +def write_version_file(filename, updated_content, dry_run): + if dry_run: + print(f"Dry run: The following changes would be written to {filename}:") + for line in updated_content: + print(line.strip()) + else: + with open(filename, "w") as file: + file.write("\n".join(updated_content) + "\n") + print(f"{filename} updated.") + + +def git_operations(dry_run): + commands = [ + ["git", "commit", "-am", "Update VERSION and examples/VERSION"], + ["git", "push"], + [ + "git", + "tag", + "-a", + "v$(grep SORA_CPP_SDK_VERSION VERSION | cut -d '=' -f 2)", + "-m", + "Tagging new release", + ], + ] + + for command in commands: + if dry_run: + print(f"Dry run: Would execute: {' '.join(command)}") + else: + print(f"Executing: {' '.join(command)}") + subprocess.run(command, check=True) + + +def main(): + parser = argparse.ArgumentParser( + description="Update VERSION and examples/VERSION file and push changes with git." + ) + parser.add_argument( + "--dry-run", action="store_true", help="Perform a dry run without making any changes." + ) + args = parser.parse_args() + + # Read the VERSION file + with open(VERSION_FILE, "r") as file: + version_content = file.readlines() + + # Update the VERSION content + updated_content = update_version(version_content) + + # Write updated content back to VERSION file + write_version_file(VERSION_FILE, updated_content, args.dry_run) + + # Also update examples/VERSION + write_version_file(EXAMPLES_VERSION_FILE, updated_content, args.dry_run) + + # Perform git operations + git_operations(args.dry_run) + + +if __name__ == "__main__": + main() From 4721c56e5c186b8e798c923d219bcec41120ded6 Mon Sep 17 00:00:00 2001 From: voluntas Date: Sun, 13 Oct 2024 15:49:07 +0900 Subject: [PATCH 2/2] canary.py --- canary.py | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/canary.py b/canary.py index 40c748a8..ff03c249 100644 --- a/canary.py +++ b/canary.py @@ -9,6 +9,7 @@ def update_version(version_content): updated_content = [] sora_version_updated = False + new_version = None for line in version_content: if line.startswith("SORA_CPP_SDK_VERSION="): @@ -34,7 +35,7 @@ def update_version(version_content): if not sora_version_updated: raise ValueError("SORA_CPP_SDK_VERSION not found in VERSION file.") - return updated_content + return updated_content, new_version def write_version_file(filename, updated_content, dry_run): @@ -48,26 +49,24 @@ def write_version_file(filename, updated_content, dry_run): print(f"{filename} updated.") -def git_operations(dry_run): - commands = [ - ["git", "commit", "-am", "Update VERSION and examples/VERSION"], - ["git", "push"], - [ - "git", - "tag", - "-a", - "v$(grep SORA_CPP_SDK_VERSION VERSION | cut -d '=' -f 2)", - "-m", - "Tagging new release", - ], - ] - - for command in commands: - if dry_run: - print(f"Dry run: Would execute: {' '.join(command)}") - else: - print(f"Executing: {' '.join(command)}") - subprocess.run(command, check=True) +def git_operations(new_version, dry_run): + if dry_run: + print("Dry run: Would execute git commit -am 'Update VERSION and examples/VERSION'") + print(f"Dry run: Would execute git tag {new_version}") + print("Dry run: Would execute git push") + print(f"Dry run: Would execute git push origin {new_version}") + else: + print("Executing: git commit -am 'Update VERSION and examples/VERSION'") + subprocess.run(["git", "commit", "-am", "Update VERSION and examples/VERSION"], check=True) + + print(f"Executing: git tag {new_version}") + subprocess.run(["git", "tag", new_version], check=True) + + print("Executing: git push") + subprocess.run(["git", "push"], check=True) + + print(f"Executing: git push origin {new_version}") + subprocess.run(["git", "push", "origin", new_version], check=True) def main(): @@ -84,7 +83,7 @@ def main(): version_content = file.readlines() # Update the VERSION content - updated_content = update_version(version_content) + updated_content, new_version = update_version(version_content) # Write updated content back to VERSION file write_version_file(VERSION_FILE, updated_content, args.dry_run) @@ -93,7 +92,7 @@ def main(): write_version_file(EXAMPLES_VERSION_FILE, updated_content, args.dry_run) # Perform git operations - git_operations(args.dry_run) + git_operations(new_version, args.dry_run) if __name__ == "__main__":