added overcomplicated script that increments version code in android/build.gradle automaticaly

This commit is contained in:
Looki2000 2023-03-02 16:56:42 +01:00
parent 2b72ec963d
commit 4eba8a044a
2 changed files with 65 additions and 1 deletions

View File

@ -4,7 +4,7 @@ project.ext.set("versionMajor", 1) // Version Major
project.ext.set("versionMinor", 1) // Version Minor
project.ext.set("versionPatch", 0) // Version Patch
project.ext.set("versionExtra", "") // Version Extra
project.ext.set("versionCode", 44) // Android Version Code
project.ext.set("versionCode", 45) // Android Version Code
project.ext.set("developmentBuild", 0) // Whether it is a development build, or a release
// NOTE: +2 after each release!
// +1 for ARM and +1 for ARM64 APK's, because

64
android/versionCode+1.py Normal file
View File

@ -0,0 +1,64 @@
import os
###############################################################################
# Overcomplicated script that increments the versionCode in build.gradle by 1 #
###############################################################################
script_path = os.path.dirname(os.path.realpath(__file__))
# open build.gradle as read
with open(script_path + "\\build.gradle", "r") as f:
# read lines
lines = f.readlines()
# find versionCode
for line_i in range(len(lines)):
# find char_i of "project.ext.set("versionCode", "
char_i = lines[line_i].find("project.ext.set(\"versionCode\",")
if char_i != -1:
char_i += 30
line_max_i = len(lines[line_i]) - 1
# find start of number
while True:
if char_i > line_max_i:
print("Error: number in versionCode not found")
input("Press Enter to exit...")
exit()
char_unicode = ord(lines[line_i][char_i])
if 48 <= char_unicode <= 57:
break
char_i += 1
# find end of number
num_end_i = char_i + 1
while True:
char_unicode = ord(lines[line_i][num_end_i])
if 48 > char_unicode or char_unicode > 57:
break
num_end_i += 1
# get number
num = int(lines[line_i][char_i:num_end_i])
print(f"OLD versionCode: {num}")
num += 1
print(f"NEW versionCode: {num}")
# replace number
lines[line_i] = lines[line_i][:char_i] + str(num) + lines[line_i][num_end_i:]
# write lines
with open(script_path + "\\build.gradle", "w") as f:
f.writelines(lines)
break
if char_i == -1:
print("Error: versionCode not found")
input("Press Enter to exit...")