forked from ubccr/xdmod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.travis.build.sh
executable file
·136 lines (123 loc) · 4.59 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/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=da -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
# Get any added files by language
php_files_added=()
js_files_added=()
while IFS= read -r -d $'\0' file; do
if [[ "$file" == *.php ]]; then
php_files_added+=("$file")
elif [[ "$file" == *.js ]]; then
js_files_added+=("$file")
fi
done < <(git diff --name-only --diff-filter=A -z "$TRAVIS_COMMIT_RANGE")
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[@]}" "${php_files_added[@]}"; do
php -l "$file" >/dev/null
if [ $? != 0 ]; then
build_exit_value=2
fi
done
elif [ "$TEST_SUITE" = "style" ]; then
npm install https://github.com/jpwhite4/lint-diff/tarball/master
for file in "${php_files_changed[@]}"; do
phpcs "$file" --report=json > "$file.lint.new.json"
if [ $? != 0 ]; then
git show "$commit_range_start:$file" | phpcs --stdin-path="$file" --report=json > "$file.lint.orig.json"
./node_modules/.bin/lint-diff "$file.lint.orig.json" "$file.lint.new.json"
if [ $? != 0 ]; then
build_exit_value=2
fi
rm "$file.lint.orig.json"
fi
rm "$file.lint.new.json"
done
for file in "${php_files_added[@]}"; do
phpcs "$file"
if [ $? != 0 ]; then
build_exit_value=2
fi
done
for file in "${js_files_changed[@]}"; do
eslint "$file" -f json > "$file.lint.new.json"
if [ $? != 0 ]; then
git show "$commit_range_start:$file" | eslint --stdin --stdin-filename "$file" -f json > "$file.lint.orig.json"
./node_modules/.bin/lint-diff "$file.lint.orig.json" "$file.lint.new.json"
if [ $? != 0 ]; then
build_exit_value=2
fi
rm "$file.lint.orig.json"
fi
rm "$file.lint.new.json"
done
for file in "${js_files_added[@]}"; do
eslint "$file"
if [ $? != 0 ]; then
build_exit_value=2
fi
done
elif [ "$TEST_SUITE" = "unit" ]; then
open_xdmod/modules/xdmod/tests/runtests.sh && phantomjs html/unit_tests/phantom.js
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