-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest_all_commits.py
executable file
·50 lines (34 loc) · 1.49 KB
/
test_all_commits.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
#!/usr/bin/python3.5
import subprocess
import sys
TEST_BRANCH_NAME = 'test-branch'
def run():
completed_process = run_process(['git', 'checkout', 'master'])
if 0 != completed_process.returncode:
raise Exception('Can not checkout branch master')
checkout_test_branch()
while True:
completed_process = run_process(['git', 'log', '-1', '--pretty=%B'])
run_maven(completed_process.stdout.decode().strip())
completed_process = run_process(['git', 'reset', '--hard', 'HEAD^'])
if 0 != completed_process.returncode:
print('Reached first commit. All tests passed successfully!')
break
run_process(['git', 'checkout', 'master'])
run_process(['git', 'branch', '-d', TEST_BRANCH_NAME])
def run_process(arguments):
return subprocess.run(arguments, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
def checkout_test_branch():
# Ignore failure to delete the test branch
run_process(['git', 'branch', '-d', TEST_BRANCH_NAME])
completed_process = run_process(['git', 'checkout', '-b', TEST_BRANCH_NAME])
if 0 != completed_process.returncode:
raise Exception('Can not checkout test branch')
def run_maven(message):
print('Testing commit: %s' % message)
completed_process = run_process(['mvn', 'clean', 'verify'])
if 0 != completed_process.returncode:
print(completed_process.stdout.decode(), file=sys.stderr)
raise Exception("Maven failed! :'(")
if __name__ == '__main__':
run()