Skip to content

Commit 95e9f1a

Browse files
Create code-analysis.yml
1 parent 90f55cc commit 95e9f1a

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

.github/workflows/code-analysis.yml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# This workflow performs code analysis using both CodeQL and Microsoft C++ Code Analysis.
2+
# It is triggered on pushes to the 'master' branch and publishes warnings into the security GitHub tab.
3+
# The workflow includes two jobs: one for CodeQL analysis on Ubuntu and another for MSVC Code Analysis on Windows.
4+
5+
name: Code Analysis
6+
7+
on:
8+
push:
9+
branches:
10+
- 'master'
11+
12+
permissions:
13+
contents: read
14+
security-events: write
15+
packages: read
16+
17+
env:
18+
# Path to the CMake build directory.
19+
build: '${{ github.workspace }}/build'
20+
config: 'Debug'
21+
22+
jobs:
23+
codeql-analyze:
24+
name: CodeQL Analyze (C/C++)
25+
runs-on: ubuntu-latest
26+
27+
steps:
28+
# Step: Checkout the repository
29+
- name: Checkout repository
30+
uses: actions/[email protected]
31+
32+
# Step: Install necessary dependencies for building the project
33+
- name: Install dependencies
34+
run: sudo apt-get update && sudo apt-get install -y tcl-dev tk-dev cmake gcc g++ make libbtbb-dev libx11-dev libglu1-mesa-dev
35+
36+
# Step: Initialize CodeQL for scanning
37+
- name: Initialize CodeQL
38+
uses: github/codeql-action/[email protected]
39+
with:
40+
languages: c-cpp
41+
build-mode: manual
42+
43+
# Step: Build the project using CMake and Make
44+
- name: Build project
45+
shell: bash
46+
run: |
47+
mkdir -p build
48+
cd build
49+
cmake -G "Unix Makefiles" \
50+
-D CMAKE_C_COMPILER=gcc \
51+
-D CMAKE_CXX_COMPILER=g++ \
52+
-D USE_FREETYPE=OFF \
53+
-D CMAKE_BUILD_TYPE=Release ..
54+
make -j$(nproc)
55+
56+
# Step: Perform CodeQL Analysis
57+
- name: Perform CodeQL Analysis
58+
uses: github/codeql-action/[email protected]
59+
with:
60+
category: "/language:c-cpp"
61+
62+
msvc-analyze:
63+
name: Microsoft C++ Code Analysis
64+
runs-on: windows-latest
65+
66+
steps:
67+
# Step: Checkout the repository
68+
- name: Checkout repository
69+
uses: actions/[email protected]
70+
71+
# Step: Install necessary dependencies using Chocolatey
72+
- name: Install dependencies
73+
run: |
74+
choco install cmake --installargs 'ADD_CMAKE_TO_PATH=System' -y
75+
choco install magicsplat-tcl-tk -y
76+
77+
# Step: Configure the project using CMake
78+
- name: Configure CMake
79+
run: |
80+
mkdir build
81+
cd build
82+
cmake -D USE_FREETYPE=OFF -DCMAKE_BUILD_TYPE=${{ env.config }} ..
83+
84+
# Step: Run MSVC Code Analysis
85+
- name: Run MSVC Code Analysis
86+
uses: microsoft/[email protected]
87+
id: run-analysis
88+
with:
89+
cmakeBuildDirectory: ${{ env.build }}
90+
buildConfiguration: ${{ env.config }}
91+
ruleset: NativeRecommendedRules.ruleset
92+
93+
# Step: Upload SARIF file to GitHub Code Scanning Alerts
94+
- name: Upload SARIF to GitHub
95+
uses: github/codeql-action/[email protected]
96+
with:
97+
sarif_file: ${{ steps.run-analysis.outputs.sarif }}

0 commit comments

Comments
 (0)