Skip to content

Commit df8bb05

Browse files
committed
Enhances CI caching and report processing
Updates caching keys to include lock files and renames test job dependency Improves report handling by safely moving files with fallback defaults and aggregating SARIF reports Signed-off-by: DavidOsipov <[email protected]>
1 parent 9270de2 commit df8bb05

File tree

2 files changed

+106
-33
lines changed

2 files changed

+106
-33
lines changed

.github/workflows/python-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
path: |
4242
~/.cache/pip
4343
~/.cache/pypoetry
44-
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }}
44+
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock', 'pyproject.toml') }}
4545
restore-keys: |
4646
${{ runner.os }}-pip-${{ matrix.python-version }}-
4747

.github/workflows/sonarqube.yml

Lines changed: 105 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ permissions:
1616
contents: read
1717

1818
jobs:
19-
test:
19+
Python_Tests:
2020
uses: ./.github/workflows/python-tests.yml
2121
# This workflow now depends on the successful completion of the python-tests workflow
2222
Analyze:
23-
needs: test
23+
needs: Python_Tests
2424
runs-on: ubuntu-latest
2525
strategy:
2626
matrix:
@@ -40,11 +40,13 @@ jobs:
4040
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684
4141
with:
4242
path: |
43-
/usr/local/lib/python3.13/site-packages
43+
~/.cache/pip
4444
~/.cache/pypoetry
45-
key: pip-poetry-${{ hashFiles('pyproject.toml') }}
45+
/usr/local/lib/python3.13/site-packages
46+
key: ${{ runner.os }}-poetry-${{ matrix.tool }}-${{ hashFiles('**/poetry.lock', 'pyproject.toml') }}
4647
restore-keys: |
47-
pip-poetry-
48+
${{ runner.os }}-poetry-${{ matrix.tool }}-
49+
${{ runner.os }}-poetry-
4850
4951
- name: Install Poetry
5052
if: matrix.tool != 'codeql'
@@ -164,26 +166,104 @@ jobs:
164166
with:
165167
path: reports
166168

