Merge pull request #279 from Materialious/update/android-versioning

Fixed android versioning & added a script to keep it updated
This commit is contained in:
Ward
2024-05-11 14:30:50 +12:00
committed by GitHub
2 changed files with 56 additions and 2 deletions
+2 -2
View File
@@ -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.
+54
View File
@@ -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}"',
)
)