You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/customizing-code-scanning.md
+20-20Lines changed: 20 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -102,7 +102,7 @@ By default, only alerts with the severity level of `Error` or security severity
102
102
103
103
You might want to avoid a code scan being triggered on specific pull requests targeted against the default branch, irrespective of which files have been changed. You can configure this by specifying `on:pull_request:paths-ignore` or `on:pull_request:paths` in the {% data variables.product.prodname_code_scanning %} workflow. For example, if the only changes in a pull request are to files with the file extensions `.md` or `.txt` you can use the following `paths-ignore` array.
104
104
105
-
```yaml
105
+
```yaml{:copy}
106
106
on:
107
107
push:
108
108
branches: [main, protected]
@@ -138,7 +138,7 @@ If you use the default {% data variables.code-scanning.codeql_workflow %}, the w
138
138
139
139
The following example shows a {% data variables.code-scanning.codeql_workflow %} for a particular repository that has a default branch called `main` and one protected branch called `protected`.
140
140
141
-
``` yaml
141
+
```yaml{:copy}
142
142
on:
143
143
push:
144
144
branches: [main, protected]
@@ -157,7 +157,7 @@ This workflow scans:
157
157
158
158
If your code requires a specific operating system to compile, you can configure the operating system in your {% data variables.code-scanning.codeql_workflow %}. Edit the value of `jobs.analyze.runs-on` to specify the operating system for the machine that runs your {% data variables.product.prodname_code_scanning %} actions. {% ifversion ghes %}You specify the operating system by using an appropriate label as the second element in a two-element array, after `self-hosted`.{% else %}
159
159
160
-
``` yaml
160
+
```yaml{:copy}
161
161
jobs:
162
162
analyze:
163
163
name: Analyze
@@ -166,7 +166,7 @@ jobs:
166
166
167
167
If you choose to use a self-hosted runner for code scanning, you can specify an operating system by using an appropriate label as the second element in a two-element array, after `self-hosted`.{% endif %}
168
168
169
-
``` yaml
169
+
```yaml{:copy}
170
170
jobs:
171
171
analyze:
172
172
name: Analyze
@@ -183,7 +183,7 @@ For recommended specifications (RAM, CPU cores, and disk) for running {% data va
183
183
184
184
In general, you do not need to worry about where the {% data variables.code-scanning.codeql_workflow %} places {% data variables.product.prodname_codeql %} databases since later steps will automatically find databases created by previous steps. However, if you are writing a custom workflow step that requires the {% data variables.product.prodname_codeql %} database to be in a specific disk location, for example to upload the database as a workflow artifact, you can specify that location using the `db-location` parameter under the `init` action.
185
185
186
-
``` yaml
186
+
```yaml{:copy}
187
187
- uses: {% data reusables.actions.action-codeql-action-init %}
188
188
with:
189
189
db-location: {% raw %}'${{ github.workspace }}/codeql_dbs'{% endraw %}
@@ -205,7 +205,7 @@ The default {% data variables.code-scanning.codeql_workflow %} file contains a m
205
205
206
206
If your workflow uses the `language` matrix then {% data variables.product.prodname_codeql %} is hardcoded to analyze only the languages in the matrix. To change the languages you want to analyze, edit the value of the matrix variable. You can remove a language to prevent it being analyzed or you can add a language that was not present in the repository when {% data variables.product.prodname_code_scanning %} was configured. For example, if the repository initially only contained JavaScript when {% data variables.product.prodname_code_scanning %} was configured, and you later added Python code, you will need to add `python` to the matrix.
207
207
208
-
```yaml
208
+
```yaml{:copy}
209
209
jobs:
210
210
analyze:
211
211
name: Analyze
@@ -218,7 +218,7 @@ jobs:
218
218
219
219
If your workflow does not contain a matrix called `language`, then {% data variables.product.prodname_codeql %} is configured to run analysis sequentially. If you don't specify languages in the workflow, {% data variables.product.prodname_codeql %} automatically detects, and attempts to analyze, any supported languages in the repository. If you want to choose which languages to analyze, without using a matrix, you can use the `languages` parameter under the `init` action.
220
220
221
-
```yaml
221
+
```yaml{:copy}
222
222
- uses: {% data reusables.actions.action-codeql-action-init %}
223
223
with:
224
224
languages: cpp, csharp, python
@@ -234,7 +234,7 @@ For GitHub-hosted runners that use Linux only, the {% data variables.code-scanni
234
234
235
235
Alternatively, you can install Python dependencies manually on any operating system. You will need to add `setup-python-dependencies` and set it to `false`, as well as set `CODEQL_PYTHON` to the Python executable that includes the dependencies, as shown in this workflow extract:
236
236
237
-
```yaml
237
+
```yaml{:copy}
238
238
jobs:
239
239
CodeQL-Build:
240
240
runs-on: ubuntu-latest
@@ -274,7 +274,7 @@ Use `category` to distinguish between multiple analyses for the same tool and co
274
274
275
275
This parameter is particularly useful if you work with monorepos and have multiple SARIF files for different components of the monorepo.
276
276
277
-
``` yaml
277
+
```yaml{:copy}
278
278
- name: Perform CodeQL Analysis
279
279
uses: {% data reusables.actions.action-codeql-action-analyze %}
280
280
with:
@@ -315,7 +315,7 @@ In the example below, `scope` is the organization or personal account that publi
315
315
- The latest version of `pack3` that is compatible with version 3.2.1 is downloaded and all queries are run.
316
316
- Version 4.5.6 of `pack4` is downloaded and only the queries found in `path/to/queries` are run.
317
317
318
-
``` yaml
318
+
```yaml{:copy}
319
319
- uses: {% data reusables.actions.action-codeql-action-init %}
320
320
with:
321
321
# Comma-separated list of packs to download
@@ -341,7 +341,7 @@ For more information about pack compatibility, see "[About {% data variables.pro
341
341
342
342
If your workflow uses packs that are published on a {% data variables.product.prodname_ghe_server %} installation, you need to tell your workflow where to find them. You can do this by using the `registries` input of the {% data reusables.actions.action-codeql-action-init %} action. This input accepts a list of `url`, `packages`, and `token` properties as shown below.
343
343
344
-
```
344
+
```yaml{:copy}
345
345
- uses: {% data reusables.actions.action-codeql-action-init %}
346
346
with:
347
347
registries: {% raw %}|
@@ -373,7 +373,7 @@ Notice the `|` after the `registries` property name. This is important since {%
373
373
{% endif %}
374
374
To add one or more queries, add a `with: queries:` entry within the `uses: {% data reusables.actions.action-codeql-action-init %}` section of the workflow. If the queries are in a private repository, use the `external-repository-token` parameter to specify a token that has access to checkout the private repository.
375
375
376
-
``` yaml
376
+
```yaml{:copy}
377
377
- uses: {% data reusables.actions.action-codeql-action-init %}
378
378
with:
379
379
queries: COMMA-SEPARATED LIST OF PATHS
@@ -393,7 +393,7 @@ If you also use a configuration file for custom settings, any additional {% ifve
393
393
394
394
In the following example, the `+` symbol ensures that the specified additional {% ifversion codeql-packs %}packs and {% endif %}queries are used together with any specified in the referenced configuration file.
395
395
396
-
```yaml
396
+
```yaml{:copy}
397
397
- uses: {% data reusables.actions.action-codeql-action-init %}
398
398
with:
399
399
config-file: ./.github/codeql/codeql-config.yml
@@ -409,7 +409,7 @@ A custom configuration file is an alternative way to specify additional {% ifver
409
409
410
410
In the workflow file, use the `config-file` parameter of the `init` action to specify the path to the configuration file you want to use. This example loads the configuration file _./.github/codeql/codeql-config.yml_.
411
411
412
-
```yaml
412
+
```yaml{:copy}
413
413
- uses: {% data reusables.actions.action-codeql-action-init %}
414
414
with:
415
415
config-file: ./.github/codeql/codeql-config.yml
@@ -419,7 +419,7 @@ In the workflow file, use the `config-file` parameter of the `init` action to sp
419
419
420
420
If the configuration file is located in an external private repository, use the `external-repository-token` parameter of the `init` action to specify a token that has access to the private repository.
421
421
422
-
```yaml
422
+
```yaml{:copy}
423
423
- uses: {% data reusables.actions.action-codeql-action-init %}
424
424
with:
425
425
external-repository-token: {% raw %}${{ secrets.ACCESS_TOKEN }}{% endraw %}
@@ -435,7 +435,7 @@ The settings in the configuration file are written in YAML format.
435
435
You specify {% data variables.product.prodname_codeql %} query packs in an array. Note that the format is different from the format used by the workflow file.
436
436
437
437
{% raw %}
438
-
``` yaml
438
+
```yaml{:copy}
439
439
packs:
440
440
# Use the latest version of 'pack1' published by 'scope'
441
441
- scope/pack1
@@ -457,7 +457,7 @@ The full format for specifying a query pack is `scope/name[@version][:path]`. Bo
457
457
If you have a workflow that generates more than one {% data variables.product.prodname_codeql %} database, you can specify any {% data variables.product.prodname_codeql %} query packs to run in a custom configuration file using a nested map of packs.
458
458
459
459
{% raw %}
460
-
``` yaml
460
+
```yaml{:copy}
461
461
packs:
462
462
# Use these packs for JavaScript and TypeScript analysis
463
463
javascript:
@@ -475,7 +475,7 @@ packs:
475
475
476
476
You specify additional queries in a `queries` array. Each element of the array contains a `uses` parameter with a value that identifies a single query file, a directory containing query files, or a query suite definition file.
477
477
478
-
``` yaml
478
+
```yaml{:copy}
479
479
queries:
480
480
- uses: ./my-basic-queries/example-query.ql
481
481
- uses: ./my-advanced-queries
@@ -500,7 +500,7 @@ This is useful if you want to exclude, for example:
500
500
501
501
You can use `exclude` filters similar to those in the configuration file below to exclude queries that you want to remove from the default analysis. In the example of configuration file below, both the `js/redundant-assignment` and the `js/useless-assignment-to-local` queries are excluded from analysis.
502
502
503
-
```yaml
503
+
```yaml{:copy}
504
504
query-filters:
505
505
- exclude:
506
506
id: js/redundant-assignment
@@ -527,7 +527,7 @@ For more information about using `exclude` and `include` filters in your custom
527
527
528
528
For the interpreted languages that {% data variables.product.prodname_codeql %} supports (Python{% ifversion fpt or ghes or ghae > 3.3 %}, Ruby{% endif %} and JavaScript/TypeScript), you can restrict {% data variables.product.prodname_code_scanning %} to files in specific directories by adding a `paths` array to the configuration file. You can exclude the files in specific directories from analysis by adding a `paths-ignore` array.
0 commit comments