-
Notifications
You must be signed in to change notification settings - Fork 4
/
travis_gradle_build.sh
executable file
·99 lines (82 loc) · 2.66 KB
/
travis_gradle_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
#!/usr/bin/env bash
# Abort on error, uninitialized variables and pipe errors
set -eEu
set -o pipefail
set -v
WORKDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
export WORKDIR
export PING_SLEEP=30s
export BUILD_OUTPUT=$WORKDIR/build.out
export TEST_PROC_LOG_OUTPUT=$WORKDIR/test-proc.out
export TEST_API_LOG_OUTPUT=$WORKDIR/test-api.out
# dump the last N lines of the output files
DUMP_LINES_BUILD=2000
DUMP_LINES_TEST_PROC=5000
DUMP_LINES_TEST_API=2000
touch "$BUILD_OUTPUT"
touch "$TEST_PROC_LOG_OUTPUT"
touch "$TEST_API_LOG_OUTPUT"
# Helper functions
print_log_separator() {
echo "----------------------------------------------------------------"
echo "-"
echo "-"
echo "-"
echo "-"
echo "----------------------------------------------------------------"
}
dump_output() {
if [ "$2" -eq "-1" ]; then
echo "Printing all the output: $1"
cat "$1"
else
echo "Tailing the last $2 lines of build output: $1"
tail -$2 "$1"
fi
}
print_logs() {
print_log_separator
dump_output "$BUILD_OUTPUT" $DUMP_LINES_BUILD
print_log_separator
dump_output "$TEST_PROC_LOG_OUTPUT" $DUMP_LINES_TEST_PROC
print_log_separator
dump_output "$TEST_API_LOG_OUTPUT" $DUMP_LINES_TEST_API
}
run_build() {
{
#./gradlew build --full-stacktrace --debug 2>&1 | tee >(grep TestEventLogger | grep -P -n "[[:ascii:]]" >> $TEST_LOG_OUTPUT) | grep -P -n "[[:ascii:]]" >> $BUILD_OUTPUT
./gradlew assemble --full-stacktrace 2>&1
} >> "$BUILD_OUTPUT"
}
run_tests() {
{
# enable debug output here to spot the errors
./gradlew test --full-stacktrace --debug --tests=tika.LegacyTikaProcessorTests 2>&1 | grep "TestEventLogger"
./gradlew test --full-stacktrace --debug --tests=tika.CompositeTikaProcessorTests 2>&1 | grep "TestEventLogger"
# disable debug output for service
./gradlew test --full-stacktrace --tests=ServiceControllerTests 2>&1
} >> "$TEST_PROC_LOG_OUTPUT"
{
# disable debug output for docs
./gradlew test --full-stacktrace --tests=ServiceControllerDocumentMultipartFileTests 2>&1
./gradlew test --full-stacktrace --tests=ServiceControllerDocumentStreamTests 2>&1
} >> "$TEST_API_LOG_OUTPUT"
}
error_handler() {
echo ERROR: An error was encountered with the build.
print_logs
exit 1
}
# If an error occurs, run our error handler to output a tail of the build
trap 'error_handler' ERR SIGPIPE
# Set up a repeating loop to send some output to Travis (to avoid killing inactive builds)
bash -c "while true; do echo \$(date) - building ...; sleep $PING_SLEEP; done" &
PING_LOOP_PID=$!
# Build Commands
run_build
run_tests
# 'nicely' terminate the ping output loop
kill $PING_LOOP_PID
# Print the logs
echo SUCCESS
print_logs