-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathrelease.py
58 lines (45 loc) · 1.44 KB
/
release.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
#! python
from subprocess import call
import subprocess
import fileinput
import re
import os
import sys
import getopt
def safeProcess( cmd ):
"Run command, return boolean for success"
print(cmd);
try:
out = subprocess.check_output(cmd, shell=True)
print(out.decode("utf-8").replace("\\\n", "\n"))
return True;
except subprocess.CalledProcessError as e:
print("Status : FAIL", e.returncode, e.output)
return False;
def safeExit():
print ("Exiting...")
sys.exit(1)
# safeProcess("git reset --hard head")
def get_version(filename):
pattern = re.compile("\s*modversion\s*=\s*(\d*.\d*.\d*)");
for line in fileinput.input(filename):
if re.search(pattern, line):
print(pattern.search(line).groups())
version = pattern.search(line).groups()[0]
return version
return None;
# Don't continue if working copy is dirty
if not safeProcess('git diff-index --quiet HEAD --'):
print( "Cannot build, git working copy dirty")
safeExit()
# Build
if not safeProcess("bash gradlew clean"):
print("Building mod failed, won't continue")
safeExit();
if not safeProcess("bash gradlew build"):
print("Building mod failed, won't continue")
safeExit();
# Tag code by version
gradle_file = 'gradle.properties'
version = get_version(gradle_file)
safeProcess("git tag release/{}".format(version))