Skip to content

Commit b361e0f

Browse files
dschoturboaibaars
committed
codeql: run static analysis as part of CI builds
CodeQL is GitHub's native offering of a static code analyzer, and hence integrates with GitHub Actions better than any other static code analyzer. By default, it comes with a large range of "queries" that test for common code patterns that should be avoided. For now, we only target source code written in C, via the `language: cpp` directive. Just in case that other languages should be targeted, too, this GitHub workflow job is set up as a matrix job to make that easier in the future. For full documentation, see https://docs.github.com/en/code-security/code-scanning/introduction-to-code-scanning/about-code-scanning-with-codeql Co-authored-by: Pierre Tempel <turbo@github.com> Co-authored-by: Arthur Baars <aibaars@github.com> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 21f188e commit b361e0f

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

.github/workflows/codeql.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: "CodeQL"
2+
3+
on:
4+
push:
5+
pull_request:
6+
workflow_dispatch:
7+
schedule:
8+
- cron: '0 3 * * 1' # Every Monday at 03:00 UTC
9+
10+
jobs:
11+
analyze:
12+
name: Analyze
13+
runs-on: ubuntu-latest
14+
permissions:
15+
actions: read
16+
contents: read
17+
security-events: write
18+
19+
strategy:
20+
fail-fast: false
21+
matrix:
22+
language: ["cpp"]
23+
24+
steps:
25+
- name: Checkout repository
26+
uses: actions/checkout@v3
27+
28+
- name: Install dependencies
29+
run: ci/install-dependencies.sh
30+
if: matrix.language == 'cpp'
31+
env:
32+
jobname: codeql
33+
34+
# Initializes the CodeQL tools for scanning.
35+
- name: Initialize CodeQL
36+
uses: github/codeql-action/init@v3
37+
with:
38+
languages: ${{ matrix.language }}
39+
queries: security-extended
40+
41+
- name: Build
42+
if: matrix.language == 'cpp'
43+
run: |
44+
cat /proc/cpuinfo
45+
make -j$(nproc)
46+
47+
- name: Perform CodeQL Analysis
48+
uses: github/codeql-action/analyze@v3

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,3 +260,5 @@ Release/
260260
CMakeSettings.json
261261
/contrib/libgit-rs/target
262262
/contrib/libgit-sys/target
263+
/.github/codeql/.cache/
264+
/.github/codeql/codeql-pack.lock.yml

ci/install-dependencies.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ case "$jobname" in
133133
ClangFormat)
134134
sudo apt-get -q -y install clang-format
135135
;;
136-
StaticAnalysis)
136+
StaticAnalysis|codeql)
137137
sudo apt-get -q -y install coccinelle libcurl4-openssl-dev libssl-dev \
138138
libexpat-dev gettext make
139139
;;

0 commit comments

Comments
 (0)