@@ -35,6 +35,49 @@ function download_iris() {
3535 --output " ${IRIS_JAR_PATH} " " ${IRIS_JAR_URL} "
3636}
3737
38+ function sonarcloud_compute_engine_status_for_given_project() {
39+ local PROJECT_KEY=" $1 "
40+ curl --silent --fail-with-body --location --request GET \
41+ --header " Authorization: Bearer ${SHADOW_SONAR_TOKEN} " \
42+ --output - \
43+ " ${SHADOW_SONAR_HOST_URL} /api/ce/component?component=${PROJECT_KEY} " | \
44+ jq -r ' .current.status'
45+ }
46+
47+ function wait_for_sonarcloud_compute_engine_to_finish() {
48+ local MAX_WAIT_TIME_SECONDS=" 300" # Default to 5 minutes
49+ local SLEEP_INTERVAL_SECONDS=" 1"
50+ local ELAPSED_TIME=0
51+ local LAST_STATUS=" "
52+ local STATUS
53+
54+ echo " Waiting for SonarCloud compute engine to finish for project key: ${SHADOW_PROJECT_KEY} "
55+ while (( ELAPSED_TIME < MAX_WAIT_TIME_SECONDS )) ; do
56+ STATUS=$( sonarcloud_compute_engine_status_for_given_project " ${SHADOW_PROJECT_KEY} " )
57+ if [[ " ${STATUS} " != " ${LAST_STATUS} " ]]; then
58+ echo -n " ${STATUS} "
59+ LAST_STATUS=" ${STATUS} "
60+ fi
61+
62+ if [[ " ${STATUS} " == " PENDING" || " ${STATUS} " == " IN_PROGRESS" ]]; then
63+ echo -n " ."
64+ elif [[ " ${STATUS} " == " FAILED" || " ${STATUS} " == " CANCELED" ]]; then
65+ echo " \nERROR: SonarCloud compute engine finished with status: ${STATUS} "
66+ return 1
67+ elif [[ " ${STATUS} " == " SUCCESS" ]]; then
68+ echo " \nSonarCloud compute engine finished successfully."
69+ return 0
70+ else
71+ echo " \nERROR: Unknown status: ${STATUS} "
72+ return 1
73+ fi
74+ sleep " ${SLEEP_INTERVAL_SECONDS} "
75+ ELAPSED_TIME=$(( ELAPSED_TIME + SLEEP_INTERVAL_SECONDS))
76+ done
77+ echo " \nERROR: Timeout reached after ${MAX_WAIT_TIME_SECONDS} seconds."
78+ return 1
79+ }
80+
3881function run_iris() {
3982 local DRY_RUN=" $1 "
4083 java \
@@ -70,4 +113,5 @@ function run_iris_with_and_without_dry_run() {
70113
71114build_and_analyze_the_project " $@ "
72115download_iris
116+ wait_for_sonarcloud_compute_engine_to_finish
73117run_iris_with_and_without_dry_run
0 commit comments