-
Notifications
You must be signed in to change notification settings - Fork 8k
/
ftr_configs.sh
executable file
·133 lines (107 loc) · 3.59 KB
/
ftr_configs.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
#!/usr/bin/env bash
set -euo pipefail
source .buildkite/scripts/common/util.sh
.buildkite/scripts/bootstrap.sh
.buildkite/scripts/build_kibana_plugins.sh
is_test_execution_step
export JOB_NUM=$BUILDKITE_PARALLEL_JOB
export JOB=ftr-configs-${JOB_NUM}
export CODE_COVERAGE=1
FAILED_CONFIGS_KEY="${BUILDKITE_STEP_ID}${BUILDKITE_PARALLEL_JOB:-0}"
# a FTR failure will result in the script returning an exit code of 10
exitCode=0
configs="${FTR_CONFIG:-}"
if [[ "$configs" == "" ]]; then
echo "--- downloading ftr test run order"
buildkite-agent artifact download ftr_run_order.json .
configs=$(jq -r '.groups[env.JOB_NUM | tonumber].names | .[]' ftr_run_order.json)
fi
failedConfigs=""
results=()
while read -r config; do
if [[ ! "$config" ]]; then
continue
fi
echo "--- $ node scripts/functional_tests --config $config --exclude-tag ''skipCoverage''"
start=$(date +%s)
# prevent non-zero exit code from breaking the loop
set +e
NODE_OPTIONS=--max_old_space_size=14336 \
./node_modules/.bin/nyc \
--nycrc-path ./src/dev/code_coverage/nyc_config/nyc.server.config.js \
node scripts/functional_tests \
--config="$config" \
--exclude-tag "skipCoverage"
lastCode=$?
set -e
dasherize() {
withoutExtension=${1%.*}
dasherized=$(echo "$withoutExtension" | tr '\/' '\-')
}
dasherize $config
serverAndClientSummary="target/kibana-coverage/functional/xpack-${dasherized}-server-coverage.json"
functionalSummary="target/kibana-coverage/functional/xpack-${dasherized}-coverage.json"
# Server side and client side (server and public dirs)
if [[ -d "$KIBANA_DIR/target/kibana-coverage/server" ]]; then
echo "--- Server and Client side code coverage collected"
mkdir -p target/kibana-coverage/functional
mv target/kibana-coverage/server/coverage-final.json "$serverAndClientSummary"
fi
# Each browser unload event, creates a new coverage file.
# So, we merge them here.
if [[ -d "$KIBANA_DIR/target/kibana-coverage/functional" ]]; then
echo "--- Merging code coverage for FTR Config: $config"
yarn nyc report --nycrc-path src/dev/code_coverage/nyc_config/nyc.functional.config.js --reporter json
rm -rf target/kibana-coverage/functional/*
mv target/kibana-coverage/functional-combined/coverage-final.json "$functionalSummary"
else
echo "--- Code coverage not found"
fi
# Check for empty summary files.
empties=()
emptyCheck() {
echo "### Checking $1"
echo $(head -5 $1) | grep -E -i "pct.+Unknown" >/dev/null
lastCode=$?
if [ $lastCode -eq 0 ]; then
echo " --- Empty Summary File: $1"
empties+=($1)
fi
}
emptyCheck $serverAndClientSummary
emptyCheck $functionalSummary
if [[ ${#empties[@]} -ge 2 ]]; then
echo "### Empty count = ${#empties[@]}, fail the build"
else
echo "### Empty count < 2, dont fail the build"
fi
timeSec=$(($(date +%s) - start))
if [[ $timeSec -gt 60 ]]; then
min=$((timeSec / 60))
sec=$((timeSec - (min * 60)))
duration="${min}m ${sec}s"
else
duration="${timeSec}s"
fi
results+=("- $config
duration: ${duration}
result: ${lastCode}")
if [ $lastCode -ne 0 ]; then
exitCode=10
echo "FTR exited with code $lastCode"
echo "^^^ +++"
if [[ "$failedConfigs" ]]; then
failedConfigs="${failedConfigs}"$'\n'"$config"
else
failedConfigs="$config"
fi
fi
done <<<"$configs"
if [[ "$failedConfigs" ]]; then
buildkite-agent meta-data set "$FAILED_CONFIGS_KEY" "$failedConfigs"
fi
echo "--- FTR configs complete"
printf "%s\n" "${results[@]}"
echo ""
# Force exit 0 to ensure the next build step starts.
exit 0