forked from netdata/netdata
-
Notifications
You must be signed in to change notification settings - Fork 0
162 lines (159 loc) · 5.04 KB
/
codeql.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
---
# Run CodeQL to analyze C/C++ and Python code.
name: CodeQL
on:
pull_request:
types: [opened, reopened, labeled, synchronize]
branches: [master]
push:
branches: [master]
schedule:
- cron: "27 2 * * 1"
env:
DISABLE_TELEMETRY: 1
concurrency:
group: codeql-${{ github.ref }}
cancel-in-progress: true
jobs:
prepare:
name: Prepare Jobs
runs-on: ubuntu-latest
outputs:
cpp: ${{ steps.cpp.outputs.run }}
python: ${{ steps.python.outputs.run }}
go: ${{ steps.go.outputs.run }}
steps:
- name: Clone repository
uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0
- name: Check if we should always run
id: always
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
if [ "${{ contains(github.event.pull_request.labels.*.name, 'run-ci/codeql') }}" = "true" ]; then
echo "run=true" >> "${GITHUB_OUTPUT}"
echo '::notice::Found ci/codeql label, unconditionally running all CodeQL checks.'
else
echo "run=false" >> "${GITHUB_OUTPUT}"
fi
else
echo "run=true" >> "${GITHUB_OUTPUT}"
fi
- name: Check for C/C++ changes
id: cpp
run: |
if [ "${{ steps.always.outputs.run }}" = "false" ]; then
if git diff --name-only origin/${{ github.base_ref }} HEAD | grep -Eq '.*\.[ch](xx|\+\+)?' ; then
echo "run=true" >> "${GITHUB_OUTPUT}"
echo '::notice::C/C++ code has changed, need to run CodeQL.'
else
echo "run=false" >> "${GITHUB_OUTPUT}"
fi
else
echo "run=true" >> "${GITHUB_OUTPUT}"
fi
- name: Check for python changes
id: python
run: |
if [ "${{ steps.always.outputs.run }}" = "false" ]; then
if git diff --name-only origin/${{ github.base_ref }} HEAD | grep -Eq 'src/collectors/python.d.plugin/.*\.py' ; then
echo "run=true" >> "${GITHUB_OUTPUT}"
echo '::notice::Python code has changed, need to run CodeQL.'
else
echo "run=false" >> "${GITHUB_OUTPUT}"
fi
else
echo "run=true" >> "${GITHUB_OUTPUT}"
fi
- name: Check for Go changes
id: go
run: |
if [ "${{ steps.always.outputs.run }}" = "false" ]; then
if git diff --name-only origin/${{ github.base_ref }} HEAD | grep -Eq 'src/go/*\.go' ; then
echo "run=true" >> "${GITHUB_OUTPUT}"
echo '::notice::Go code has changed, need to run CodeQL.'
else
echo "run=false" >> "${GITHUB_OUTPUT}"
fi
else
echo "run=true" >> "${GITHUB_OUTPUT}"
fi
analyze-cpp:
name: Analyze C/C++
runs-on: ubuntu-latest
needs: prepare
if: needs.prepare.outputs.cpp == 'true'
permissions:
security-events: write
steps:
- name: Git clone repository
uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: cpp
config-file: ./.github/codeql/c-cpp-config.yml
- name: Prepare environment
run: ./packaging/installer/install-required-packages.sh --dont-wait --non-interactive netdata
- name: Build netdata
run: ./netdata-installer.sh --dont-start-it --disable-telemetry --dont-wait --install-prefix /tmp/install --one-time-build
- name: Run CodeQL
uses: github/codeql-action/analyze@v3
with:
category: "/language:cpp"
analyze-python:
name: Analyze Python
runs-on: ubuntu-latest
needs: prepare
if: needs.prepare.outputs.python == 'true'
permissions:
security-events: write
steps:
- name: Git clone repository
uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
config-file: ./.github/codeql/python-config.yml
languages: python
- name: Run CodeQL
uses: github/codeql-action/analyze@v3
with:
category: "/language:python"
analyze-go:
name: Analyze Go
runs-on: ubuntu-latest
needs: prepare
if: needs.prepare.outputs.go == 'true'
strategy:
matrix:
tree:
- src/go
permissions:
security-events: write
steps:
- name: Git clone repository
uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: go
- name: Autobuild
uses: github/codeql-action/autobuild@v3
with:
working-directory: ${{ matrix.tree }}
- name: Run CodeQL
uses: github/codeql-action/analyze@v3
with:
category: "/language:go"