From 03ad9a873c39cdc95dd8d77dbbda67f84db43945 Mon Sep 17 00:00:00 2001 From: Vince Grassia <593223+vgrassia@users.noreply.github.com> Date: Wed, 12 Jan 2022 13:44:30 -0500 Subject: [PATCH] Update Version Bump action to address formatting issues (#23) --- version-bump/main.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/version-bump/main.py b/version-bump/main.py index 2d477b84..5adda357 100644 --- a/version-bump/main.py +++ b/version-bump/main.py @@ -1,6 +1,7 @@ import os import json import plistlib +import re import lxml.etree as ET @@ -18,6 +19,8 @@ def update_json(version, file): except KeyError: pass json.dump(data, open(file, "w"), indent=2) + with open(file, "a") as f: + f.write("\n") # Make sure we add the new line back in at EOF. def update_plist(version, file): @@ -37,14 +40,19 @@ def update_xml(version, file): # Android Manifests if myroot.tag == "manifest": - myroot.attrib[ - "{http://schemas.android.com/apk/res/android}versionName" - ] = version - ET.register_namespace("android", "http://schemas.android.com/apk/res/android") - ET.register_namespace("tools", "http://schemas.android.com/tools") - mytree.write(file, encoding="utf-8", xml_declaration=True, pretty_print=True) + with open(file, "r") as f: + data = f.read() + data_new = re.sub( + 'android:versionName="[0-9]+\.[0-9]+\.[0-9]+"', + f'android:versionName="{version}"', + data, + flags=re.M, + ) + with open(file, "w") as f: + f.write(data_new) + # Microsoft .NET project files - elif "Microsoft.NET.Sdk" in myroot.attrib["Sdk"]: + elif myroot.attrib.has_key("Sdk") and "Microsoft.NET.Sdk" in myroot.attrib["Sdk"]: version_property = [x for x in myroot[0] if x.tag == "Version"][-1] version_property.text = version mytree.write(file)