forked from github/codeql-coding-standards
-
Notifications
You must be signed in to change notification settings - Fork 0
281 lines (243 loc) · 10.2 KB
/
code-scanning-pack-gen.yml
File metadata and controls
281 lines (243 loc) · 10.2 KB
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
name: Code Scanning Query Pack Generation
on:
pull_request:
branches:
- main
- "rc/**"
- next
push:
branches:
- main
- "rc/**"
- next
env:
XARGS_MAX_PROCS: 4
jobs:
prepare-code-scanning-pack-matrix:
name: Prepare CodeQL Code Scanning pack matrix
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.export-code-scanning-pack-matrix.outputs.matrix }}
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Export Code Scanning pack matrix
id: export-code-scanning-pack-matrix
run: |
echo "::set-output name=matrix::$(
jq --compact-output '.supported_environment | {include: .}' supported_codeql_configs.json
)"
create-code-scanning-pack-anon:
name: Create anonymous Code Scanning pack
needs: prepare-code-scanning-pack-matrix
runs-on: ubuntu-20.04-xl
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.prepare-code-scanning-pack-matrix.outputs.matrix) }}
steps:
- uses: actions/checkout@v2
- name: Cache CodeQL
id: cache-codeql
uses: actions/cache@v2.1.3
with:
path: ${{ github.workspace }}/codeql_home
key: codeql-home-${{ matrix.os }}-${{ matrix.codeql_cli }}-${{ matrix.codeql_standard_library }}
- name: Install CodeQL
if: steps.cache-codeql.outputs.cache-hit != 'true'
uses: ./.github/actions/install-codeql
with:
codeql-cli-version: ${{ matrix.codeql_cli }}
codeql-stdlib-version: ${{ matrix.codeql_standard_library }}
codeql-home: ${{ github.workspace }}/codeql_home
add-to-path: false
- name: Install Python
uses: actions/setup-python@v4
with:
python-version: "3.9"
- name: Anonymising and pre-compiling queries
env:
CODEQL_HOME: ${{ github.workspace }}/codeql_home
run: |
PATH=$PATH:$CODEQL_HOME/codeql
pip install -r scripts/requirements.txt
find rule_packages/cpp -name '*.json' -exec basename {} .json \; | xargs --max-procs "$XARGS_MAX_PROCS" --max-args 1 python scripts/generate_rules/generate_package_files.py -a cpp
find rule_packages/c -name '*.json' -exec basename {} .json \; | xargs --max-procs "$XARGS_MAX_PROCS" --max-args 1 python scripts/generate_rules/generate_package_files.py --skip-shared-test-generation -a c
echo "Remove help files that cannot be freely distributed"
find cpp/autosar/src/rules -name "*.md" -delete
find c/misra/src/rules -name "*.md" -delete
codeql query compile --search-path cpp --threads 0 cpp
codeql query compile --search-path c --search-path cpp --threads 0 c
cd ..
zip -r codeql-coding-standards/code-scanning-cpp-query-pack-anon.zip codeql-coding-standards/c/ codeql-coding-standards/cpp/ codeql-coding-standards/.codeqlmanifest.json codeql-coding-standards/supported_codeql_configs.json codeql-coding-standards/scripts/deviations codeql-coding-standards/scripts/reports
- name: Upload GHAS Query Pack
uses: actions/upload-artifact@v2
with:
name: code-scanning-cpp-query-pack-anon.zip
path: code-scanning-cpp-query-pack-anon.zip
- name: Create LGTM query pack
env:
CODEQL_HOME: ${{ github.workspace }}/codeql_home
run: |
PATH=$PATH:$CODEQL_HOME/codeql
mkdir -p lgtm-cpp-query-pack
function copy_queries_for_pack {
for q in $(codeql resolve queries $2/$1/src/codeql-suites/$1-default.qls)
do
copy_from_root_name="${q%.*}"
copy_to_root_name=$(realpath --relative-to "./$2/$1/src/" "$copy_from_root_name")
query_dir=$(dirname "lgtm-cpp-query-pack/$copy_to_root_name")
mkdir -p "$query_dir"
# Copy each selected ql file
cp "$copy_from_root_name.ql" "lgtm-cpp-query-pack/$copy_to_root_name.ql"
done
}
echo "Copying autosar-default queries (CPP)"
copy_queries_for_pack "autosar" "cpp"
echo "Copying cert-default queries (CPP)"
copy_queries_for_pack "cert" "cpp"
echo "Copying misra-default queries (C)"
copy_queries_for_pack "misra" "c"
echo "Copying cert-default queries (C)"
copy_queries_for_pack "cert" "c"
# Now copy all the .qll files
lgtm_pack_dir=$(realpath lgtm-cpp-query-pack)
for query_pack in autosar cert common
do
echo "Copying $query_pack qll files"
pushd cpp/$query_pack/src
for query_library in $(find . -name \*.qll)
do
qll_dir=$(dirname "$lgtm_pack_dir/$query_library")
echo "Making $qll_dir"
mkdir -p "$qll_dir"
cp "$query_library" "$lgtm_pack_dir/$query_library"
done
popd
done
for query_pack in misra cert common
do
echo "Copying $query_pack qll files"
pushd c/$query_pack/src
for query_library in $(find . -name \*.qll)
do
qll_dir=$(dirname "$lgtm_pack_dir/$query_library")
echo "Making $qll_dir"
mkdir -p "$qll_dir"
cp "$query_library" "$lgtm_pack_dir/$query_library"
done
popd
done
cd lgtm-cpp-query-pack
zip -9 -r ../lgtm-cpp-query-pack-anon.zip *
- name: Upload LGTM query pack
uses: actions/upload-artifact@v2
with:
name: lgtm-cpp-query-pack-anon.zip
path: lgtm-cpp-query-pack-anon.zip
create-code-scanning-pack:
name: Create Code Scanning pack
needs: prepare-code-scanning-pack-matrix
runs-on: ubuntu-20.04-xl
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.prepare-code-scanning-pack-matrix.outputs.matrix) }}
steps:
- uses: actions/checkout@v2
- name: Cache CodeQL
id: cache-codeql
uses: actions/cache@v2.1.3
with:
path: ${{ github.workspace }}/codeql_home
key: codeql-home-${{ matrix.os }}-${{ matrix.codeql_cli }}-${{ matrix.codeql_standard_library }}
- name: Install CodeQL
if: steps.cache-codeql.outputs.cache-hit != 'true'
uses: ./.github/actions/install-codeql
with:
codeql-cli-version: ${{ matrix.codeql_cli }}
codeql-stdlib-version: ${{ matrix.codeql_standard_library }}
codeql-home: ${{ github.workspace }}/codeql_home
add-to-path: false
- name: Checkout external help files
uses: actions/checkout@v2
with:
ssh-key: ${{ secrets.CODEQL_CODING_STANDARDS_HELP_KEY }}
repository: "github/codeql-coding-standards-help"
ref: ${{ github.head_ref }}
path: external-help-files
- name: Include external help files
run: |
pushd external-help-files
find . -name '*.md' -exec rsync -av --relative {} "$GITHUB_WORKSPACE" \;
popd
- name: Pre-compiling queries
env:
CODEQL_HOME: ${{ github.workspace }}/codeql_home
run: |
PATH=$PATH:$CODEQL_HOME/codeql
codeql query compile --search-path cpp --threads 0 cpp
codeql query compile --search-path c --search-path cpp --threads 0 c
cd ..
zip -r codeql-coding-standards/code-scanning-cpp-query-pack.zip codeql-coding-standards/c/ codeql-coding-standards/cpp/ codeql-coding-standards/.codeqlmanifest.json codeql-coding-standards/supported_codeql_configs.json codeql-coding-standards/scripts/deviations codeql-coding-standards/scripts/reports
- name: Upload GHAS Query Pack
uses: actions/upload-artifact@v2
with:
name: code-scanning-cpp-query-pack.zip
path: code-scanning-cpp-query-pack.zip
- name: Create LGTM query pack
env:
CODEQL_HOME: ${{ github.workspace }}/codeql_home
run: |
PATH=$PATH:$CODEQL_HOME/codeql
mkdir -p lgtm-cpp-query-pack
function copy_queries_for_pack {
for rule_dir in $(codeql resolve queries $2/$1/src/codeql-suites/$1-default.qls | xargs -L1 dirname | uniq)
do
copy_to_root="lgtm-cpp-query-pack/$(realpath --relative-to "./$2/$1/src/" "$rule_dir")"
mkdir -p "$copy_to_root"
# Copy each selected ql file, plus the related files
find "$rule_dir" -name '*.ql' -o -name '*.c' -name '*.cpp' -o -name '*.png' -exec cp -n {} "$copy_to_root" \;
done
}
echo "Copying autosar-default queries (CPP)"
copy_queries_for_pack "autosar" "cpp"
echo "Copying cert-default queries (CPP)"
copy_queries_for_pack "cert" "cpp"
echo "Copying misra-default queries (C)"
copy_queries_for_pack "misra" "c"
echo "Copying cert-default queries (C)"
copy_queries_for_pack "cert" "c"
# Now copy all the .qll files
lgtm_pack_dir=$(realpath lgtm-cpp-query-pack)
for query_pack in autosar cert common
do
echo "Copying $query_pack qll files"
pushd cpp/$query_pack/src
for query_library in $(find . -name \*.qll)
do
qll_dir=$(dirname "$lgtm_pack_dir/$query_library")
echo "Making $qll_dir"
mkdir -p "$qll_dir"
cp "$query_library" "$lgtm_pack_dir/$query_library"
done
popd
done
for query_pack in misra cert common
do
echo "Copying $query_pack qll files"
pushd c/$query_pack/src
for query_library in $(find . -name \*.qll)
do
qll_dir=$(dirname "$lgtm_pack_dir/$query_library")
echo "Making $qll_dir"
mkdir -p "$qll_dir"
cp "$query_library" "$lgtm_pack_dir/$query_library"
done
popd
done
cd lgtm-cpp-query-pack
zip -9 -r ../lgtm-cpp-query-pack.zip *
- name: Upload LGTM query pack
uses: actions/upload-artifact@v2
with:
name: lgtm-cpp-query-pack.zip
path: lgtm-cpp-query-pack.zip