forked from explosion/projects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-tests.sh
32 lines (28 loc) · 1.2 KB
/
run-tests.sh
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
#!/bin/bash
# Only run tests in second-level directories that have been changed in the last commit.
# Fetch changed files.
mapfile -t dirs < <( git diff --dirstat=files,0 HEAD~1 | sed 's/^[ 0-9.]\+% //g')
declare -a tested_dirs=()
exit_code=0
for dir in "${dirs[@]}"
do
# Get path with second level only. This will be empty if the change happened at the first level.
second_level_dir=$(echo "$dir" | awk -F/ '{print FS $2}')
second_level_dir="${second_level_dir:1}"
# Get path with first level/second level.
full_second_level_dir=$(echo "$dir" | cut -d/ -f1-2)
# Only run if change happened at second level, since first level-changes don't require the tests to be re-run.
if [ ! -z "$second_level_dir" -a "$second_level_dir" != " " ]; then
if [[ ! " ${tested_dirs[*]} " =~ " ${full_second_level_dir} " ]]; then
tested_dirs+=($full_second_level_dir)
if [ -e $full_second_level_dir/requirements.txt ]; then
python -m pip install -q -r $full_second_level_dir/requirements.txt --extra-index-url https://download.pytorch.org/whl/cpu
fi
python -m pytest -s $full_second_level_dir
if [[ $? != @(0|5) ]]; then
exit_code=1
fi
fi
fi
done
exit $exit_code