Skip to content

Commit 4f31254

Browse files
JAVASE-14 Wait for the sonarcloud compute engine to finish (#38)
1 parent 437e385 commit 4f31254

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

shadow-scan-and-issue-replication.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,62 @@ 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+
local RESPONSE
41+
RESPONSE="$(
42+
curl --silent --fail-with-body --location --request GET \
43+
--header "Authorization: Bearer ${SHADOW_SONAR_TOKEN}" \
44+
--output - \
45+
"${SHADOW_SONAR_HOST_URL}/api/ce/component?component=${PROJECT_KEY}"
46+
)"
47+
local STATUS
48+
# we first check if there is one or more 'PENDING' tasks in the queue
49+
STATUS="$(echo "${RESPONSE}" | jq -r '.queue[].status')"
50+
if [[ "${STATUS}" == "null" ]]; then
51+
STATUS=""
52+
fi
53+
if [[ -z "${STATUS}" ]]; then
54+
# otherwise we get the status of the current task
55+
STATUS="$(echo "${RESPONSE}" | jq -r '.current.status')"
56+
fi
57+
echo -n "${STATUS}"
58+
}
59+
60+
function wait_for_sonarcloud_compute_engine_to_finish() {
61+
local MAX_WAIT_TIME_SECONDS="300" # Default to 5 minutes
62+
local SLEEP_INTERVAL_SECONDS="1"
63+
local ELAPSED_TIME=0
64+
local LAST_STATUS=""
65+
local STATUS
66+
67+
echo "Waiting for SonarCloud compute engine to finish for project key: ${SHADOW_PROJECT_KEY}"
68+
while (( ELAPSED_TIME < MAX_WAIT_TIME_SECONDS )); do
69+
STATUS=$(sonarcloud_compute_engine_status_for_given_project "${SHADOW_PROJECT_KEY}")
70+
if [[ "${STATUS}" != "${LAST_STATUS}" ]]; then
71+
echo -n " ${STATUS} "
72+
LAST_STATUS="${STATUS}"
73+
fi
74+
75+
if [[ "${STATUS}" == "PENDING" || "${STATUS}" == "IN_PROGRESS" ]]; then
76+
echo -n "."
77+
elif [[ "${STATUS}" == "FAILED" || "${STATUS}" == "CANCELED" ]]; then
78+
echo -e "\nERROR: SonarCloud compute engine finished with status: ${STATUS}"
79+
return 1
80+
elif [[ "${STATUS}" == "SUCCESS" ]]; then
81+
echo -e "\nSonarCloud compute engine finished successfully."
82+
return 0
83+
else
84+
echo -e "\nERROR: Unknown status: ${STATUS}"
85+
return 1
86+
fi
87+
sleep "${SLEEP_INTERVAL_SECONDS}"
88+
ELAPSED_TIME=$((ELAPSED_TIME + SLEEP_INTERVAL_SECONDS))
89+
done
90+
echo -e "\nERROR: Timeout reached after ${MAX_WAIT_TIME_SECONDS} seconds."
91+
return 1
92+
}
93+
3894
function run_iris() {
3995
local DRY_RUN="$1"
4096
java \
@@ -70,4 +126,5 @@ function run_iris_with_and_without_dry_run() {
70126

71127
build_and_analyze_the_project "$@"
72128
download_iris
129+
wait_for_sonarcloud_compute_engine_to_finish
73130
run_iris_with_and_without_dry_run

0 commit comments

Comments
 (0)