-
Notifications
You must be signed in to change notification settings - Fork 34
167 lines (143 loc) · 5.55 KB
/
analyzers.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
name: Analyzers
on:
push:
paths:
- '.github/workflows/analyzers.yml'
- 'CMakeLists.txt'
- 'src/**'
- 'test/**'
- 'modules/**'
- '3rdparty/**'
- '**.imp'
pull_request:
paths:
- '.github/workflows/analyzers.yml'
- 'CMakeLists.txt'
- 'src/**'
- 'test/**'
- 'modules/**'
- '3rdparty/**'
- '**.imp'
release:
types: published
jobs:
analyze-linux:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
tool: [clang-analyzer, iwyu, CodeQL]
config: [Release, Debug]
permissions:
# required for all codeql to report detected outcomes
security-events: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
submodules: recursive
- name: Hack to fix github runner
run: |
# Hack to deal with https://github.com/actions/runner-images/issues/8659
sudo rm -f /etc/apt/sources.list.d/ubuntu-toolchain-r-ubuntu-test-jammy.list
sudo apt-get update
sudo apt-get install -y --allow-downgrades libstdc++-12-dev libstdc++6=12.* libgcc-s1=12.*
- name: Install dependencies
run: |
sudo apt-get update
sudo apt install -y libglfw3-dev libopenal-dev libglvnd-core-dev iwyu clang clang-tidy clang-tools ninja-build
# TODO: Really, this should only be fetching the build dependencies, so we can only use the in-tree version
sudo apt install -y libsdl2-dev
- name: Configure
run: |
cmake -G Ninja -B build -DCMAKE_BUILD_TYPE=${{ matrix.config }}
# Compile deps before initializing codeql, to avoid unnecessary analysis.
# and for iwyu and clang-analayzer, SDL2 apparently generates some code at build time, which breaks the analyzers if we don't compile
- name: Compile Dependencies
run: |
cmake --build build --parallel --config ${{ matrix.config }} --target compile-osp-magnum-deps compile-test-deps
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
if: ${{ matrix.tool == 'CodeQL' }}
with:
languages: cpp
- name: Reconfigure for CodeQL
if: ${{ matrix.tool == 'CodeQL' }}
run: |
cmake -G Ninja -B build -DCMAKE_BUILD_TYPE=${{ matrix.config }}
- name: Compile for CodeQL
if: ${{ matrix.tool == 'CodeQL' }}
run: |
cmake --build build --parallel --target osp-magnum compile-tests
# Unlike clang-analyzer and include-what-you-use, CodeQL can't operate on just the config step. Need to actually build everything.
- name: Perform CodeQL Analysis
if: ${{ matrix.tool == 'CodeQL' }}
uses: github/codeql-action/analyze@v2
with:
upload: false
output: sarif-results
- name: Filter 3rdparty from CodeQL
if: ${{ matrix.tool == 'CodeQL' }}
uses: advanced-security/filter-sarif@v1
with:
# filter out all test files unless they contain a sql-injection vulnerability
patterns: |
-3rdparty/**
input: sarif-results/cpp.sarif
output: sarif-results/cpp.sarif
- name: Upload SARIF
if: ${{ matrix.tool == 'CodeQL' }}
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: sarif-results/cpp.sarif
# Implicitly requires build/compile_commands.json to exist
- name: Run Clang Analyzer
if: ${{ matrix.tool == 'clang-analyzer' }}
run: |
wget https://raw.githubusercontent.com/llvm/llvm-project/llvmorg-14.0.6/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
chmod +x run-clang-tidy.py
./run-clang-tidy.py -j $(nproc) -p build
# Implicitly requires build/compile_commands.json to exist
- name: Run IWYU
if: ${{ matrix.tool == 'iwyu' }}
run: |
wget https://raw.githubusercontent.com/include-what-you-use/include-what-you-use/clang_14/iwyu_tool.py
chmod +x iwyu_tool.py
# iwyu_tool.py returns non-zero if any executions returned nonzero. Which... happens to be useless unless the project is already IWYU clean.
./iwyu_tool.py -j $(nproc) -p build -- -Xiwyu --mapping_file=${GITHUB_WORKSPACE}/iwyu-ubuntu.imp || exit 0
analyze-windows:
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
tool: [msvc-code-analysis]
config: [Release, Debug]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
submodules: recursive
- name: Configure (MSVC)
run: |
cmake -B build -DCMAKE_CONFIGURATION_TYPES=${{ matrix.config }}
# Compile deps before initializing codeql, to avoid unnecessary analysis.
# and for iwyu and clang-analayzer, SDL2 apparently generates some code at build time, which breaks the analyzers if we don't compile
- name: Compile Dependencies
run: |
cmake --build build --parallel --config ${{ matrix.config }} --target compile-osp-magnum-deps compile-test-deps
- name: Initialize MSVC Code Analysis
uses: microsoft/[email protected]
# Provide a unique ID to access the sarif output path
id: run-analysis
with:
cmakeBuildDirectory: build
buildConfiguration: ${{ matrix.config }}
# Ruleset file that will determine what checks will be run
ruleset: NativeRecommendedRules.ruleset
ignoredPaths: 3rdparty
ignoredIncludePaths: 3rdparty
# Upload SARIF file to GitHub Code Scanning Alerts
- name: Upload SARIF to GitHub
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: ${{ steps.run-analysis.outputs.sarif }}