Skip to content

Commit 9befad4

Browse files
committed
adding release script
1 parent 2f3ed44 commit 9befad4

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed

script/release.py

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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+
import fileinput
11+
if sys.version_info < (3, 0):
12+
sys.stdout.write("Sorry, requires Python 3.x or better\n")
13+
sys.exit(1)
14+
15+
def colored(r, g, b, text):
16+
return "\033[38;2;{};{};{}m{} \033[38;2;255;255;255m".format(r, g, b, text)
17+
18+
def extractnumbers(s):
19+
return tuple(map(int,re.findall("(\d+)\.(\d+)\.(\d+)",str(s))[0]))
20+
21+
def toversionstring(major, minor, rev):
22+
return str(major)+"."+str(minor)+"."+str(rev)
23+
24+
def topaddedversionstring(major, minor, rev):
25+
return str(major)+str(minor).zfill(3)+str(rev).zfill(3)
26+
print("Calling git rev-parse --abbrev-ref HEAD")
27+
pipe = subprocess.Popen(["git", "rev-parse", "--abbrev-ref", "HEAD"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
28+
branchresult = pipe.communicate()[0].decode().strip()
29+
30+
if(branchresult != "main"):
31+
print(colored(255, 0, 0, "We recommend that you release on main, you are on '"+branchresult+"'"))
32+
33+
ret = subprocess.call(["git", "remote", "update"])
34+
35+
if(ret != 0):
36+
sys.exit(ret)
37+
print("Calling git log HEAD.. --oneline")
38+
pipe = subprocess.Popen(["git", "log", "HEAD..", "--oneline"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
39+
uptodateresult = pipe.communicate()[0].decode().strip()
40+
41+
if(len(uptodateresult) != 0):
42+
print(uptodateresult)
43+
sys.exit(-1)
44+
45+
pipe = subprocess.Popen(["git", "rev-parse", "--show-toplevel"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
46+
maindir = pipe.communicate()[0].decode().strip()
47+
scriptlocation = os.path.dirname(os.path.abspath(__file__))
48+
49+
print("repository: "+maindir)
50+
51+
pipe = subprocess.Popen(["git", "describe", "--abbrev=0", "--tags"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
52+
versionresult = pipe.communicate()[0].decode().strip()
53+
54+
print("last version: "+versionresult )
55+
try:
56+
currentv = extractnumbers(versionresult)
57+
except:
58+
currentv = [0,0,0]
59+
if(len(sys.argv) != 2):
60+
nextv = (currentv[0],currentv[1], currentv[2]+1)
61+
print ("please specify version number, e.g. "+toversionstring(*nextv))
62+
sys.exit(-1)
63+
try:
64+
newversion = extractnumbers(sys.argv[1])
65+
print(newversion)
66+
except:
67+
print("can't parse version number "+sys.argv[1])
68+
sys.exit(-1)
69+
70+
print("checking that new version is valid")
71+
if(newversion[0] != currentv[0]):
72+
assert newversion[0] == currentv[0] + 1
73+
assert newversion[1] == 0
74+
assert newversion[2] == 0
75+
elif (newversion[1] != currentv[1]):
76+
assert newversion[1] == currentv[1] + 1
77+
assert newversion[2] == 0
78+
else :
79+
assert newversion[2] == currentv[2] + 1
80+
81+
atleastminor= (currentv[0] != newversion[0]) or (currentv[1] != newversion[1])
82+
83+
84+
85+
newmajorversionstring = str(newversion[0])
86+
mewminorversionstring = str(newversion[1])
87+
newrevversionstring = str(newversion[2])
88+
newversionstring = str(newversion[0]) + "." + str(newversion[1]) + "." + str(newversion[2])
89+
cmakefile = maindir + os.sep + "CMakeLists.txt"
90+
91+
92+
for line in fileinput.input(cmakefile, inplace=1, backup='.bak'):
93+
line = re.sub('project\(fast_float VERSION \d+\.\d+\.\d+ LANGUAGES CXX\)','project(fast_float VERSION '+newmajorversionstring+'.'+mewminorversionstring+'.'+newrevversionstring+" LANGUAGES CXX)", line.rstrip())
94+
print(line)
95+
96+
print("modified "+cmakefile+", a backup was made")
97+
98+
99+
readmefile = maindir + os.sep + "README.md"
100+
101+
102+
for line in fileinput.input(readmefile, inplace=1, backup='.bak'):
103+
line = re.sub('https://github.com/fastfloat/fast_float/releases/download/v(\d+\.\d+\.\d+)/fast_float.h','https://github.com/fastfloat/fast_float/releases/download/v'+newmajorversionstring+'.'+mewminorversionstring+'.'+newrevversionstring+'/fast_float.h', line.rstrip())
104+
print(line)
105+
106+
print("modified "+readmefile+", a backup was made")
107+
print("Please run the tests before issuing a release. \n")
108+
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")
109+
110+
111+

0 commit comments

Comments
 (0)