@@ -8,59 +8,103 @@ source .buildkite/scripts/steps/code_coverage/merge.sh
88
99export CODE_COVERAGE=1
1010echo " --- Reading Kibana stats cluster creds from vault"
11- export USER_FROM_VAULT=" $( retry 5 5 vault read -field=username secret/kibana-issues/prod/coverage/elasticsearch) "
12- export PASS_FROM_VAULT=" $( retry 5 5 vault read -field=password secret/kibana-issues/prod/coverage/elasticsearch) "
13- export HOST_FROM_VAULT=" $( retry 5 5 vault read -field=host secret/kibana-issues/prod/coverage/elasticsearch) "
14- export TIME_STAMP=$( date +" %Y-%m-%dT%H:%M:00Z" )
15-
16- echo " --- Print KIBANA_DIR"
17- echo " ### KIBANA_DIR: $KIBANA_DIR "
11+ USER_FROM_VAULT=" $( retry 5 5 vault read -field=username secret/kibana-issues/prod/coverage/elasticsearch) "
12+ export USER_FROM_VAULT
13+ PASS_FROM_VAULT=" $( retry 5 5 vault read -field=password secret/kibana-issues/prod/coverage/elasticsearch) "
14+ export PASS_FROM_VAULT
15+ HOST_FROM_VAULT=" $( retry 5 5 vault read -field=host secret/kibana-issues/prod/coverage/elasticsearch) "
16+ export HOST_FROM_VAULT
17+ TIME_STAMP=$( date +" %Y-%m-%dT%H:%M:00Z" )
18+ export TIME_STAMP
1819
1920echo " --- Download previous git sha"
2021.buildkite/scripts/steps/code_coverage/reporting/downloadPrevSha.sh
21- previousSha =$( cat downloaded_previous.txt)
22+ PREVIOUS_SHA =$( cat downloaded_previous.txt)
2223
2324echo " --- Upload new git sha"
2425.buildkite/scripts/steps/code_coverage/reporting/uploadPrevSha.sh
2526
2627.buildkite/scripts/bootstrap.sh
2728
28- echo " --- Download coverage artifacts"
29- buildkite-agent artifact download target/kibana-coverage/jest/* .
30- # buildkite-agent artifact download target/kibana-coverage/functional/* .
31- buildkite-agent artifact download target/ran_files/* .
32- ls -l target/ran_files/* || echo " ### No ran-files found"
33-
34- echo " --- process HTML Links"
35- .buildkite/scripts/steps/code_coverage/reporting/prokLinks.sh
36-
37- echo " --- collect VCS Info"
38- .buildkite/scripts/steps/code_coverage/reporting/collectVcsInfo.sh
39-
40- echo " --- Jest: Reset file paths prefix, merge coverage files, and generate the final combined report"
41- # Jest: Reset file paths prefix to Kibana Dir of final worker
42- replacePaths " $KIBANA_DIR /target/kibana-coverage/jest" " CC_REPLACEMENT_ANCHOR" " $KIBANA_DIR "
43- yarn nyc report --nycrc-path src/dev/code_coverage/nyc_config/nyc.jest.config.js
44-
45- # echo "--- Functional: Reset file paths prefix, merge coverage files, and generate the final combined report"
46- # Functional: Reset file paths prefix to Kibana Dir of final worker
47- # set +e
48- # sed -ie "s|CC_REPLACEMENT_ANCHOR|${KIBANA_DIR}|g" target/kibana-coverage/functional/*.json
49- # echo "--- Begin Split and Merge for Functional"
50- # splitCoverage target/kibana-coverage/functional
51- # splitMerge
52- # set -e
53-
54- echo " --- Archive and upload combined reports"
55- collectAndUpload target/kibana-coverage/jest/kibana-jest-coverage.tar.gz \
56- target/kibana-coverage/jest-combined
57- # collectAndUpload target/kibana-coverage/functional/kibana-functional-coverage.tar.gz \
58- # target/kibana-coverage/functional-combined
59-
60- echo " --- Upload coverage static site"
61- .buildkite/scripts/steps/code_coverage/reporting/uploadStaticSite.sh
62-
63- echo " --- Ingest results to Kibana stats cluster"
64- .buildkite/scripts/steps/code_coverage/reporting/ingestData.sh ' elastic+kibana+code-coverage' \
65- ${BUILDKITE_BUILD_NUMBER} ${BUILDKITE_BUILD_URL} ${previousSha} \
66- ' src/dev/code_coverage/ingest_coverage/team_assignment/team_assignments.txt'
29+ collectRan () {
30+ buildkite-agent artifact download target/ran_files/* .
31+
32+ while read -r x; do
33+ ran=(" ${ran[@]} " " $( cat " $x " ) " )
34+ done <<< " $(find target/ran_files -maxdepth 1 -type f -name '*.txt')"
35+
36+ echo " --- Collected Ran files: ${ran[*]} "
37+ }
38+
39+ uniqueifyRanConfigs () {
40+ local xs=(" $@ " )
41+ local xss
42+ xss=$( printf " %s\n" " ${xs[@]} " | sort -u | tr ' \n' ' ' | xargs) # xargs trims whitespace
43+ uniqRanConfigs=(" $xss " )
44+ echo " --- Uniq Ran files: ${uniqRanConfigs[*]} "
45+ }
46+
47+ fetchArtifacts () {
48+ echo " --- Fetch coverage artifacts"
49+
50+ local xs=(" $@ " )
51+ for x in " ${xs[@]} " ; do
52+ buildkite-agent artifact download " target/kibana-coverage/${x} /*" .
53+ done
54+ }
55+
56+ archiveReports () {
57+ echo " --- Archive and upload combined reports"
58+
59+ local xs=(" $@ " )
60+ for x in " ${xs[@]} " ; do
61+ echo " ### Collect and Upload for: ${x} "
62+ # fileHeads "target/file-heads-archive-reports-for-${x}.txt" "target/kibana-coverage/${x}"
63+ # dirListing "target/dir-listing-${x}-combined-during-archiveReports.txt" target/kibana-coverage/${x}-combined
64+ # dirListing "target/dir-listing-${x}-during-archiveReports.txt" target/kibana-coverage/${x}
65+ collectAndUpload " target/kibana-coverage/${x} /kibana-${x} -coverage.tar.gz" " target/kibana-coverage/${x} -combined"
66+ done
67+ }
68+
69+ mergeAll () {
70+ local xs=(" $@ " )
71+
72+ for x in " ${xs[@]} " ; do
73+ if [ " $x " == " jest" ]; then
74+ echo " --- [$x ]: Reset file paths prefix, merge coverage files, and generate the final combined report"
75+ replacePaths " $KIBANA_DIR /target/kibana-coverage/jest" " CC_REPLACEMENT_ANCHOR" " $KIBANA_DIR "
76+ yarn nyc report --nycrc-path src/dev/code_coverage/nyc_config/nyc.jest.config.js
77+ elif [ " $x " == " functional" ]; then
78+ echo " ---[$x ] : Reset file paths prefix, merge coverage files, and generate the final combined report"
79+ set +e
80+ sed -ie " s|CC_REPLACEMENT_ANCHOR|${KIBANA_DIR} |g" target/kibana-coverage/functional/* .json
81+ echo " --- Begin Split and Merge for Functional"
82+ splitCoverage target/kibana-coverage/functional
83+ splitMerge
84+ set -e
85+ fi
86+ done
87+ }
88+
89+ modularize () {
90+ collectRan
91+ if [ -d target/ran_files ]; then
92+ uniqueifyRanConfigs " ${ran[@]} "
93+ fetchArtifacts " ${uniqRanConfigs[@]} "
94+ mergeAll " ${uniqRanConfigs[@]} "
95+ archiveReports " ${uniqRanConfigs[@]} "
96+ .buildkite/scripts/steps/code_coverage/reporting/prokLinks.sh " ${uniqRanConfigs[@]} "
97+ .buildkite/scripts/steps/code_coverage/reporting/uploadStaticSite.sh " ${uniqRanConfigs[@]} "
98+ .buildkite/scripts/steps/code_coverage/reporting/collectVcsInfo.sh
99+ source .buildkite/scripts/steps/code_coverage/reporting/ingestData.sh ' elastic+kibana+code-coverage' \
100+ " ${BUILDKITE_BUILD_NUMBER} " " ${BUILDKITE_BUILD_URL} " " ${PREVIOUS_SHA} " \
101+ ' src/dev/code_coverage/ingest_coverage/team_assignment/team_assignments.txt'
102+ ingestModular " ${uniqRanConfigs[@]} "
103+ else
104+ echo " --- Found zero configs that ran, cancelling ingestion."
105+ exit 11
106+ fi
107+ }
108+
109+ modularize
110+ echo " ### unique ran configs: ${uniqRanConfigs[*]} "
0 commit comments