Skip to content

Commit 8aa1649

Browse files
author
“jagnd1”
committed
fix coverage format compatibility and update deprecated action
- use sonarqube-scan-action@v5.0.0 instead of deprecated action - generate coverage from project root for proper path alignment - use generic coverage format for sonarcloud compatibility
1 parent 557f15d commit 8aa1649

2 files changed

Lines changed: 21 additions & 27 deletions

File tree

.github/workflows/sonarcloud.yml

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -106,35 +106,31 @@ jobs:
106106
export PROTOCOL="http"
107107
export PYTHONPATH="../:$PYTHONPATH"
108108
109-
# Generate coverage with proper relative paths for SonarCloud
109+
# Generate coverage for SonarCloud (using simple format)
110110
pytest unit_tests/ integration_tests/ e2e_tests/ \
111111
--cov=../crypto_service \
112112
--cov=../pki_service \
113113
--cov=../common \
114-
--cov-report=xml:coverage.xml \
114+
--cov-report=term-missing \
115115
--junitxml=test-results.xml \
116116
-v
117117
118-
# CRITICAL: Fix absolute paths to relative paths for SonarCloud
119-
sed -i 's|filename="/home/runner/work/fmcrypto/fmcrypto/|filename="|g' coverage.xml
120-
sed -i 's|filename="home/runner/work/fmcrypto/fmcrypto/|filename="|g' coverage.xml
121-
122-
# FINAL FIX: Fix sources section to match sonar.sources=.
123-
sed -i 's|<source>../common</source>|<source>common</source>|g' coverage.xml
124-
sed -i 's|<source>../crypto_service</source>|<source>crypto_service</source>|g' coverage.xml
125-
sed -i 's|<source>../pki_service</source>|<source>pki_service</source>|g' coverage.xml
126-
127-
# Verify ALL fixes worked (paths AND sources)
128-
echo "=== Verifying path fix ==="
129-
grep 'filename=' coverage.xml | head -3
130-
echo "=== Verifying sources section ==="
131-
grep '<source>' coverage.xml
118+
# Generate SonarCloud-compatible coverage using coverage.py directly
119+
cd ..
120+
coverage run --source=crypto_service,pki_service,common -m pytest testing/unit_tests/ testing/integration_tests/ testing/e2e_tests/ -q
121+
coverage xml -o testing/coverage.xml
122+
cd testing
132123
133-
# DIAGNOSTIC: Show coverage file stats for SonarCloud
134-
echo "=== Coverage file diagnostic ==="
135-
echo "File size: $(ls -lh coverage.xml | awk '{print $5}')"
136-
echo "Line count: $(wc -l < coverage.xml)"
137-
echo "Coverage rate: $(grep 'line-rate=' coverage.xml | head -1)"
124+
# Verify coverage file generated correctly
125+
echo "=== Coverage file verification ==="
126+
if [ -f coverage.xml ]; then
127+
echo "Coverage file generated successfully"
128+
echo "File size: $(ls -lh coverage.xml | awk '{print $5}')"
129+
echo "First few lines:"
130+
head -10 coverage.xml
131+
else
132+
echo "ERROR: coverage.xml not generated"
133+
fi
138134
139135
- name: stop services
140136
if: always()
@@ -174,14 +170,13 @@ jobs:
174170
find . -name "*.py" -path "./common/*" | head -3
175171
176172
- name: sonarcloud scan
177-
uses: SonarSource/sonarcloud-github-action@master
173+
uses: SonarSource/sonarqube-scan-action@v5.0.0
178174
env:
179175
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
180176
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
181177
with:
182178
projectBaseDir: .
183-
# use the sonar-project.properties file from testing directory
184-
# override key settings for sonarcloud
179+
# use the sonar-project.properties file from project root
185180
args: >
186181
-Dsonar.projectKey=jagnd1_fmcrypto
187182
-Dsonar.organization=jagnd1

sonar-project.properties

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ sonar.tests=testing
1616
# exclude test files and non-source directories from analysis
1717
sonar.exclusions=**/test_*.py,**/tests/**,**/*_test.py,**/test.py,testing/**,deployment/**,.github/**,**/.venv/**,**/htmlcov/**,**/.pytest_cache/**,**/__pycache__/**
1818

19-
# test execution and coverage (multiple formats to force processing)
20-
sonar.python.coverage.reportPaths=testing/coverage.xml
21-
sonar.python.xunit.reportPath=testing/test-results.xml
19+
# test execution and coverage (use generic format for compatibility)
2220
sonar.coverageReportPaths=testing/coverage.xml
21+
sonar.python.xunit.reportPath=testing/test-results.xml
2322
# enable maximum verbosity for diagnostic
2423
sonar.verbose=true
2524
sonar.log.level=DEBUG

0 commit comments

Comments
 (0)