forked from common-workflow-library/bio-cwl-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ci.py
93 lines (84 loc) · 3.06 KB
/
ci.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
82
83
84
85
86
87
88
89
90
91
92
93
import crayons
import os
from subprocess import check_output, check_call, CalledProcessError
import sys
has_failed = False
tool_failed = False
# changed_files = check_output("git --no-pager diff --name-status release..$(git branch | grep \* | cut -d ' ' -f2)", shell=True)
if "GITHUB_REF" in os.environ:
changed_files = check_output(
"git --no-pager diff --name-status --diff-filter d HEAD^1 HEAD",
shell=True,
)
print("Using GITHUB_REF")
else:
try:
changed_files = check_output(
"git --no-pager diff --name-status --diff-filter d release..FETCH_HEAD",
shell=True,
)
print("Using Head")
except:
print("Using default branch")
changed_files = check_output("git --no-pager diff --name-status", shell=True)
for line in changed_files.decode("utf-8").rstrip().split("\n"):
tool_failed = False
change = line.split("\t")[0]
if change not in ["M", "A", "C", "R", "X"]:
continue
fs = line.split("\t")[1]
if not fs.lower().endswith(".cwl"):
continue
print(crayons.blue(f"Testing CWL Validation: {fs} \n"))
try:
file_validation_status = check_call(f"cwltool --validate {fs}", shell=True)
except CalledProcessError:
file_validation_status = -1
if file_validation_status != 0:
print(f"Tool Failed Validation: {fs}")
tool_failed = True
continue
if file_validation_status == 0:
print(crayons.green(f"Tool Passed Validation: {fs}\n"))
print(crayons.blue(f"Testing Repo Requirements\n"))
with open(fs) as f:
lines_expected = [
["#!/usr/bin/env cwl-runner"],
[
"cwlVersion:v1.0",
"cwlVersion: v1.0",
"cwlVersion:v1.1",
"cwlVersion: v1.1",
"cwlVersion: v1.2",
],
["class: CommandLineTool", "class: Workflow", "class: ExpressionTool"],
]
for index, line in enumerate(f.readlines()):
line = line.rstrip()
if index == 3:
break
patterns = lines_expected[index]
for line_expected in patterns:
if line == line_expected:
break
else:
# if we get to the end of the loop without breaking, it means the line has not been matched
print(
crayons.red(
f"Tool Failed Requirements: Line {index + 1} : {fs} : got: '{line}', expected one of {patterns}\n"
)
)
tool_failed = True
if tool_failed == False:
print(crayons.green(f"Tool Passed Repo Requirements: {fs}\n"))
else:
print(crayons.red(f"Tool Failed Repo Requirements: {fs}\n"))
has_failed = True
if os.access(fs, os.X_OK):
print(crayons.green(f"Tool Passed Executable Test: {fs}"))
else:
print(crayons.red(f"File Failed Executable Requirement: {fs}"))
has_failed = True
print("=====================")
if has_failed == True:
sys.exit(1)