SONAR-14825 Provide Quality Gate check GitHub Action

This commit is contained in:
Jacek committed 2021-05-14 09:04:32 +02:00
commit 388210fd6e
9 files changed
+496

No files matched your search

+48
View File
@@ -0,0 +1,48 @@
#!/usr/bin/env bash
source "$(dirname "$0")/common.sh"
if [[ -z "${SONAR_TOKEN}" ]]; then
echo "Set the SONAR_TOKEN env variable."
exit 1
fi
metadataFile="$1"
if [[ ! -f "$metadataFile" ]]; then
echo "$metadataFile does not exist."
exit 1
fi
serverUrl="$(sed -n 's/serverUrl=\(.*\)/\1/p' ${metadataFile})"
ceTaskUrl="$(sed -n 's/ceTaskUrl=\(.*\)/\1/p' ${metadataFile})"
if [ -z "${serverUrl}" ] || [ -z "${ceTaskUrl}" ]; then
echo "Invalid report metadata file."
exit 1
fi
task="$(curl --silent --fail --show-error --user ${SONAR_TOKEN}: ${ceTaskUrl})"
status="$(jq -r '.task.status' <<< "$task")"
until [[ ${status} != "PENDING" && ${status} != "IN_PROGRESS" ]]; do
printf '.'
sleep 5s
task="$(curl --silent --fail --show-error --user ${SONAR_TOKEN}: ${ceTaskUrl})"
status="$(jq -r '.task.status' <<< "$task")"
done
analysisId="$(jq -r '.task.analysisId' <<< "${task}")"
qualityGateUrl="${serverUrl}/api/qualitygates/project_status?analysisId=${analysisId}"
qualityGateStatus="$(curl --silent --fail --show-error --user ${SONAR_TOKEN}: ${qualityGateUrl} | jq -r '.projectStatus.status')"
if [[ ${qualityGateStatus} == "OK" ]];then
success "Quality Gate has PASSED."
elif [[ ${qualityGateStatus} == "WARN" ]];then
warn "Warnings on Quality Gate."
elif [[ ${qualityGateStatus} == "ERROR" ]];then
fail "Quality Gate has FAILED."
else
fail "Quality Gate not set for the project. Please configure the Quality Gate in SonarQube or remove sonarqube-quality-gate action from the workflow."
fi
+49
View File
@@ -0,0 +1,49 @@
#!/usr/bin/env bash
# Begin Standard 'imports'
set -e
set -o pipefail
gray="\\e[37m"
blue="\\e[36m"
red="\\e[31m"
yellow="\\e[33m"
green="\\e[32m"
reset="\\e[0m"
info() { echo -e "${blue}INFO: $*${reset}"; }
error() { echo -e "${red}ERROR: $*${reset}"; }
debug() {
if [[ "${DEBUG}" == "true" ]]; then
echo -e "${gray}DEBUG: $*${reset}";
fi
}
success() { echo -e "${green}✔ $*${reset}"; }
warn() { echo -e "${yellow}✖ $*${reset}"; exit 1; }
fail() { echo -e "${red}✖ $*${reset}"; exit 1; }
## Enable debug mode.
enable_debug() {
if [[ "${DEBUG}" == "true" ]]; then
info "Enabling debug mode."
set -x
fi
}
# Execute a command, saving its output and exit status code, and echoing its output upon completion.
# Globals set:
# status: Exit status of the command that was executed.
# output: Output generated from the command.
#
run() {
echo "$@"
set +e
output=$("$@" 2>&1)
status=$?
set -e
echo "${output}"
}
# End standard 'imports'