mirror of
https://github.com/SonarSource/sonarqube-quality-gate-action.git
synced 2026-10-03 10:21:31 +00:00
SQQGGHA-5 Ambiguous redirect when GITHUB_OUTPUT is not set (#33)
This commit is contained in:
1 parent
745e48ebda
commit
d304d050d9
3 files changed
+68
-4
No files matched your search
@@ -43,16 +43,16 @@ qualityGateStatus="$(curl --location --location-trusted --max-redirs 10 --silent
|
|||||||
|
|
||||||
printf '\n'
|
printf '\n'
|
||||||
if [[ ${qualityGateStatus} == "OK" ]]; then
|
if [[ ${qualityGateStatus} == "OK" ]]; then
|
||||||
echo 'quality-gate-status=PASSED' >> ${GITHUB_OUTPUT}
|
set_output "quality-gate-status" "PASSED"
|
||||||
success "Quality Gate has PASSED."
|
success "Quality Gate has PASSED."
|
||||||
elif [[ ${qualityGateStatus} == "WARN" ]]; then
|
elif [[ ${qualityGateStatus} == "WARN" ]]; then
|
||||||
echo 'quality-gate-status=WARN' >> ${GITHUB_OUTPUT}
|
set_output "quality-gate-status" "WARN"
|
||||||
warn "Warnings on Quality Gate."
|
warn "Warnings on Quality Gate."
|
||||||
elif [[ ${qualityGateStatus} == "ERROR" ]]; then
|
elif [[ ${qualityGateStatus} == "ERROR" ]]; then
|
||||||
echo 'quality-gate-status=FAILED' >> ${GITHUB_OUTPUT}
|
set_output "quality-gate-status" "FAILED"
|
||||||
fail "Quality Gate has FAILED."
|
fail "Quality Gate has FAILED."
|
||||||
else
|
else
|
||||||
echo 'quality-gate-status=FAILED' >> ${GITHUB_OUTPUT}
|
set_output "quality-gate-status" "FAILED"
|
||||||
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
|
||||||
|
|
||||||
@@ -23,6 +23,15 @@ success() { echo -e "${green}✔ $*${reset}"; }
|
|||||||
warn() { echo -e "${yellow}✖ $*${reset}"; exit 1; }
|
warn() { echo -e "${yellow}✖ $*${reset}"; exit 1; }
|
||||||
fail() { echo -e "${red}✖ $*${reset}"; exit 1; }
|
fail() { echo -e "${red}✖ $*${reset}"; exit 1; }
|
||||||
|
|
||||||
|
# support old GH Actions runners
|
||||||
|
set_output () {
|
||||||
|
if [[ -n "${GITHUB_OUTPUT}" ]]; then
|
||||||
|
echo "${1}=${2}" >> "${GITHUB_OUTPUT}"
|
||||||
|
else
|
||||||
|
echo "::set-output name=${1}::${2}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
## Enable debug mode.
|
## Enable debug mode.
|
||||||
enable_debug() {
|
enable_debug() {
|
||||||
if [[ "${DEBUG}" == "true" ]]; then
|
if [[ "${DEBUG}" == "true" ]]; then
|
||||||
|
|||||||
@@ -192,3 +192,58 @@ teardown() {
|
|||||||
[[ "${lines[0]}" = "....." ]]
|
[[ "${lines[0]}" = "....." ]]
|
||||||
[[ "${lines[1]}" = *"Quality Gate has PASSED."* ]]
|
[[ "${lines[1]}" = *"Quality Gate has PASSED."* ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "pass spaces in GITHUB_OUTPUT path are handled" {
|
||||||
|
export SONAR_TOKEN="test"
|
||||||
|
echo "serverUrl=http://localhost:9000" >> metadata_tmp
|
||||||
|
echo "ceTaskUrl=http://localhost:9000/api/ce/task?id=AXlCe3gsFwOUsY8YKHTn" >> metadata_tmp
|
||||||
|
|
||||||
|
#mock curl
|
||||||
|
function curl() {
|
||||||
|
url="${@: -1}"
|
||||||
|
if [[ $url == *"/api/qualitygates/project_status?analysisId"* ]]; then
|
||||||
|
echo '{"projectStatus":{"status":"OK"}}'
|
||||||
|
else
|
||||||
|
echo '{"task":{"analysisId":"AXlCe3jz9LkwR9Gs0pBY","status":"SUCCESS"}}'
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
export -f curl
|
||||||
|
|
||||||
|
# GITHUB_OUTPUT is a path with spaces
|
||||||
|
github_output_dir="${BATS_TEST_TMPDIR}/some subdir"
|
||||||
|
mkdir -p "${github_output_dir}"
|
||||||
|
export GITHUB_OUTPUT="${github_output_dir}/github_output"
|
||||||
|
touch "${GITHUB_OUTPUT}"
|
||||||
|
|
||||||
|
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" ]]
|
||||||
|
[[ "$output" = *"Quality Gate has PASSED."* ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "pass fall back to set-output if GITHUB_OUTPUT unset" {
|
||||||
|
export SONAR_TOKEN="test"
|
||||||
|
unset GITHUB_OUTPUT
|
||||||
|
echo "serverUrl=http://localhost:9000" >> metadata_tmp
|
||||||
|
echo "ceTaskUrl=http://localhost:9000/api/ce/task?id=AXlCe3gsFwOUsY8YKHTn" >> metadata_tmp
|
||||||
|
|
||||||
|
#mock curl
|
||||||
|
function curl() {
|
||||||
|
url="${@: -1}"
|
||||||
|
if [[ $url == *"/api/qualitygates/project_status?analysisId"* ]]; then
|
||||||
|
echo '{"projectStatus":{"status":"OK"}}'
|
||||||
|
else
|
||||||
|
echo '{"task":{"analysisId":"AXlCe3jz9LkwR9Gs0pBY","status":"SUCCESS"}}'
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
export -f curl
|
||||||
|
|
||||||
|
run script/check-quality-gate.sh metadata_tmp
|
||||||
|
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[[ "$output" = *"::set-output name=quality-gate-status::PASSED"* ]]
|
||||||
|
[[ "$output" = *"Quality Gate has PASSED."* ]]
|
||||||
|
}
|
||||||
Reference in new issue
Block a user