-
Notifications
You must be signed in to change notification settings - Fork 16
/
version-bump.py
49 lines (37 loc) · 1.51 KB
/
version-bump.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import argparse
import xml.etree.ElementTree as ET
def __bump(filename, old, new, preserve=None):
lines = []
with open(filename, 'r') as f:
for line in f:
if preserve and not preserve(line.rstrip()):
line = line.replace(old, new)
lines.append(line)
with open(filename, 'w') as f:
for line in lines:
f.write(line)
def __bump_xhtml(filename, old, new):
__bump(filename, old, new, preserve=lambda s: s.endswith('<!-- hold-version -->'))
def __bump_yaml(filename, old, new):
__bump(filename, old, new, preserve=lambda s: s.endswith('# hold-version'))
def pom(old, new):
__bump_xhtml('pom.xml', old, new)
def readme(old, new):
__bump_xhtml('README.md', old, new)
def docker_compose(old, new):
__bump_yaml('docker-compose.yml', old, new)
__bump_yaml('docker-compose.cluster.yml', old, new)
def helm(old, new):
__bump_yaml('chart/Chart.yaml', old, new)
__bump_xhtml('chart/README.md', old, new)
parser = argparse.ArgumentParser(description='Version bumper')
pom_tree = ET.parse('pom.xml')
pom_version = pom_tree.find('{http://maven.apache.org/POM/4.0.0}version').text
parser.add_argument('--old', help='Old version. Defaults to parse from pom.xml version field', default=pom_version)
parser.add_argument('--new', help='New Version')
args = parser.parse_args()
if not args.new:
parser.print_help()
raise ValueError('missing new version argument')
for f in [pom, readme, docker_compose, helm]:
f(args.old, args.new)