mirror of
https://github.com/SonarSource/sonarqube-quality-gate-action.git
synced 2026-10-03 10:21:31 +00:00
SQQGGHA-6 SQQGGHA-5 Migrate set-output to environment files
This commit is contained in:
1 parent
00d36147d5
commit
745e48ebda
2 files changed
+64
-8
No files matched your search
@@ -41,17 +41,18 @@ analysisId="$(jq -r '.task.analysisId' <<< "${task}")"
|
|||||||
qualityGateUrl="${serverUrl}/api/qualitygates/project_status?analysisId=${analysisId}"
|
qualityGateUrl="${serverUrl}/api/qualitygates/project_status?analysisId=${analysisId}"
|
||||||
qualityGateStatus="$(curl --location --location-trusted --max-redirs 10 --silent --fail --show-error --user "${SONAR_TOKEN}": "${qualityGateUrl}" | jq -r '.projectStatus.status')"
|
qualityGateStatus="$(curl --location --location-trusted --max-redirs 10 --silent --fail --show-error --user "${SONAR_TOKEN}": "${qualityGateUrl}" | jq -r '.projectStatus.status')"
|
||||||
|
|
||||||
|
printf '\n'
|
||||||
if [[ ${qualityGateStatus} == "OK" ]]; then
|
if [[ ${qualityGateStatus} == "OK" ]]; then
|
||||||
echo '::set-output name=quality-gate-status::PASSED'
|
echo 'quality-gate-status=PASSED' >> ${GITHUB_OUTPUT}
|
||||||
success "Quality Gate has PASSED."
|
success "Quality Gate has PASSED."
|
||||||
elif [[ ${qualityGateStatus} == "WARN" ]]; then
|
elif [[ ${qualityGateStatus} == "WARN" ]]; then
|
||||||
echo '::set-output name=quality-gate-status::WARN'
|
echo 'quality-gate-status=WARN' >> ${GITHUB_OUTPUT}
|
||||||
warn "Warnings on Quality Gate."
|
warn "Warnings on Quality Gate."
|
||||||
elif [[ ${qualityGateStatus} == "ERROR" ]]; then
|
elif [[ ${qualityGateStatus} == "ERROR" ]]; then
|
||||||
echo '::set-output name=quality-gate-status::FAILED'
|
echo 'quality-gate-status=FAILED' >> ${GITHUB_OUTPUT}
|
||||||
fail "Quality Gate has FAILED."
|
fail "Quality Gate has FAILED."
|
||||||
else
|
else
|
||||||
echo '::set-output name=quality-gate-status::FAILED'
|
echo 'quality-gate-status=FAILED' >> ${GITHUB_OUTPUT}
|
||||||
fail "Quality Gate not set for the project. Please configure the Quality Gate in SonarQube or remove sonarqube-quality-gate action from the workflow."
|
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
|
fi
|
||||||
|
|
||||||
@@ -3,11 +3,14 @@
|
|||||||
setup() {
|
setup() {
|
||||||
DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )"
|
DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )"
|
||||||
PATH="$DIR/../src:$PATH"
|
PATH="$DIR/../src:$PATH"
|
||||||
|
export GITHUB_OUTPUT=${BATS_TEST_TMPDIR}/github_output
|
||||||
|
touch ${GITHUB_OUTPUT}
|
||||||
touch metadata_tmp
|
touch metadata_tmp
|
||||||
}
|
}
|
||||||
|
|
||||||
teardown() {
|
teardown() {
|
||||||
rm -f metadata_tmp
|
rm -f metadata_tmp
|
||||||
|
unset GITHUB_OUTPUT
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "fail when SONAR_TOKEN not provided" {
|
@test "fail when SONAR_TOKEN not provided" {
|
||||||
@@ -66,9 +69,12 @@ teardown() {
|
|||||||
export -f curl
|
export -f curl
|
||||||
|
|
||||||
run script/check-quality-gate.sh metadata_tmp
|
run script/check-quality-gate.sh metadata_tmp
|
||||||
|
|
||||||
|
read -r github_out_actual < ${GITHUB_OUTPUT}
|
||||||
|
|
||||||
[ "$status" -eq 1 ]
|
[ "$status" -eq 1 ]
|
||||||
|
[[ "${github_out_actual}" = "quality-gate-status=FAILED" ]]
|
||||||
[[ "$output" = *"Quality Gate not set for the project. Please configure the Quality Gate in SonarQube or remove sonarqube-quality-gate action from the workflow."* ]]
|
[[ "$output" = *"Quality Gate not set for the project. Please configure the Quality Gate in SonarQube or remove sonarqube-quality-gate action from the workflow."* ]]
|
||||||
[[ "$output" = *"name=quality-gate-status::FAILED"* ]]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "fail when Quality Gate status WARN" {
|
@test "fail when Quality Gate status WARN" {
|
||||||
@@ -88,9 +94,12 @@ teardown() {
|
|||||||
export -f curl
|
export -f curl
|
||||||
|
|
||||||
run script/check-quality-gate.sh metadata_tmp
|
run script/check-quality-gate.sh metadata_tmp
|
||||||
|
|
||||||
|
read -r github_out_actual < ${GITHUB_OUTPUT}
|
||||||
|
|
||||||
[ "$status" -eq 1 ]
|
[ "$status" -eq 1 ]
|
||||||
|
[[ "${github_out_actual}" = "quality-gate-status=WARN" ]]
|
||||||
[[ "$output" = *"Warnings on Quality Gate."* ]]
|
[[ "$output" = *"Warnings on Quality Gate."* ]]
|
||||||
[[ "$output" = *"name=quality-gate-status::WARN"* ]]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "fail when Quality Gate status ERROR" {
|
@test "fail when Quality Gate status ERROR" {
|
||||||
@@ -110,9 +119,12 @@ teardown() {
|
|||||||
export -f curl
|
export -f curl
|
||||||
|
|
||||||
run script/check-quality-gate.sh metadata_tmp
|
run script/check-quality-gate.sh metadata_tmp
|
||||||
|
|
||||||
|
read -r github_out_actual < ${GITHUB_OUTPUT}
|
||||||
|
|
||||||
[ "$status" -eq 1 ]
|
[ "$status" -eq 1 ]
|
||||||
|
[[ "${github_out_actual}" = "quality-gate-status=FAILED" ]]
|
||||||
[[ "$output" = *"Quality Gate has FAILED."* ]]
|
[[ "$output" = *"Quality Gate has FAILED."* ]]
|
||||||
[[ "$output" = *"name=quality-gate-status::FAILED"* ]]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "pass when Quality Gate status OK" {
|
@test "pass when Quality Gate status OK" {
|
||||||
@@ -132,8 +144,51 @@ teardown() {
|
|||||||
export -f curl
|
export -f curl
|
||||||
|
|
||||||
run script/check-quality-gate.sh metadata_tmp
|
run script/check-quality-gate.sh metadata_tmp
|
||||||
|
|
||||||
|
read -r github_out_actual < ${GITHUB_OUTPUT}
|
||||||
|
|
||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
|
[[ "${github_out_actual}" = "quality-gate-status=PASSED" ]]
|
||||||
[[ "$output" = *"Quality Gate has PASSED."* ]]
|
[[ "$output" = *"Quality Gate has PASSED."* ]]
|
||||||
[[ "$output" = *"name=quality-gate-status::PASSED"* ]]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "pass when Quality Gate status OK and status starts from IN_PROGRESS" {
|
||||||
|
export SONAR_TOKEN="test"
|
||||||
|
export COUNTER_FILE=${BATS_TEST_TMPDIR}/counter
|
||||||
|
echo "serverUrl=http://localhost:9000" >> metadata_tmp
|
||||||
|
echo "ceTaskUrl=http://localhost:9000/api/ce/task?id=AXlCe3gsFwOUsY8YKHTn" >> metadata_tmp
|
||||||
|
|
||||||
|
printf "5" > ${COUNTER_FILE}
|
||||||
|
|
||||||
|
#mock curl
|
||||||
|
function curl() {
|
||||||
|
read -r counter < ${COUNTER_FILE}
|
||||||
|
|
||||||
|
url="${@: -1}"
|
||||||
|
if [[ $url == *"/api/qualitygates/project_status?analysisId"* ]]; then
|
||||||
|
echo '{"projectStatus":{"status":"OK"}}'
|
||||||
|
elif [[ $counter -gt 0 ]]; then
|
||||||
|
echo '{"task":{"analysisId":"AXlCe3jz9LkwR9Gs0pBY","status":"IN_PROGRESS"}}'
|
||||||
|
printf "%d\n" "$(( --counter ))" > ${COUNTER_FILE}
|
||||||
|
else
|
||||||
|
echo '{"task":{"analysisId":"AXlCe3jz9LkwR9Gs0pBY","status":"SUCCESS"}}'
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
export -f curl
|
||||||
|
|
||||||
|
#mock sleep
|
||||||
|
function sleep() {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
export -f sleep
|
||||||
|
|
||||||
|
run script/check-quality-gate.sh metadata_tmp
|
||||||
|
|
||||||
|
read -r github_out_actual < ${GITHUB_OUTPUT}
|
||||||
|
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[[ "${github_out_actual}" = "quality-gate-status=PASSED" ]]
|
||||||
|
# lines[0] is the dots from waiting for status to move to SUCCESS
|
||||||
|
[[ "${lines[0]}" = "....." ]]
|
||||||
|
[[ "${lines[1]}" = *"Quality Gate has PASSED."* ]]
|
||||||
|
}
|
||||||
Reference in new issue
Block a user