-
Notifications
You must be signed in to change notification settings - Fork 85
/
version.py
95 lines (73 loc) · 2.64 KB
/
version.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python
import sys
import re
import platform
import os
from subprocess import run
if len(sys.argv) != 2:
print("Usage:\n<nameOfScript>.py <version-number>")
exit(1)
version = sys.argv[1].strip()
versionRegex = re.compile(r"^(\d)+\.(\d)+\.(\d)+(-SNAPSHOT)?$")
if versionRegex.match(version) == None:
print("Invalid version format")
exit(1)
# release versions for msi/deb/dmg do not like SNAPSHOT
reducedVersion = version
if reducedVersion.endswith("-SNAPSHOT"):
reducedVersion = version[0:(len(version)-len("-SNAPSHOT"))]
def replace(file, regex, replacement):
found=0
with open(file, "r") as sources:
lines = sources.readlines()
with open(file, "w") as sources:
for line in lines:
if regex.match(line):
found = found + 1
sources.write(replacement)
else:
sources.write(line)
if found != 1:
print("Regex " + str(regex) + " has been matched " + str(found) + " times")
exit(1)
def replaceInMakeExecutable():
regex = re.compile(r'.*VERSION.*=.*')
replacement = 'VERSION='+reducedVersion+'\n'
replace("makeExecutable.sh", regex, replacement)
def replaceInCI():
regex = re.compile(r' evomaster-version:.*')
replacement = ' evomaster-version: '+reducedVersion+'\n'
replace(".github/workflows/ci.yml", regex, replacement)
replace(".github/workflows/release.yml", regex, replacement)
def replaceInBBE2E():
regex = re.compile(r'\s*<version>.*</version><!--MARKER-->\s*')
replacement = ' <version>'+version+'</version><!--MARKER-->\n'
replace("e2e-tests/spring-rest-bb/maven/pom.xml", regex, replacement)
### JS and C# no longer supported
# def replaceInJS():
# regex = re.compile(r'\s*"version"\s*:.*')
# replacement = ' "version": "'+version+'",\n'
# replace("client-js/evomaster-client-js/package.json", regex, replacement)
#
# def replaceInCS():
# regex = re.compile(r'\s*<Version>.*</Version>\s*')
# replacement = ' <Version>'+version+'</Version>\n'
# replace("client-dotnet/common.props", regex, replacement)
#
# regex = re.compile(r'.*VERSION.*=.*')
# replacement = 'VERSION='+reducedVersion+'\n'
# replace("client-dotnet/publish.sh", regex, replacement)
SHELL = platform.system() == 'Windows'
def replaceInMvn():
mvnres = run(["mvn", "versions:set", "-DnewVersion="+version], shell=SHELL)
mvnres = mvnres.returncode
if mvnres != 0:
print("\nERROR: Maven command failed")
exit(1)
replaceInMakeExecutable()
replaceInCI()
replaceInMvn()
replaceInBBE2E()
### No longer supported
# replaceInCS()
# replaceInJS()