-
-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathupdate_version.py
More file actions
32 lines (28 loc) · 879 Bytes
/
update_version.py
File metadata and controls
32 lines (28 loc) · 879 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import os
import xml.etree.ElementTree as ET
path = 'listenarr.api/Listenarr.Api.csproj'
new = os.environ['NEW_VERSION']
tree = ET.parse(path)
root = tree.getroot()
found_version = False
for elem in root.findall('.//Version'):
elem.text = new
found_version = True
break
if not found_version:
pg = root.find('PropertyGroup')
if pg is None:
pg = ET.SubElement(root, 'PropertyGroup')
ET.SubElement(pg, 'Version').text = new
found_assembly = False
for elem in root.findall('.//AssemblyVersion'):
elem.text = new
found_assembly = True
break
if not found_assembly:
pg = root.find('PropertyGroup')
if pg is None:
pg = ET.SubElement(root, 'PropertyGroup')
ET.SubElement(pg, 'AssemblyVersion').text = new
tree.write(path, encoding='utf-8', xml_declaration=True)
print('Wrote new version and assembly version to csproj')