kibana/.buildkite/scripts/steps/code_coverage/ingest.sh
Tre d92440e631
[QA][Code Coverage] Modularize Code Coverage (#133759)
Kinda sneaky...since we already mutate the jest portion of the
file system (target/kibana-coverage/jest)
by dumping "jest unit" & "jest integration" coverage
into the same "final" directory...go ahead an make "jest integration"
use the same ran file designator as "jest unit".
This saves me from having to add logic for this later on.
2022-06-13 15:40:59 +01:00

110 lines
3.9 KiB
Bash
Executable file

#!/usr/bin/env bash
set -euo pipefail
source .buildkite/scripts/common/util.sh
source .buildkite/scripts/steps/code_coverage/util.sh
source .buildkite/scripts/steps/code_coverage/merge.sh
export CODE_COVERAGE=1
echo "--- Reading Kibana stats cluster creds from vault"
USER_FROM_VAULT="$(retry 5 5 vault read -field=username secret/kibana-issues/prod/coverage/elasticsearch)"
export USER_FROM_VAULT
PASS_FROM_VAULT="$(retry 5 5 vault read -field=password secret/kibana-issues/prod/coverage/elasticsearch)"
export PASS_FROM_VAULT
HOST_FROM_VAULT="$(retry 5 5 vault read -field=host secret/kibana-issues/prod/coverage/elasticsearch)"
export HOST_FROM_VAULT
TIME_STAMP=$(date +"%Y-%m-%dT%H:%M:00Z")
export TIME_STAMP
echo "--- Download previous git sha"
.buildkite/scripts/steps/code_coverage/reporting/downloadPrevSha.sh
PREVIOUS_SHA=$(cat downloaded_previous.txt)
echo "--- Upload new git sha"
.buildkite/scripts/steps/code_coverage/reporting/uploadPrevSha.sh
.buildkite/scripts/bootstrap.sh
collectRan() {
buildkite-agent artifact download target/ran_files/* .
while read -r x; do
ran=("${ran[@]}" "$(cat "$x")")
done <<<"$(find target/ran_files -maxdepth 1 -type f -name '*.txt')"
echo "--- Collected Ran files: ${ran[*]}"
}
uniqueifyRanConfigs() {
local xs=("$@")
local xss
xss=$(printf "%s\n" "${xs[@]}" | sort -u | tr '\n' ' ' | xargs) # xargs trims whitespace
uniqRanConfigs=("$xss")
echo "--- Uniq Ran files: ${uniqRanConfigs[*]}"
}
fetchArtifacts() {
echo "--- Fetch coverage artifacts"
local xs=("$@")
for x in "${xs[@]}"; do
buildkite-agent artifact download "target/kibana-coverage/${x}/*" .
done
}
archiveReports() {
echo "--- Archive and upload combined reports"
local xs=("$@")
for x in "${xs[@]}"; do
echo "### Collect and Upload for: ${x}"
# fileHeads "target/file-heads-archive-reports-for-${x}.txt" "target/kibana-coverage/${x}"
# dirListing "target/dir-listing-${x}-combined-during-archiveReports.txt" target/kibana-coverage/${x}-combined
# dirListing "target/dir-listing-${x}-during-archiveReports.txt" target/kibana-coverage/${x}
collectAndUpload "target/kibana-coverage/${x}/kibana-${x}-coverage.tar.gz" "target/kibana-coverage/${x}-combined"
done
}
mergeAll() {
local xs=("$@")
for x in "${xs[@]}"; do
if [ "$x" == "jest" ]; then
echo "--- [$x]: Reset file paths prefix, merge coverage files, and generate the final combined report"
replacePaths "$KIBANA_DIR/target/kibana-coverage/jest" "CC_REPLACEMENT_ANCHOR" "$KIBANA_DIR"
yarn nyc report --nycrc-path src/dev/code_coverage/nyc_config/nyc.jest.config.js
elif [ "$x" == "functional" ]; then
echo "---[$x] : Reset file paths prefix, merge coverage files, and generate the final combined report"
set +e
sed -ie "s|CC_REPLACEMENT_ANCHOR|${KIBANA_DIR}|g" target/kibana-coverage/functional/*.json
echo "--- Begin Split and Merge for Functional"
splitCoverage target/kibana-coverage/functional
splitMerge
set -e
fi
done
}
modularize() {
collectRan
if [ -d target/ran_files ]; then
uniqueifyRanConfigs "${ran[@]}"
fetchArtifacts "${uniqRanConfigs[@]}"
mergeAll "${uniqRanConfigs[@]}"
archiveReports "${uniqRanConfigs[@]}"
.buildkite/scripts/steps/code_coverage/reporting/prokLinks.sh "${uniqRanConfigs[@]}"
.buildkite/scripts/steps/code_coverage/reporting/uploadStaticSite.sh "${uniqRanConfigs[@]}"
.buildkite/scripts/steps/code_coverage/reporting/collectVcsInfo.sh
source .buildkite/scripts/steps/code_coverage/reporting/ingestData.sh 'elastic+kibana+code-coverage' \
"${BUILDKITE_BUILD_NUMBER}" "${BUILDKITE_BUILD_URL}" "${PREVIOUS_SHA}" \
'src/dev/code_coverage/ingest_coverage/team_assignment/team_assignments.txt'
ingestModular "${uniqRanConfigs[@]}"
else
echo "--- Found zero configs that ran, cancelling ingestion."
exit 11
fi
}
modularize
echo "### unique ran configs: ${uniqRanConfigs[*]}"