167-
- name: Move reports to working directory
169+
- name: Process reports and prepare for SonarQube
168170
run: |
169-
mv reports/bandit-report/bandit_report.json .
170-
mv reports/ruff-report/ruff_report.json .
171-
mv reports/mypy-report/mypy_report.txt .
172-
mv reports/flake8-report/flake8_report.txt .
173-
mv reports/pylint-report/pylint_report.json .
174-
mv reports/codeql-report/codeql_report.sarif .
175-
mv reports/snyk-report/snyk_report.sarif .
176-
mv reports/pyright-report/pyright_report.json .
177-
mv reports/cyclonedx-report/cyclonedx_report.json .
178-
179-
- name: Check if reports exist
180-
run: |
181-
for report in bandit_report.json ruff_report.json mypy_report.txt flake8_report.txt pylint_report.json codeql_report.sarif snyk_report.sarif pyright_report.json cyclonedx_report.json; do
182-
if [ ! -f "$report" ]; then
183-
echo "$report not found. Exiting."
184-
exit 1
171+
mkdir -p processed_reports
172+
173+
# Function to safely move reports
174+
safe_move_report() {
175+
local source_dir="$1"
176+
local report_file="$2"
177+
local target_file="$3"
178+
179+
if [ -f "${source_dir}/${report_file}" ]; then
180+
echo "✅ Found ${report_file}"
181+
cp "${source_dir}/${report_file}" "${target_file}"
182+
return 0
183+
else
184+
echo "⚠️ Warning: ${report_file} not found in ${source_dir}"
185+
# For JSON reports, create an empty valid JSON file
186+
if [[ "${report_file}" == *".json" ]]; then
187+
echo "Creating empty JSON file for ${target_file}"
188+
echo "[]" > "${target_file}"
189+
# For SARIF reports, create a minimal valid SARIF file
190+
elif [[ "${report_file}" == *".sarif" ]]; then
191+
echo "Creating minimal SARIF file for ${target_file}"
192+
echo '{"version":"2.1.0","runs":[{"tool":{"driver":{"name":"Missing Report","rules":[]}},"results":[]}]}' > "${target_file}"
193+
# For text reports, create an empty file
194+
else
195+
echo "Creating empty file for ${target_file}"
196+
touch "${target_file}"
197+
fi
198+
return 1
199+
fi
200+
}
201+
202+
# Initialize list of available report paths for SonarQube
203+
sonar_args=""
204+
205+
# Process each report type
206+
safe_move_report "reports/bandit-report" "bandit_report.json" "processed_reports/bandit_report.json"
207+
if [ $? -eq 0 ]; then
208+
sonar_args="${sonar_args} -Dsonar.python.bandit.reportPaths=processed_reports/bandit_report.json"
209+
fi
210+
211+
safe_move_report "reports/ruff-report" "ruff_report.json" "processed_reports/ruff_report.json"
212+
if [ $? -eq 0 ]; then
213+
sonar_args="${sonar_args} -Dsonar.python.ruff.reportPaths=processed_reports/ruff_report.json"
214+
fi
215+
216+
safe_move_report "reports/mypy-report" "mypy_report.txt" "processed_reports/mypy_report.txt"
217+
if [ $? -eq 0 ]; then
218+
sonar_args="${sonar_args} -Dsonar.python.mypy.reportPaths=processed_reports/mypy_report.txt"
219+
fi
220+
221+
safe_move_report "reports/flake8-report" "flake8_report.txt" "processed_reports/flake8_report.txt"
222+
if [ $? -eq 0 ]; then
223+
sonar_args="${sonar_args} -Dsonar.python.flake8.reportPaths=processed_reports/flake8_report.txt"
224+
fi
225+
226+
safe_move_report "reports/pylint-report" "pylint_report.json" "processed_reports/pylint_report.json"
227+
if [ $? -eq 0 ]; then
228+
sonar_args="${sonar_args} -Dsonar.python.pylint.reportPaths=processed_reports/pylint_report.json"
229+
fi
230+
231+
# Process SARIF reports and combine into a single list if both exist
232+
sarif_reports=""
233+
safe_move_report "reports/codeql-report" "codeql_report.sarif" "processed_reports/codeql_report.sarif"
234+
if [ $? -eq 0 ]; then
235+
sarif_reports="processed_reports/codeql_report.sarif"
236+
fi
237+
238+
safe_move_report "reports/snyk-report" "snyk_report.sarif" "processed_reports/snyk_report.sarif"
239+
if [ $? -eq 0 ]; then
240+
if [ -n "$sarif_reports" ]; then
241+
sarif_reports="${sarif_reports},processed_reports/snyk_report.sarif"
242+
else
243+
sarif_reports="processed_reports/snyk_report.sarif"
185244
fi
186-
done
245+
fi
246+
247+
if [ -n "$sarif_reports" ]; then
248+
sonar_args="${sonar_args} -Dsonar.sarifReportPaths=${sarif_reports}"
249+
fi
250+
251+
safe_move_report "reports/pyright-report" "pyright_report.json" "processed_reports/pyright_report.json"
252+
if [ $? -eq 0 ]; then
253+
sonar_args="${sonar_args} -Dsonar.externalIssuesReportPaths=processed_reports/pyright_report.json"
254+
fi
255+
256+
safe_move_report "reports/cyclonedx-report" "cyclonedx_report.json" "processed_reports/cyclonedx_report.json"
257+
if [ $? -eq 0 ]; then
258+
sonar_args="${sonar_args} -Dsonar.dependencyCheck.jsonReportPath=processed_reports/cyclonedx_report.json"
259+
fi
260+
261+
# Store SonarQube args in environment variable for next step
262+
echo "SONAR_EXTRA_ARGS=${sonar_args}" >> $GITHUB_ENV
263+
264+
# Print summary
265+
echo "✨ Report processing complete. SonarQube will use the following reports:"
266+
echo "${sonar_args}"
187267
188268
- name: Analyze with SonarQube
189269
uses: SonarSource/sonarqube-scan-action@aa494459d7c39c106cc77b166de8b4250a32bb97
@@ -195,13 +275,6 @@ jobs:
195275
args: >
196276
-Dsonar.projectKey=DavidOsipov_PostQuantum-Feldman-VSS
197277
-Dsonar.organization=davidosipov
198-
-Dsonar.python.bandit.reportPaths=bandit_report.json
199-
-Dsonar.python.ruff.reportPaths=ruff_report.json
200-
-Dsonar.python.mypy.reportPaths=mypy_report.txt
201-
-Dsonar.python.flake8.reportPaths=flake8_report.txt
202-
-Dsonar.python.pylint.reportPaths=pylint_report.json
203-
-Dsonar.sarifReportPaths=codeql_report.sarif,snyk_report.sarif
204-
-Dsonar.externalIssuesReportPaths=pyright_report.json
205-
-Dsonar.dependencyCheck.jsonReportPath=cyclonedx_report.json
206278
-Dsonar.python.version=3.10-3.13
207-
-Dsonar.languages=python
279+
-Dsonar.languages=python
280+
${{ env.SONAR_EXTRA_ARGS }}

0 commit comments

Comments
 (0)