-
Notifications
You must be signed in to change notification settings - Fork 8k
/
ftr_configs.sh
executable file
·122 lines (98 loc) · 3.33 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
#!/usr/bin/env bash
set -euo pipefail
source .buildkite/scripts/common/util.sh
source .buildkite/scripts/steps/code_coverage/merge.sh
source .buildkite/scripts/steps/code_coverage/util.sh
source .buildkite/scripts/steps/code_coverage/node_scripts.sh
export CODE_COVERAGE=1 # Kibana is bootstrapped differently for code coverage
echo "--- KIBANA_DIR: $KIBANA_DIR"
.buildkite/scripts/bootstrap.sh
buildPlatformPlugins
is_test_execution_step
export JOB_NUM=$BUILDKITE_PARALLEL_JOB
export JOB=ftr-configs-${JOB_NUM}
functionalTarget="$KIBANA_DIR/target/kibana-coverage/functional"
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
echo "--- Config(s) for this FTR Group:"
echo "${configs[@]}"
failedConfigs=""
results=()
while read -r config; do
if [[ ! "$config" ]]; then
continue
fi
echo "--- Begin config $config"
start=$(date +%s)
# prevent non-zero exit code from breaking the loop
set +e
runFTRInstrumented "$config"
lastCode=$?
set -e
dasherize() {
local withoutExtension=${1%.*}
dasherized=$(echo "$withoutExtension" | tr '\/' '\-')
}
dasherize "$config"
if [[ -d "$functionalTarget" ]]; then
echo "--- Server and / or Client side code coverage collected"
if [[ -f "target/kibana-coverage/functional/coverage-final.json" ]]; then
# We potentially have more than one file with the same name being created,
# so we make them unique here.
mv target/kibana-coverage/functional/coverage-final.json "target/kibana-coverage/functional/${dasherized}-server-coverage.json"
fi
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
echo "--- Config complete: $config"
done <<<"$configs"
# Each browser unload event, creates a new coverage file.
# So, we merge them here.
if [[ -d "$functionalTarget" ]]; then
reportMergeFunctional
uniqueifyFunctional "$(date +%s)"
else
echo "--- Code coverage not found in: $functionalTarget"
fi
# Nyc uses matching absolute paths for reporting / merging
# So, set all coverage json files to a specific prefx.
# The prefix will be changed to the kibana dir, in the final stage,
# so nyc doesnt error.
echo "--- Normalize file paths prefix"
replacePaths "$KIBANA_DIR/target/kibana-coverage/functional" "$KIBANA_DIR" "CC_REPLACEMENT_ANCHOR"
if [[ "$failedConfigs" ]]; then
buildkite-agent meta-data set "$FAILED_CONFIGS_KEY" "$failedConfigs"
fi
echo "--- FTR configs complete, result(s):"
printf "%s\n" "${results[@]}"
echo ""
# So the last step "knows" this config ran
uploadRanFile "ftr_configs"
# Force exit 0 to ensure the next build step starts.
exit 0