kibana/.buildkite/scripts/steps/code_coverage/jest_parallel.sh
Tre 5f950e617a
[QA][Code Coverage] follow up pr for ftr auto config handling & fix merge (#131734)
* [QA][Code Coverage] fixup for auto config handling pr

## Summary

Embed buildkite pipeline definition.

Follow up pr to change cc per auto config handling.
Also, resolves https://github.com/elastic/kibana/issues/132706

Increase worker count for `node scripts/build_kibana_platform_plugins` to 4 workers.

Normalize file names within coverage files such that nyc correctly builds the combined summaries.
  _Ci runs this on myriad servers, so the paths are different, which "breaks" nyc's output_

Split the final merge of functional coverage into 2 passes due to [nyc issue](https://github.com/istanbuljs/nyc/issues/1263)

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2022-05-27 12:28:16 +01:00

89 lines
2.7 KiB
Bash
Executable file

#!/bin/bash
set -euo pipefail
source .buildkite/scripts/steps/code_coverage/util.sh
export JOB=$BUILDKITE_PARALLEL_JOB
# a jest failure will result in the script returning an exit code of 10
exitCode=0
results=()
if [[ "$1" == 'jest.config.js' ]]; then
TEST_TYPE="unit"
else
TEST_TYPE="integration"
fi
export TEST_TYPE
echo "--- downloading jest test run order"
buildkite-agent artifact download jest_run_order.json .
configs=$(jq -r 'getpath([env.TEST_TYPE]) | .groups[env.JOB | tonumber].names | .[]' jest_run_order.json)
echo "--- KIBANA_DIR: $KIBANA_DIR"
echo "--- Config(s) for this JEST Group:"
echo "${configs[@]}"
while read -r config; do
echo "--- $ node scripts/jest --config $config --coverage --coverageReporters json --coverageDirectory target/kibana-coverage/jest"
echo "--- Print config name"
echo "### config: $config"
start=$(date +%s)
# prevent non-zero exit code from breaking the loop
set +e
NODE_OPTIONS="--max-old-space-size=14336" node ./scripts/jest \
--config="$config" --runInBand --ci --coverage \
--coverageReporters json --passWithNoTests \
--coverageDirectory target/kibana-coverage/jest
lastCode=$?
set -e
if [[ -f target/kibana-coverage/jest/coverage-final.json ]]; then
echo "--- Rename target/kibana-coverage/jest/coverage-final.json to avoid overwrite"
mv target/kibana-coverage/jest/coverage-final.json "target/kibana-coverage/jest/coverage-$(date +%s%3N).json"
else
echo "Cannot find coverage-final.json"
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
echo "Jest exited with code $lastCode"
echo "^^^ +++"
fi
done <<<"$configs"
echo "--- Normalize file paths prefix before final stage"
# 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.
replacePaths "$KIBANA_DIR/target/kibana-coverage/jest" "$KIBANA_DIR" "CC_REPLACEMENT_ANCHOR"
echo "--- Merging code coverage for a thread"
yarn nyc report --nycrc-path src/dev/code_coverage/nyc_config/nyc.jest.config.js --reporter json
rm -rf target/kibana-coverage/jest/*
mv target/kibana-coverage/jest-combined/coverage-final.json \
"target/kibana-coverage/jest/jest-$TEST_TYPE-merged-coverage-$(date +%s%3N).json"
echo "--- Jest [$TEST_TYPE] configs complete"
printf "%s\n" "${results[@]}"
# Force exit 0 to ensure the next build step starts.
exit 0