@@ -69,22 +69,36 @@ jobs:
6969 with :
7070 fetch-depth : 0 # Disable shallow clone for better analysis
7171
72+ - name : Check for Python code
73+ id : check-code
74+ run : |
75+ if find src -name '*.py' -type f 2>/dev/null | grep -q .; then
76+ echo "has-code=true" >> $GITHUB_OUTPUT
77+ else
78+ echo "has-code=false" >> $GITHUB_OUTPUT
79+ echo "ℹ️ No Python source files found. Skipping SonarCloud analysis." >> $GITHUB_STEP_SUMMARY
80+ fi
81+
7282 - name : Set up Python
83+ if : steps.check-code.outputs.has-code == 'true'
7384 uses : actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
7485 with :
7586 python-version : ' {{ cookiecutter.python_version }}'
7687 cache : ' pip'
7788
7889 - name : Install UV
90+ if : steps.check-code.outputs.has-code == 'true'
7991 run : |
8092 curl -LsSf https://astral.sh/uv/install.sh | sh
8193 echo "$HOME/.cargo/bin" >> $GITHUB_PATH
8294
8395 - name : Install dependencies
96+ if : steps.check-code.outputs.has-code == 'true'
8497 run : |
8598 uv sync --frozen --all-extras
8699
87100 - name : Run tests with coverage
101+ if : steps.check-code.outputs.has-code == 'true'
88102 run : |
89103 # Generate coverage in Cobertura XML format for SonarCloud
90104 uv run pytest \
96110 continue-on-error : true # Don't fail on test failures; let SonarCloud report them
97111
98112 - name : Verify coverage report
113+ if : steps.check-code.outputs.has-code == 'true'
99114 run : |
100115 if [ ! -f coverage.xml ]; then
101116 echo "::warning::Coverage report not found. Tests may have failed."
@@ -107,6 +122,7 @@ jobs:
107122 fi
108123
109124 - name : SonarCloud Scan
125+ if : steps.check-code.outputs.has-code == 'true'
110126 uses : SonarSource/sonarqube-scan-action@884b79409bbd464b2a59edc326a4b77dc56b2195 # v4.0.0
111127 env :
112128 GITHUB_TOKEN : {% raw %}${{ secrets.GITHUB_TOKEN }}{% endraw %} # Needed for PR decoration
0 commit comments