1
- name : Analyze and SonarQube Scan
1
+ name : 🛡️ Bastion Quality Gates
2
2
3
3
on :
4
4
push :
8
8
workflow_dispatch :
9
9
10
10
permissions :
11
- pull-requests : read # Allows SonarQube to decorate PRs with analysis results
11
+ pull-requests : read
12
+ security-events : write
12
13
13
14
jobs :
14
15
Analyze :
15
16
runs-on : ubuntu-latest
16
17
strategy :
17
18
matrix :
18
- tool : [bandit, ruff, mypy]
19
+ tool : [bandit, ruff, mypy, flake8, pylint, codeql, snyk ]
19
20
steps :
20
21
- name : Checkout code
21
22
uses : actions/checkout@85e6279cec87321a52edac9c87bce653a07cf6c2
22
23
23
24
- name : Set up Python
25
+ if : matrix.tool != 'codeql' && matrix.tool != 'snyk'
24
26
uses : actions/setup-python@8d9ed9ac5c53483de85588cdf95a591a75ab9f55
25
27
with :
26
28
python-version : ' 3.13'
27
29
28
30
- name : Cache pip dependencies
31
+ if : matrix.tool != 'codeql' && matrix.tool != 'snyk'
29
32
uses : actions/cache@5a3ec84eff668545956fd18022155c47e93e2684
30
33
with :
31
- path : /usr/local/lib/python3.12 /site-packages
34
+ path : /usr/local/lib/python3.13 /site-packages
32
35
key : pip-${{ hashFiles('pyproject.toml') }}
33
36
restore-keys : |
34
37
pip-
35
38
36
39
- name : Install project dependencies
40
+ if : matrix.tool != 'codeql' && matrix.tool != 'snyk'
37
41
run : |
38
42
pip install .
39
43
pip install .[dev]
40
44
41
45
- name : Install analysis tools
46
+ if : matrix.tool != 'codeql' && matrix.tool != 'snyk'
42
47
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 }}
46
72
47
73
- name : Run Bandit
48
74
if : matrix.tool == 'bandit'
54
80
55
81
- name : Run Mypy
56
82
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
58
104
59
105
- name : Upload report artifact
60
106
uses : actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
69
115
- name : Checkout code
70
116
uses : actions/checkout@85e6279cec87321a52edac9c87bce653a07cf6c2
71
117
with :
72
- fetch-depth : 0 # Fetch full Git history for SonarQube
118
+ fetch-depth : 0
73
119
74
120
- name : Download analysis reports
75
121
uses : actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e
@@ -81,10 +127,14 @@ jobs:
81
127
mv reports/bandit-report/bandit_report.json .
82
128
mv reports/ruff-report/ruff_report.json .
83
129
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 .
84
134
85
135
- name : Check if reports exist
86
136
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
88
138
if [ ! -f "$report" ]; then
89
139
echo "$report not found. Exiting."
90
140
exit 1
@@ -104,5 +154,8 @@ jobs:
104
154
-Dsonar.python.bandit.reportPaths=bandit_report.json
105
155
-Dsonar.python.ruff.reportPaths=ruff_report.json
106
156
-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
107
160
-Dsonar.python.version=3.10-3.13
108
161
-Dsonar.languages=python
0 commit comments