From d98bcac6190c29121c00678015af99ea7657827b Mon Sep 17 00:00:00 2001 From: WardPearce Date: Sat, 11 May 2024 14:29:22 +1200 Subject: [PATCH] Fixed android versioning & added a script to keep it updated --- materialious/android/app/build.gradle | 4 +- update_versions.py | 54 +++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 update_versions.py diff --git a/materialious/android/app/build.gradle b/materialious/android/app/build.gradle index 3964117a..a8c68d07 100644 --- a/materialious/android/app/build.gradle +++ b/materialious/android/app/build.gradle @@ -7,8 +7,8 @@ android { applicationId "us.materialio.app" minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion - versionCode 1 - versionName "1.0" + versionCode 6 + versionName "1.0.6" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" aaptOptions { // Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps. diff --git a/update_versions.py b/update_versions.py new file mode 100644 index 00000000..c057f930 --- /dev/null +++ b/update_versions.py @@ -0,0 +1,54 @@ +"""Small script for keeping versioning consistent for Materialious +""" + +import json +import os +import re + +LATEST_VERSION = "1.0.6" +WORKING_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "materialious") + +ROOT_PACKAGE = os.path.join(WORKING_DIR, "package.json") +ELECTRON_PACKAGE = os.path.join(WORKING_DIR, "electron", "package.json") +ANDROID_PACKAGE = os.path.join(WORKING_DIR, "android", "app", "build.gradle") + + +def package_json_update_ver(location: str) -> None: + with open(location, "r") as f_: + package = json.loads(f_.read()) + if package["version"] == LATEST_VERSION: + return + + package["version"] = LATEST_VERSION + + with open(location, "w") as f_: + f_.write(json.dumps(package, indent="\t")) + + +if __name__ == "__main__": + for location in (ROOT_PACKAGE, ELECTRON_PACKAGE): + package_json_update_ver(location) + + with open(ANDROID_PACKAGE, "r") as f_: + contents = f_.read() + + version_code_match = re.search(r"versionCode\s+(\d+)", contents) + version_name_match = re.search(r'versionName\s+"([^"]+)"', contents) + + if version_code_match and version_name_match: + version_code = version_code_match.group(1) + version_name = version_name_match.group(1) + + f_.close() + + with open(ANDROID_PACKAGE, "w") as f_: + new_version_code = int(version_code) + 1 + + f_.write( + contents.replace( + f"versionCode {version_code}", f"versionCode {new_version_code}" + ).replace( + f'versionName "{version_name}"', + f'versionName "{LATEST_VERSION}"', + ) + )