forked from ubccr/xdmod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.travis.build.sh
executable file
·105 lines (94 loc) · 3.26 KB
/
.travis.build.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
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
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env bash
export PATH
PATH="$(pwd)/vendor/bin:$(pwd)/node_modules/.bin:$PATH"
source ~/.nvm/nvm.sh
nvm use "$NODE_VERSION"
# Fix for Travis not specifying a range if testing the first commit of
# a new branch on push
if [ -z "$TRAVIS_COMMIT_RANGE" ]; then
TRAVIS_COMMIT_RANGE="$(git rev-parse --verify --quiet "${TRAVIS_COMMIT}^1")...${TRAVIS_COMMIT}"
fi
if [ "$TEST_SUITE" = "syntax" ] || [ "$TEST_SUITE" = "style" ]; then
# Check whether the start of the commit range is available.
# If it is not available, try fetching the complete history.
commit_range_start="$(echo "$TRAVIS_COMMIT_RANGE" | sed -E 's/^([a-fA-F0-9]+).*/\1/')"
if ! git show --format='' --no-patch "$commit_range_start" &>/dev/null; then
git fetch --unshallow
# If it's still unavailable (likely due a push build caused by a force push),
# tests based on what has changed cannot be run.
if ! git show --format='' --no-patch "$commit_range_start" &>/dev/null; then
echo "Could not find commit range start ($commit_range_start)." >&2
echo "Tests based on changed files cannot run." >&2
exit 1
fi
fi
# Get the files changed by this commit (excluding deleted files).
files_changed=()
while IFS= read -r -d $'\0' file; do
files_changed+=("$file")
done < <(git diff --name-only --diff-filter=d -z "$TRAVIS_COMMIT_RANGE")
# Separate the changed files by language.
php_files_changed=()
js_files_changed=()
for file in "${files_changed[@]}"; do
if [[ "$file" == *.php ]]; then
php_files_changed+=("$file")
elif [[ "$file" == *.js ]]; then
js_files_changed+=("$file")
fi
done
fi
# Perform a test set based on the value of $TEST_SUITE.
build_exit_value=0
if [ "$TEST_SUITE" = "syntax" ]; then
for file in "${php_files_changed[@]}"; do
php -l "$file" >/dev/null
if [ $? != 0 ]; then
build_exit_value=2
fi
done
for file in "${js_files_changed[@]}"; do
eslint --no-eslintrc "$file"
if [ $? != 0 ]; then
build_exit_value=2
fi
done
elif [ "$TEST_SUITE" = "style" ]; then
for file in "${php_files_changed[@]}"; do
phpcs "$file"
if [ $? != 0 ]; then
build_exit_value=2
fi
done
for file in "${js_files_changed[@]}"; do
eslint "$file"
if [ $? != 0 ]; then
build_exit_value=2
fi
done
elif [ "$TEST_SUITE" = "unit" ]; then
open_xdmod/modules/xdmod/tests/runtests.sh
if [ $? != 0 ]; then
build_exit_value=2
fi
elif [ "$TEST_SUITE" = "build" ]; then
echo "Building Open XDMoD..."
open_xdmod/build_scripts/build_package.php --module xdmod
if [ $? != 0 ]; then
build_exit_value=2
fi
xdmod_install_dir="$HOME/xdmod-install"
echo "Installing Open XDMoD..."
cd open_xdmod/build || exit 2
xdmod_tar="$(find . -regex '^\./xdmod-[0-9]+[^/]*\.tar\.gz$')"
tar -xf "$xdmod_tar"
cd "$(basename "$xdmod_tar" .tar.gz)" || exit 2
./install --prefix="$xdmod_install_dir"
if [ $? != 0 ]; then
build_exit_value=2
fi
else
echo "Invalid value for \$TEST_SUITE: $TEST_SUITE" >&2
build_exit_value=1
fi
exit $build_exit_value