forked from anonyreview/ICST2022-JS-Instrumentation-Test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathversion.py
executable file
·68 lines (47 loc) · 1.61 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
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)
replaceInMakeExecutable()
replaceInCI()
SHELL = platform.system() == 'Windows'
mvnres = run(["mvn", "versions:set", "-DnewVersion="+version], shell=SHELL)
mvnres = mvnres.returncode
if mvnres != 0:
print("\nERROR: Maven command failed")
exit(1)