Skip to content

Commit 0242c00

Browse files
committed
Enhance SonarQube workflow by installing analysis tools via Poetry, adding version checks, and improving report handling
Signed-off-by: DavidOsipov <[email protected]>
1 parent 8252f24 commit 0242c00

File tree

1 file changed

+72
-4
lines changed

1 file changed

+72
-4
lines changed

.github/workflows/sonarqube.yml

Lines changed: 72 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,26 @@ jobs:
3838
restore-keys: |
3939
pip-poetry-
4040
41-
- name: Install project dependencies
41+
- name: Install Poetry
4242
if: matrix.tool != 'codeql'
4343
run: |
4444
pip install poetry
45+
poetry --version
46+
47+
- name: Install project dependencies
48+
if: matrix.tool != 'codeql'
49+
run: |
4550
poetry install --with dev --no-interaction
4651
4752
- name: Install analysis tools
4853
if: matrix.tool != 'codeql' && matrix.tool != 'snyk'
4954
run: |
50-
pip install bandit ruff mypy flake8 pylint
55+
poetry run pip install bandit ruff mypy flake8 pylint
56+
poetry run bandit --version
57+
poetry run ruff --version
58+
poetry run mypy --version
59+
poetry run flake8 --version
60+
poetry run pylint --version
5161
5262
- name: Setup Snyk CLI
5363
if: matrix.tool == 'snyk'
@@ -67,7 +77,37 @@ jobs:
6777
--strict-out-of-sync=false \
6878
--sarif-file-output=snyk_report.sarif
6979
70-
# ... [keep other tool steps unchanged] ...
80+
- name: Run Bandit
81+
if: matrix.tool == 'bandit'
82+
run: poetry run bandit -r . -o bandit_report.json --format json --exclude tests,.git || true
83+
84+
- name: Run Ruff
85+
if: matrix.tool == 'ruff'
86+
run: poetry run ruff check . --output-format json --output-file ruff_report.json --exclude tests,.git || true
87+
88+
- name: Run Mypy
89+
if: matrix.tool == 'mypy'
90+
run: poetry run mypy . 2>&1 | tee mypy_report.txt || true
91+
92+
- name: Run Flake8
93+
if: matrix.tool == 'flake8'
94+
run: poetry run flake8 . --output-file flake8_report.txt --format=pylint || true
95+
96+
- name: Run Pylint
97+
if: matrix.tool == 'pylint'
98+
run: poetry run pylint --recursive=y . --output-format=json > pylint_report.json || true
99+
100+
- name: Initialize CodeQL
101+
if: matrix.tool == 'codeql'
102+
uses: github/codeql-action/init@main
103+
with:
104+
languages: python
105+
106+
- name: Perform CodeQL Analysis
107+
if: matrix.tool == 'codeql'
108+
uses: github/codeql-action/analyze@main
109+
with:
110+
output: codeql_report.sarif
71111

72112
- name: Upload report artifact
73113
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
@@ -79,7 +119,35 @@ jobs:
79119
needs: Analyze
80120
runs-on: ubuntu-latest
81121
steps:
82-
# ... [keep existing SonarQube steps] ...
122+
- name: Checkout code
123+
uses: actions/checkout@85e6279cec87321a52edac9c87bce653a07cf6c2
124+
with:
125+
fetch-depth: 0
126+
127+
- name: Download analysis reports
128+
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e
129+
with:
130+
path: reports
131+
132+
- name: Move reports to working directory
133+
run: |
134+
mv reports/bandit-report/bandit_report.json .
135+
mv reports/ruff-report/ruff_report.json .
136+
mv reports/mypy-report/mypy_report.txt .
137+
mv reports/flake8-report/flake8_report.txt .
138+
mv reports/pylint-report/pylint_report.json .
139+
mv reports/codeql-report/codeql_report.sarif .
140+
mv reports/snyk-report/snyk_report.sarif .
141+
142+
- name: Check if reports exist
143+
run: |
144+
for report in bandit_report.json ruff_report.json mypy_report.txt flake8_report.txt pylint_report.json codeql_report.sarif snyk_report.sarif; do
145+
if [ ! -f "$report" ]; then
146+
echo "$report not found. Exiting."
147+
exit 1
148+
fi
149+
done
150+
83151
- name: Analyze with SonarQube
84152
uses: SonarSource/sonarqube-scan-action@aa494459d7c39c106cc77b166de8b4250a32bb97
85153
env:

0 commit comments

Comments
 (0)