-
Notifications
You must be signed in to change notification settings - Fork 0
504 lines (405 loc) · 14.9 KB
/
StaticAnalysis.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
name: StaticAnalysis
on:
push:
paths:
# Workflow file itself
- '.github/workflows/StaticAnalysis.yml'
# C++ files
- '**.cpp'
- '**.hpp'
# CMake files
- '**.cmake'
- '**.txt'
# Script files
- '**.sh'
# dotfiles
- '.clang-tidy'
- '.cmake-format.yaml'
branches-ignore:
- 'dependabot/**'
pull_request:
branches:
- main
- develop
release:
types: [published]
workflow_dispatch:
schedule:
- cron: '0 4 * * 1'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
CMAKE_C_COMPILER_LAUNCHER: "ccache"
CMAKE_CXX_COMPILER_LAUNCHER: "ccache"
jobs:
cppcheck:
runs-on: ubuntu-24.04
env:
LLVM_VERSION: 19
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 2
- uses: reviewdog/action-setup@v1
with:
reviewdog_version: latest
- name: Install dependencies
run: sudo scripts/ci/InstallDependencies.sh
- name: Install
env:
CPPCHECK_VERSION: "2.16.0"
run: external/Phi/scripts/ci/InstallTools.sh clang-${{ env.LLVM_VERSION }} cppcheck-${{ env.CPPCHECK_VERSION }} ninja
- name: Configure
run: |
# Create build directory
mkdir build -p
cd build
# Generate compile_commands.json
cmake .. -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=ON
# Build glad target since it generates required files
cmake --build . --target glad
- name: Run cppcheck
run: |
# Create build directory
mkdir -p build-cppcheck
cppcheck --project=build/compile_commands.json --enable=all --inconclusive --inline-suppr --template='{file}:{line}:{column}: {severity}: {message} [{id}](CWE {cwe})' -DPHI_CONFIG_ALWAYS_INLINE_OVERWRITE=inline -DPHI_CONFIG_NEVER_INLINE_OVERWRITE="" --cppcheck-build-dir="build-cppcheck" -i external --suppress=missingInclude --suppress=unusedFunction --suppress=unmatchedSuppression --suppress=missingIncludeSystem --suppress=unknownMacro -UDLXEMU_COVERAGE_BUILD 2> cppcheck.log
# Filter out external libraries and test code
cat cppcheck.log | grep -Ev "external/|tests/" > cppcheck_filtered.log || true
- name: Print results
run: cat cppcheck_filtered.log
- name: Determine reporter
uses: haya14busa/action-cond@v1
id: reporter
with:
cond: ${{ github.event_name == 'pull_request' }}
if_true: 'github-pr-check'
if_false: 'github-check'
- name: ReviewDog check
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
cat cppcheck_filtered.log | reviewdog -efm="%f:%l:%c: %m" -diff="git diff HEAD~1" -reporter=${{ steps.reporter.outputs.value }} -name CppCheck -level warning
clang-tidy:
runs-on: ubuntu-24.04
env:
LLVM_VERSION: 19
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 2
- uses: reviewdog/action-setup@v1
with:
reviewdog_version: latest
- name: Install dependencies
run: sudo scripts/ci/InstallDependencies.sh
- name: Install
run: external/Phi/scripts/ci/InstallTools.sh clang-${{ env.LLVM_VERSION }} clang-tidy-${{ env.LLVM_VERSION }} ninja
- name: Run clang-tidy
run: |
# Create build directory
mkdir build -p
cd build
# Generate compile_commands.json
cmake .. -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=ON
# Build glad so it generates the required files
cmake --build . --target glad --clean-first
# Run clang-tidy
run-clang-tidy-${{ env.LLVM_VERSION }} -quiet -header-filter "*" -j $(nproc) | tee clang_tidy.log
# Filter to only include warnings
cat clang_tidy.log | grep "warning:" > clang_tidy_warnings.log
# Filter out external libraries and test code
cat clang_tidy_warnings.log | grep -Ev "DLXEmu/external|DLXEmu/tests|\[clang-diagnostic-ignored-optimization-argument\]" > clang_tidy_filtered.log || true
# Remove duplicate entries
sort clang_tidy_filtered.log | uniq -d > clang_tidy_output.log
- name: Print results
run: cat build/clang_tidy_output.log
- name: Determine reporter
uses: haya14busa/action-cond@v1
id: reporter
with:
cond: ${{ github.event_name == 'pull_request' }}
if_true: 'github-pr-check'
if_false: 'github-check'
- name: ReviewDog check
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
cat build/clang_tidy_output.log | reviewdog -efm="%f:%l:%c: warning: %m" -diff="git diff HEAD~1" -reporter=${{ steps.reporter.outputs.value }} -name Clang-Tidy -level warning
include-what-you-use:
runs-on: ubuntu-24.04
env:
LLVM_VERSION: 19
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 2
- name: Setup Reviewdog
uses: reviewdog/action-setup@v1
with:
reviewdog_version: latest
- name: Install
run: external/Phi/scripts/ci/InstallTools.sh iwyu-${{ env.LLVM_VERSION }} ninja
- name: Install dependencies
run: sudo scripts/ci/InstallDependencies.sh
- name: Run Include-What-You-Use
run: |
# Create build directory
mkdir build -p
cd build
# Configure
cmake .. -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=ON
# Run include-what-you-use
iwyu_tool.py --output-format clang --jobs $(nproc) -p . ../DLXEmu ../DLXLib -- -Xiwyu --cxx17ns | tee iwyu.log || true
# Filter out correct includes and generated code
cat iwyu.log | grep -Ev "#includes/fwd-decls are correct" | tee iwyu_filtered.log || true
- name: Print results
run: cat build/iwyu_filtered.log
- name: Determine reporter
uses: haya14busa/action-cond@v1
id: reporter
with:
cond: ${{ github.event_name == 'pull_request' }}
if_true: 'github-pr-check'
if_false: 'github-check'
- name: ReviewDog check
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
cat build/iwyu_filtered.log | reviewdog -efm="%Z%A%f:%l:%c: error: %m" -efm="%C%m" -diff="git diff HEAD~1" -reporter=${{ steps.reporter.outputs.value }} -name include-what-you-use -level warning
cmake-lint:
runs-on: ubuntu-24.04
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
- name: Setup Reviewdog
uses: reviewdog/action-setup@v1
with:
reviewdog_version: latest
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install
run: external/Phi/scripts/ci/InstallTools.sh cmake-format
- name: Run cmake-lint
run: cmake-lint $(find -iregex "./.*\.cmake" -or -iregex "./.*\CMakeLists\.txt") -c ".cmake-format.yaml" --suppress-decorations --outfile-path cmake_lint.log || true
- name: Print results
run: cat cmake_lint.log
- name: Determine reporter
uses: haya14busa/action-cond@v1
id: reporter
with:
cond: ${{ github.event_name == 'pull_request' }}
if_true: 'github-pr-check'
if_false: 'github-check'
- name: ReviewDog check
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
cat cmake_lint.log | reviewdog -efm="%f:%l: %m" -diff="git diff HEAD~1" -reporter=${{ steps.reporter.outputs.value }} -name cmake-lint -level warning
code-ql:
runs-on: ubuntu-24.04
permissions:
actions: read
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
language: [ 'cpp' ]
compiler:
- 'gcc-14'
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive
- name: Setup ccache
uses: hendrikmuhs/ccache-action@v1
with:
key: ${{ runner.os }}-${{ matrix.compiler }}
- name: Setup Environment
run: external/Phi/scripts/ci/SetupEnvironment.sh
- name: Install compiler
run: external/Phi/scripts/ci/InstallTools.sh ${{ matrix.compiler }} ninja
- name: Install dependencies
run: sudo scripts/ci/InstallDependencies.sh
- name: Configure build directory
run: |
mkdir build -p
cd build
cmake -DCMAKE_AR=$AR_EXECUTABLE -DCMAKE_BUILD_TYPE:STRING=Debug ..
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
# Override language selection by uncommenting this and choosing your languages
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main
- name: Build
working-directory: ./build
run: cmake --build . --config Debug
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
upload: False
output: sarif-results
- name: filter-sarif
uses: advanced-security/filter-sarif@main
with:
patterns: -**/external/** # Ignore external directory
input: sarif-results/${{ matrix.language }}.sarif
output: sarif-results/${{ matrix.language }}.sarif
- name: Upload SARIF
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: sarif-results/${{ matrix.language }}.sarif
msvc-code-analysis:
permissions:
contents: read # for actions/checkout to fetch code
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
runs-on: windows-latest
# Default windows to use bash
defaults:
run:
shell: bash
strategy:
fail-fast: false
matrix:
build_type:
- 'RelWithDebInfo'
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: '3.x'
cache: 'pip'
- name: Install dependencies
run: pip install jinja2
- name: Configure
run: |
# Create build directory
mkdir build -p
cd build
# Configure
cmake .. -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=ON
- name: Build
working-directory: ./build
run: cmake --build .
- name: Initialize MSVC Code Analysis
uses: microsoft/msvc-code-analysis-action@v0.1.1
# Provide a unique ID to access the sarif output path
id: run-analysis
with:
cmakeBuildDirectory: '${{ github.workspace }}/build'
buildConfiguration: ${{ matrix.build_type }}
# Ruleset file that will determine what checks will be run
ruleset: NativeRecommendedRules.ruleset
- name: filter-sarif
uses: advanced-security/filter-sarif@main
with:
patterns: -**/external/** # Ignore external directory
input: ${{ steps.run-analysis.outputs.sarif }}
output: ${{ steps.run-analysis.outputs.sarif }}
# Upload SARIF file to GitHub Code Scanning Alerts
- name: Upload SARIF to GitHub
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: ${{ steps.run-analysis.outputs.sarif }}
# Upload SARIF file as an Artifact to download and view
- name: Upload SARIF as an Artifact
uses: actions/upload-artifact@v4
with:
name: sarif-file
path: ${{ steps.run-analysis.outputs.sarif }}
dev-skim:
name: DevSkim
runs-on: ubuntu-24.04
permissions:
actions: read
contents: read
security-events: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Run DevSkim scanner
uses: microsoft/DevSkim-Action@v1
- name: Upload DevSkim scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: devskim-results.sarif
codacy-security-scan:
permissions:
contents: read # for actions/checkout to fetch code
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
name: Codacy Security Scan
runs-on: ubuntu-24.04
steps:
# Checkout the repository to the GitHub Actions runner
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: recursive
# Execute Codacy Analysis CLI and generate a SARIF output with the security issues identified during the analysis
- name: Run Codacy Analysis CLI
uses: codacy/codacy-analysis-cli-action@v4
with:
verbose: true
output: results.sarif
format: sarif
# Adjust severity of non-security issues
gh-code-scanning-compat: true
# Force 0 exit code to allow SARIF file generation
# This will handover control about PR rejection to the GitHub side
max-allowed-issues: 2147483647
- name: filter-sarif
uses: advanced-security/filter-sarif@main
with:
patterns: -**/external/** # Ignore external directory
input: results.sarif
output: results-filtered.sarif
# Upload the SARIF file generated in the previous step
- name: Upload SARIF results file
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: results-filtered.sarif
shellcheck:
name: ShellCheck
runs-on: ubuntu-24.04
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
- name: Determine reporter
uses: haya14busa/action-cond@v1
id: reporter
with:
cond: ${{ github.event_name == 'pull_request' }}
if_true: 'github-pr-check'
if_false: 'github-check'
- name: Run shellcheck with reviewdog
uses: reviewdog/action-shellcheck@v1
with:
github_token: ${{ secrets.github_token }}
reporter: ${{ steps.reporter.outputs.value }}
level: warning
path: "./scripts"
pattern: "*.sh"
exclude: "./.git/*"