forked from ocaml-bench/ocaml_bench_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
validate_yaml.py
85 lines (69 loc) · 2.89 KB
/
validate_yaml.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
#!/usr/bin/env python3
"""
This script validates a given input YAML file for various checks
required to be performed prior to running the benchmarks in Sandmark.
Usage: $ python validate_yaml.py input.yml
"""
import argparse
import sys
import requests
import yaml
def check_branch_commit_exists(conf):
""" Check if both input branch and commit exist in GitHub """
for entry in conf['tracked_branches']:
# Check branch exists
branch = requests.get('https://github.com/%s/%s/tree/%s' %
(entry['github_user'], entry['github_repo'], entry['branch']))
if branch.status_code != 200:
print('Branch %s for %s/%s does not exist!' %
(entry['branch'], entry['github_user'], entry['github_repo']))
# Check commit exists
commit = requests.get('https://github.com/%s/%s/commit/%s' %
(entry['github_user'], entry['github_repo'], entry['first_commit']))
if commit.status_code != 200:
print('Commit %s for %s/%s does not exist!' %
(entry['first_commit'], entry['github_user'], entry['github_repo']))
def check_ocaml_version(conf):
""" Check if OCaml version is in x.y.z format """
for entry in conf['tracked_branches']:
i = entry['ocaml_version'].split('.')
if len(i) != 3:
print('OCaml version needs (major, minor, patch) and not %s' %
(entry['ocaml_version']))
def check_unique_keys(conf, key):
""" To identify if duplicate entries exist """
keys = []
for entry in conf['tracked_branches']:
keys.append(entry[key])
data = [i for i, x in enumerate(keys) if keys.count(x) > 1]
if len(data) != 0:
print('Duplicate %s entries exist in %s' % (key, data))
def check_run_path_tag_length(conf):
""" Check run_path_tag is at most five characters """
for entry in conf['tracked_branches']:
if len(entry['run_path_tag']) > 5:
print('run_path_tag %s is greater than five characters!' %
(entry['run_path_tag']))
def validate(conf):
""" The list of validation checks to be performed """
check_branch_commit_exists(conf)
check_ocaml_version(conf)
check_unique_keys(conf, 'run_path_tag')
check_unique_keys(conf, 'codespeed_name')
check_run_path_tag_length(conf)
def main():
""" The main function """
parser = argparse.ArgumentParser(description=
'Validate input YAML file before running bench scripts')
parser.add_argument('config', type=str, help='config file')
args = parser.parse_args()
# read in yaml config
with open(args.config, 'r') as stream:
try:
config = yaml.safe_load(stream)
validate(config)
except yaml.YAMLError as exc:
print('YAMLError: %s'%exc)
sys.exit(1)
if __name__ == "__main__":
main()