unit-test: Run repo specific CI scripts
Allow repositories to have custom CI tests that aren't based on C++ unit
tests by finding and running any 'run-ci.sh' scripts found in the
repository. A nonzero exit status will fail the test.
The script will be run with the 'sh' command with the base directory of
the repository as the current working directory.
Change-Id: I87db4d34b6e1db9472c9b97241ce771eeab3fa7c
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
diff --git a/scripts/unit-test.py b/scripts/unit-test.py
index 85243e6..ab35c4e 100755
--- a/scripts/unit-test.py
+++ b/scripts/unit-test.py
@@ -685,6 +685,22 @@
except CalledProcessError:
raise Exception('Code coverage failed')
+def find_file(filename, basedir):
+ """
+ Finds all occurrences of a file in the base directory
+ and passes them back with their relative paths.
+
+ Parameter descriptions:
+ filename The name of the file to find
+ basedir The base directory search in
+ """
+
+ filepaths = []
+ for root, dirs, files in os.walk(basedir):
+ if filename in files:
+ filepaths.append(os.path.join(root, filename))
+ return filepaths
+
if __name__ == '__main__':
# CONFIGURE_FLAGS = [GIT REPO]:[CONFIGURE FLAGS]
CONFIGURE_FLAGS = {
@@ -879,3 +895,11 @@
else:
print "Not a supported repo for CI Tests, exit"
quit()
+
+ # Run any custom CI scripts the repo has, of which there can be
+ # multiple of and anywhere in the repository.
+ ci_scripts = find_file('run-ci.sh', os.path.join(WORKSPACE, UNIT_TEST_PKG))
+ if ci_scripts:
+ os.chdir(os.path.join(WORKSPACE, UNIT_TEST_PKG))
+ for ci_script in ci_scripts:
+ check_call_cmd('sh', ci_script)