forked from cms-sw/cms-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ib-pr-workflow-changed.py
executable file
·56 lines (49 loc) · 1.44 KB
/
ib-pr-workflow-changed.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
#!/usr/bin/env python
import re
from sys import argv, exit
from commands import getstatusoutput as run_cmd
def parse_workflows(workflow_file):
err, out = run_cmd("cat %s" % workflow_file)
if err:
print out
exit(1)
wf = ""
wfs = {}
steps = 0
for line in out.split("\n"):
line =line.strip()
m = re.match("^.*\[(\d+)\] *: *(.+)$",line)
if not m: continue
step = m.group(1)
cmd = m.group(2).strip()
prefix, rest = line.split(":",1)
items = prefix.split(" ")
if re.match("^\d+(\.\d+|)$",items[0]): wf = items[0]
if not wf in wfs: wfs[wf]={}
wfs[wf][step]=re.sub(" +"," ",cmd)
steps += 1
print "%s: %s workflows, %s steps" % (workflow_file, len(wfs), steps)
return wfs
orig_workflows = argv[1]
new_workflows = argv[2]
wfs={}
wfs["old"]=parse_workflows(argv[1])
wfs["new"]=parse_workflows(argv[2])
new_wf = []
new_step = []
chg_step = []
for wf in wfs["new"]:
if not wf in wfs["old"]:
new_wf.append(wf)
else:
for step in wfs["new"][wf]:
if not step in wfs["old"][wf]:
new_step.append(wf)
break
elif not wfs["old"][wf]==wfs["new"][wf]:
chg_step.append(wf)
break
print "New workflows:%s: %s" % (len(new_wf), ",".join(new_wf))
print "Workflows with new steps:%s: %s" % (len(new_step), ",".join(new_step))
print "Wrokflows with changed steps:%s: %s" % (len(chg_step), ",".join(chg_step))
print "WORKFLOWS TO RUN:",",".join(new_wf+new_step+chg_step)