Skip to content

Commit 814667b

Browse files
committed
Enhance SonarQube workflow with additional analysis tools and improved report handling
Signed-off-by: DavidOsipov <[email protected]>
1 parent 8a2e2df commit 814667b

File tree

1 file changed

+63
-10
lines changed

1 file changed

+63
-10
lines changed

.github/workflows/sonarqube.yml

Lines changed: 63 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Analyze and SonarQube Scan
1+
name: 🛡️ Bastion Quality Gates
22

33
on:
44
push:
@@ -8,41 +8,67 @@ on:
88
workflow_dispatch:
99

1010
permissions:
11-
pull-requests: read # Allows SonarQube to decorate PRs with analysis results
11+
pull-requests: read
12+
security-events: write
1213

1314
jobs:
1415
Analyze:
1516
runs-on: ubuntu-latest
1617
strategy:
1718
matrix:
18-
tool: [bandit, ruff, mypy]
19+
tool: [bandit, ruff, mypy, flake8, pylint, codeql, snyk]
1920
steps:
2021
- name: Checkout code
2122
uses: actions/checkout@85e6279cec87321a52edac9c87bce653a07cf6c2
2223

2324
- name: Set up Python
25+
if: matrix.tool != 'codeql' && matrix.tool != 'snyk'
2426
uses: actions/setup-python@8d9ed9ac5c53483de85588cdf95a591a75ab9f55
2527
with:
2628
python-version: '3.13'
2729

2830
- name: Cache pip dependencies
31+
if: matrix.tool != 'codeql' && matrix.tool != 'snyk'
2932
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684
3033
with:
31-
path: /usr/local/lib/python3.12/site-packages
34+
path: /usr/local/lib/python3.13/site-packages
3235
key: pip-${{ hashFiles('pyproject.toml') }}
3336
restore-keys: |
3437
pip-
3538
3639
- name: Install project dependencies
40+
if: matrix.tool != 'codeql' && matrix.tool != 'snyk'
3741
run: |
3842
pip install .
3943
pip install .[dev]
4044
4145
- name: Install analysis tools
46+
if: matrix.tool != 'codeql' && matrix.tool != 'snyk'
4247
run: |
43-
pip install bandit ruff mypy
44-
ruff --version # For debugging
45-
mypy --version # For debugging
48+
pip install bandit ruff mypy flake8 pylint
49+
bandit --version
50+
ruff --version
51+
mypy --version
52+
flake8 --version
53+
pylint --version
54+
55+
- name: Set up Node.js for Snyk
56+
if: matrix.tool == 'snyk'
57+
uses: actions/setup-node@v3
58+
with:
59+
node-version: '16'
60+
61+
- name: Setup Snyk CLI
62+
if: matrix.tool == 'snyk'
63+
uses: snyk/actions/setup@cdb760004ba9ea4d525f2e043745dfe85bb9077e
64+
with:
65+
snyk-version: latest
66+
67+
- name: Run Snyk Security Scan
68+
if: matrix.tool == 'snyk'
69+
run: snyk test --all-projects --sarif-file-output=snyk_report.sarif
70+
env:
71+
SNYK_TOKEN: ${{ secrets.SNYK_SECRET_TOKEN }}
4672

4773
- name: Run Bandit
4874
if: matrix.tool == 'bandit'
@@ -54,7 +80,27 @@ jobs:
5480

5581
- name: Run Mypy
5682
if: matrix.tool == 'mypy'
57-
run: mypy . 2>&1 | tee mypy_report.txt || true # Capture output to file and console, continue on error
83+
run: mypy . 2>&1 | tee mypy_report.txt || true
84+
85+
- name: Run Flake8
86+
if: matrix.tool == 'flake8'
87+
run: flake8 . --output-file flake8_report.txt --format=pylint || true
88+
89+
- name: Run Pylint
90+
if: matrix.tool == 'pylint'
91+
run: pylint --recursive=y . --output-format=json > pylint_report.json || true
92+
93+
- name: Initialize CodeQL
94+
if: matrix.tool == 'codeql'
95+
uses: github/codeql-action/init@main
96+
with:
97+
languages: python
98+
99+
- name: Perform CodeQL Analysis
100+
if: matrix.tool == 'codeql'
101+
uses: github/codeql-action/analyze@main
102+
with:
103+
output: codeql_report.sarif
58104

59105
- name: Upload report artifact
60106
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
@@ -69,7 +115,7 @@ jobs:
69115
- name: Checkout code
70116
uses: actions/checkout@85e6279cec87321a52edac9c87bce653a07cf6c2
71117
with:
72-
fetch-depth: 0 # Fetch full Git history for SonarQube
118+
fetch-depth: 0
73119

74120
- name: Download analysis reports
75121
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e
@@ -81,10 +127,14 @@ jobs:
81127
mv reports/bandit-report/bandit_report.json .
82128
mv reports/ruff-report/ruff_report.json .
83129
mv reports/mypy-report/mypy_report.txt .
130+
mv reports/flake8-report/flake8_report.txt .
131+
mv reports/pylint-report/pylint_report.json .
132+
mv reports/codeql-report/codeql_report.sarif .
133+
mv reports/snyk-report/snyk_report.sarif .
84134
85135
- name: Check if reports exist
86136
run: |
87-
for report in bandit_report.json ruff_report.json mypy_report.txt; do
137+
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
88138
if [ ! -f "$report" ]; then
89139
echo "$report not found. Exiting."
90140
exit 1
@@ -104,5 +154,8 @@ jobs:
104154
-Dsonar.python.bandit.reportPaths=bandit_report.json
105155
-Dsonar.python.ruff.reportPaths=ruff_report.json
106156
-Dsonar.python.mypy.reportPaths=mypy_report.txt
157+
-Dsonar.python.flake8.reportPaths=flake8_report.txt
158+
-Dsonar.python.pylint.reportPaths=pylint_report.json
159+
-Dsonar.sarifReportPaths=codeql_report.sarif,snyk_report.sarif
107160
-Dsonar.python.version=3.10-3.13
108161
-Dsonar.languages=python

0 commit comments

Comments
 (0)