Skip to content

Commit ff40d5e

Browse files
committed
Test: Bash Print in CI/CD - Pipeline with detailed information about coverage, duplication and complexity
1 parent da348f0 commit ff40d5e

1 file changed

Lines changed: 9 additions & 35 deletions

File tree

.github/workflows/sonarqube-main.yml

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: SonarCloud Full Metrics (main branch)
22

33
on:
44
push:
5-
branches: [main, master, sonarqube]
5+
branches: [sonarqube]
66
pull_request:
7-
branches: [main, master, sonarqube]
7+
branches: [main, master]
88
workflow_dispatch:
99

1010
permissions:
@@ -42,10 +42,11 @@ jobs:
4242
python -m pytest \
4343
--cov=backend \
4444
--cov-report=xml:backend/coverage.xml \
45+
--cov-report=term-missing \
4546
backend/tests/
4647
continue-on-error: true
4748

48-
# =====================================================
49+
# =====================================================
4950
# SonarCloud Scan
5051
# =====================================================
5152
- name: SonarQube Scan
@@ -80,44 +81,17 @@ jobs:
8081
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
8182
SONAR_HOST: https://sonarcloud.io
8283
QG_STATUS: ${{ steps.qg.outputs.quality-gate-status }}
83-
EVENT_NAME: ${{ github.event_name }}
84-
BRANCH_NAME: ${{ github.ref_name }}
85-
PR_NUMBER: ${{ github.event.pull_request.number }}
8684
run: |
8785
set +e
8886
KEY="GalacticCodeGambit_LazyCook"
8987
OUT="$GITHUB_STEP_SUMMARY"
9088
91-
# ---- Scope der API-Abfrage dynamisch bestimmen ----
92-
# PR-Lauf → ?pullRequest=<nr>
93-
# Push auf nicht-Default-Branch → ?branch=<name>
94-
# Push auf main/master → kein Parameter (Default-Branch)
95-
SCOPE_PARAM=""
96-
SCOPE_DESC="Default-Branch"
97-
if [ -n "${PR_NUMBER}" ]; then
98-
SCOPE_PARAM="&pullRequest=${PR_NUMBER}"
99-
SCOPE_DESC="PR #${PR_NUMBER}"
100-
elif [ "${BRANCH_NAME}" != "main" ] && [ "${BRANCH_NAME}" != "master" ]; then
101-
SCOPE_PARAM="&branch=${BRANCH_NAME}"
102-
SCOPE_DESC="Branch ${BRANCH_NAME}"
103-
fi
104-
echo "Abfrage-Scope: ${SCOPE_DESC}"
105-
106-
# Alle relevanten Metriken auf einen Schwung holen
89+
# Alle relevanten Branch-Metriken auf einen Schwung holen
10790
METRICS="alert_status,bugs,vulnerabilities,code_smells,security_hotspots,security_hotspots_reviewed,coverage,line_coverage,branch_coverage,lines_to_cover,uncovered_lines,duplicated_lines_density,duplicated_blocks,duplicated_files,duplicated_lines,complexity,cognitive_complexity,classes,functions,statements,files,ncloc,comment_lines,comment_lines_density,sqale_rating,reliability_rating,security_rating,security_review_rating,sqale_index,sqale_debt_ratio,reliability_remediation_effort,security_remediation_effort"
10891
109-
URL="${SONAR_HOST}/api/measures/component?component=${KEY}&metricKeys=${METRICS}${SCOPE_PARAM}"
92+
URL="${SONAR_HOST}/api/measures/component?component=${KEY}&metricKeys=${METRICS}"
11093
RESP=$(curl -s -u "${SONAR_TOKEN}:" "${URL}")
11194
112-
# Falls die Scope-Abfrage leer ist: Fallback auf Default-Branch
113-
HAS=$(echo "${RESP}" | jq -r '(.component.measures | length) // 0' 2>/dev/null)
114-
if [ -z "${HAS}" ] || [ "${HAS}" = "0" ]; then
115-
echo "Scope-Abfrage leer, Fallback auf Default-Branch"
116-
URL="${SONAR_HOST}/api/measures/component?component=${KEY}&metricKeys=${METRICS}"
117-
RESP=$(curl -s -u "${SONAR_TOKEN}:" "${URL}")
118-
SCOPE_DESC="${SCOPE_DESC} → fallback Default-Branch"
119-
fi
120-
12195
# Mini-Diagnose im Log
12296
echo "Anfrage: ${URL}"
12397
echo "Response (erste 300 Zeichen):"
@@ -248,7 +222,7 @@ jobs:
248222
} >> "$OUT"
249223
250224
curl -s -u "${SONAR_TOKEN}:" \
251-
"${SONAR_HOST}/api/measures/component_tree?component=${KEY}&metricKeys=complexity,cognitive_complexity,ncloc&qualifiers=FIL&ps=10&s=metric&metricSort=complexity&asc=false${SCOPE_PARAM}" \
225+
"${SONAR_HOST}/api/measures/component_tree?component=${KEY}&metricKeys=complexity,cognitive_complexity,ncloc&qualifiers=FIL&ps=10&s=metric&metricSort=complexity&asc=false" \
252226
| jq -r '.components[]?
253227
| (.path // .key) as $p
254228
| ((.measures[]? | select(.metric=="complexity") | .value) // "-") as $c
@@ -266,7 +240,7 @@ jobs:
266240
} >> "$OUT"
267241
268242
curl -s -u "${SONAR_TOKEN}:" \
269-
"${SONAR_HOST}/api/measures/component_tree?component=${KEY}&metricKeys=coverage,uncovered_lines,ncloc&qualifiers=FIL&ps=10&s=metric&metricSort=coverage&asc=true${SCOPE_PARAM}" \
243+
"${SONAR_HOST}/api/measures/component_tree?component=${KEY}&metricKeys=coverage,uncovered_lines,ncloc&qualifiers=FIL&ps=10&s=metric&metricSort=coverage&asc=true" \
270244
| jq -r '.components[]?
271245
| select(.measures[]? | select(.metric=="coverage"))
272246
| (.path // .key) as $p
@@ -285,7 +259,7 @@ jobs:
285259
} >> "$OUT"
286260
287261
curl -s -u "${SONAR_TOKEN}:" \
288-
"${SONAR_HOST}/api/measures/component_tree?component=${KEY}&metricKeys=duplicated_blocks,duplicated_lines,ncloc&qualifiers=FIL&ps=10&s=metric&metricSort=duplicated_blocks&asc=false${SCOPE_PARAM}" \
262+
"${SONAR_HOST}/api/measures/component_tree?component=${KEY}&metricKeys=duplicated_blocks,duplicated_lines,ncloc&qualifiers=FIL&ps=10&s=metric&metricSort=duplicated_blocks&asc=false" \
289263
| jq -r '.components[]?
290264
| (.path // .key) as $p
291265
| ((.measures[]? | select(.metric=="duplicated_blocks") | .value) // "0") as $b

0 commit comments

Comments
 (0)