Skip to content

Commit 9ddc8d6

Browse files
committed
Adding release script.
1 parent 3d48628 commit 9ddc8d6

1 file changed

Lines changed: 115 additions & 0 deletions

File tree

tools/release.py

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
#!/usr/bin/env python3
2+
########################################################################
3+
# Generates a new release.
4+
########################################################################
5+
import sys
6+
import re
7+
import subprocess
8+
import io
9+
import os
10+
11+
12+
def extractnumbers(s):
13+
return tuple(map(int,re.findall("(\d+)\.(\d+)\.(\d+)",str(s))[0]))
14+
15+
def toversionstring(major, minor, rev):
16+
return str(major)+"."+str(minor)+"."+str(rev)
17+
18+
def topaddedversionstring(major, minor, rev):
19+
return str(major)+str(minor).zfill(3)+str(rev).zfill(3)
20+
21+
pipe = subprocess.Popen(["git", "rev-parse", "--abbrev-ref", "HEAD"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
22+
branchresult = pipe.communicate()[0].decode().strip()
23+
24+
if(branchresult != "master"):
25+
print("release on master, you are on '"+branchresult+"'")
26+
sys.exit(-1)
27+
28+
29+
ret = subprocess.call(["git", "remote", "update"])
30+
31+
if(ret != 0):
32+
sys.exit(ret)
33+
34+
35+
36+
pipe = subprocess.Popen(["git", "log", "HEAD..", "--oneline"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
37+
uptodateresult = pipe.communicate()[0].decode().strip()
38+
39+
if(len(uptodateresult) != 0):
40+
print(uptodateresult)
41+
sys.exit(-1)
42+
43+
pipe = subprocess.Popen(["git", "rev-parse", "--show-toplevel"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
44+
maindir = pipe.communicate()[0].decode().strip()
45+
46+
47+
print("repository: "+maindir)
48+
49+
pipe = subprocess.Popen(["git", "describe", "--abbrev=0", "--tags"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
50+
versionresult = pipe.communicate()[0].decode().strip()
51+
52+
print("last version: "+versionresult )
53+
try:
54+
currentv = extractnumbers(versionresult)
55+
except:
56+
currentv = [0,0,0]
57+
if(len(sys.argv) != 2):
58+
nextv = (currentv[0],currentv[1], currentv[2]+1)
59+
print ("please specify version number, e.g. "+toversionstring(*nextv))
60+
sys.exit(-1)
61+
try:
62+
newversion = extractnumbers(sys.argv[1])
63+
except:
64+
print("can't parse version number "+sys.argv[1])
65+
sys.exit(-1)
66+
67+
print("checking that new version is valid")
68+
69+
if(newversion[0] != currentv[0]):
70+
assert newversion[0] == currentv[0] + 1
71+
assert newversion[1] == 0
72+
assert newversion[2] == 0
73+
elif (newversion[1] != currentv[1]):
74+
assert newversion[1] == currentv[1] + 1
75+
assert newversion[2] == 0
76+
else :
77+
assert newversion[2] == currentv[2] + 1
78+
79+
80+
81+
versionfilerel = os.sep + "include" + os.sep + "simdjson" + os.sep + "simdjson_version.h"
82+
versionfile = maindir + versionfilerel
83+
84+
with open(versionfile, 'w') as file:
85+
file.write("// "+versionfilerel+" automatically generated by release.py, do not change by hand \n")
86+
file.write("#ifndef SIMDJSON_INCLUDE_SIMDJSON_VERSION \n")
87+
file.write("#define SIMDJSON_INCLUDE_SIMDJSON_VERSION \n")
88+
file.write("#define SIMDJSON_VERSION = "+toversionstring(*newversion)+", \n")
89+
file.write("enum { \n")
90+
file.write(" SIMDJSON_VERSION_MAJOR = "+str(newversion[0])+", \n")
91+
file.write(" SIMDJSON_VERSION_MINOR = "+str(newversion[1])+", \n")
92+
file.write(" SIMDJSON_VERSION_REVISION = "+str(newversion[2])+" \n")
93+
file.write("}; \n")
94+
file.write("#endif // SIMDJSON_INCLUDE_SIMDJSON_VERSION \n")
95+
96+
97+
print(versionfile + " modified")
98+
99+
import fileinput
100+
import re
101+
102+
newversionstring = str(newversion[0]) + "." + str(newversion[1]) + "." + str(newversion[2])
103+
cmakefile = maindir + os.sep + "CMakeLists.txt"
104+
for line in fileinput.input(cmakefile, inplace=1, backup='.bak'):
105+
line = re.sub('SIMDJSON_LIB_VERSION "\d+\.\d+\.\d+','SIMDJSON_LIB_VERSION "'+newversionstring, line.rstrip())
106+
line = re.sub('SIMDJSON_LIB_SOVERSION "\d+\.\d+\.\d+','SIMDJSON_LIB_SOVERSION "'+newversionstring, line)
107+
print(line)
108+
109+
print("modified "+cmakefile+", a backup was made")
110+
111+
scriptlocation = os.path.dirname(os.path.abspath(__file__))
112+
113+
114+
print("Please run the tests before issuing a release, do make test && make amalgamate \n")
115+
print("to issue release, enter \n git commit -a && git push && git tag -a v"+toversionstring(*newversion)+" -m \"version "+toversionstring(*newversion)+"\" && git push --tags \n")

0 commit comments

Comments
 (0)