-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.py
81 lines (66 loc) · 1.99 KB
/
build.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
import os
import platform
import subprocess
import argparse
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKCYAN = '\033[96m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
# Parse arguments
parser = argparse.ArgumentParser(
description='Builds the project and creates a docker image',
exit_on_error=True
)
parser.add_argument(
'-d',
'--docker',
action='store_true',
help='Builds the docker image'
)
args = parser.parse_args()
# Clean root jars
# Reason: `gradle clean` does not remove the jar files in the root directory
for file in os.listdir('.'):
if file.endswith('.jar'):
os.remove(file)
windows = platform.system() == 'Windows'
# Clean and build jar
if windows:
os.system('.\\gradlew clean')
os.system('.\\gradlew build')
else:
os.system('./gradlew clean')
os.system('./gradlew build')
version = None
# Select version number from build.gradle
with open('build.gradle', 'r') as f:
for line in f:
if 'version' in line:
version = line.split('\'')[1].strip()
# Check if Docker should be built
if args.docker:
if version is None or version == '':
version = 'latest'
print('\n' + bcolors.WARNING + '=' * 50)
print(bcolors.BOLD + '[WARNING]\n' + bcolors.ENDC + bcolors.WARNING)
print('Could not find version number in build.gradle')
print(f'Defaulting to `{version}`')
print('=' * 50 + bcolors.ENDC + '\n')
decision = input('Continue? [y/n]: ').strip().lower()
while decision != 'y' and decision != 'n':
if decision == 'n':
quit()
elif decision == 'y':
os.system(f'docker build -t triggers:{version} .')
break
else:
decision = input()
continue
else:
os.system(f'docker build -t triggers:{version} .')