aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChase Qi <chase.qi@linaro.org>2019-03-07 16:19:15 +0800
committerChase Qi <chase.qi@linaro.org>2019-03-07 17:00:02 +0800
commit827203c89744456827edf37558e5a4212a25e145 (patch)
treebe4fd62150e6130e7d6e7cbd9215f38b3dc8afe7
parentcd024183af008eaa8b868a375c6dcccf0d13a3f3 (diff)
sanity-check: improve file type determination
* Use libmagic to detect file type so that we don't have to update the file for new files without extension. * Because test plan and lava test job definition yaml file also contain 'metadata' key, use 'run' key to determine test definition yaml file. * Skip sanity check on unknown file types. Signed-off-by: Chase Qi <chase.qi@linaro.org>
-rw-r--r--.travis.yml2
-rwxr-xr-xvalidate.py28
2 files changed, 17 insertions, 13 deletions
diff --git a/.travis.yml b/.travis.yml
index 4801764..7c979ca 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -9,7 +9,7 @@ python:
# https://github.com/koalaman/shellcheck#installing-the-shellcheck-binary
# php 7.2
install:
- - pip install pyyaml pycodestyle
+ - pip install pyyaml pycodestyle python-magic
script:
- ./sanity-check.sh
diff --git a/validate.py b/validate.py
index 236516f..98c5578 100755
--- a/validate.py
+++ b/validate.py
@@ -5,6 +5,7 @@ import sys
import subprocess
import traceback
import yaml
+import magic
run_pycodestyle = False
try:
@@ -71,7 +72,7 @@ def pycodestyle_check(filepath, args):
def validate_yaml_contents(filepath, args):
- def validate_lava_yaml(y, args):
+ def validate_testdef_yaml(y, args):
result_message_list = []
if 'metadata' not in y.keys():
result_message_list.append("* METADATA [FAILED]: " + filepath)
@@ -124,15 +125,15 @@ def validate_yaml_contents(filepath, args):
publish_result(["* YAMLVALIDCONTENTS [PASSED]: " + filepath + " - deleted"], args)
return 0
y = yaml.load(filecontent)
- if 'metadata' in y.keys():
- # lava yaml file
- return validate_lava_yaml(y, args)
+ if 'run' in y.keys():
+ # test definition yaml file
+ return validate_testdef_yaml(y, args)
elif 'skiplist' in y.keys():
# skipgen yaml file
return validate_skipgen_yaml(filepath, args)
else:
- publish_result(["* YAMLVALIDCONTENTS [FAILED]: " + filepath + " - Unknown yaml type detected"], args)
- return 1
+ publish_result(["* YAMLVALIDCONTENTS [SKIPPED]: " + filepath + " - Unknown yaml type detected"], args)
+ return 0
def validate_yaml(filename, args):
@@ -195,20 +196,23 @@ def validate_external(cmd, filename, prefix, args):
def validate_file(args, path):
+ filetype = magic.from_file(path, mime=True)
exitcode = 0
- if path.endswith(".yaml"):
+ # libmagic takes yaml as 'text/plain', so use file extension here.
+ if path.endswith((".yaml", "yml")):
exitcode = validate_yaml(path, args)
if exitcode == 0:
# if yaml isn't valid there is no point in checking metadata
exitcode = validate_yaml_contents(path, args)
- elif run_pycodestyle and path.endswith(".py"):
+ elif run_pycodestyle and filetype == "text/x-python":
exitcode = pycodestyle_check(path, args)
- elif path.endswith(".php"):
+ elif filetype == "text/x-php":
exitcode = validate_php(path, args)
- elif path.endswith(".sh") or \
- path.endswith("sh-test-lib") or \
- path.endswith("android-test-lib"):
+ elif filetype == "text/x-shellscript":
exitcode = validate_shell(path, args)
+ else:
+ publish_result(["* UNKNOWN [SKIPPED]: " + path + " - Unknown file type detected: " + filetype], args)
+ return 0
return exitcode