Skip to content

Commit 0cd6556

Browse files
committed
Docs: Update analyzing databases docs
Add more information about running packs. Include the `--download` flag.
1 parent 7fcf567 commit 0cd6556

File tree

1 file changed

+31
-25
lines changed

1 file changed

+31
-25
lines changed

docs/codeql/codeql-cli/analyzing-databases-with-the-codeql-cli.rst

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Running ``codeql database analyze``
2626

2727
When you run ``database analyze``, it:
2828

29+
#. Optionally downloads any referenced CodeQL packages that are not available locally.
2930
#. Executes one or more query files, by running them over a CodeQL database.
3031
#. Interprets the results, based on certain query metadata, so that alerts can be
3132
displayed in the correct location in the source code.
@@ -50,10 +51,13 @@ You must specify:
5051

5152
You can also specify:
5253

53-
- ``<queries>``: the queries to run over your database. You can
54-
list one or more individual query files, specify a directory that will be
55-
searched recursively for query files, or name a query suite that defines a
56-
particular set of queries. If omitted, the default query suite for the language
54+
- ``...<query-specifications>``: a list of queries to run over your database. This
55+
is a list of arguments. Where each argument can be:
56+
- a path to a query file
57+
- a path to a directory containing query files
58+
- a path to a query suite file
59+
- the name of a CodeQL query pack
60+
If omitted, the default query suite for the language
5761
of the database being analyzed will be usedFor more information, see the
5862
:ref:`examples <database-analyze-examples>` below.
5963

@@ -63,11 +67,14 @@ You can also specify:
6367
language to the GitHub code scanning API. For more information about this use case,
6468
see `Configuring CodeQL CLI in your CI system <https://docs.github.com/en/code-security/secure-coding/using-codeql-code-scanning-with-your-existing-ci-system/configuring-codeql-cli-in-your-ci-system>`__ in the GitHub documentation.
6569

66-
- ``--sarif-add-query-help``: (supported in version 2.7.1 onwards) adds any custom query help written
67-
in markdown to SARIF files (v2.1.0 or later) generated by the analysis. Query help stored in ``.qhelp`` files must be
68-
converted to ``.md`` before running the analysis. For further information,
70+
- ``--sarif-add-query-help``: (supported in version 2.7.1 onwards) adds any custom query help written
71+
in markdown to SARIF files (v2.1.0 or later) generated by the analysis. Query help stored in ``.qhelp`` files must be
72+
converted to ``.md`` before running the analysis. For further information,
6973
see ":ref:`Including query help for custom CodeQL queries in SARIF files <including-query-help-for-custom-codeql-queries-in-sarif-files>`."
7074

75+
- ``--download``: a boolean flag that will allow the CLI to download any referenced CodeQL packages that are not available locally.
76+
If this flag is missing and a referenced CodeQL package is not available locally, the command will fail.
77+
7178
- .. include:: ../reusables/threads-query-execution.rst
7279

7380

@@ -119,17 +126,16 @@ Running a CodeQL pack
119126

120127
.. include:: ../reusables/beta-note-package-management.rst
121128

122-
To run an existing CodeQL query pack from the GitHub Container registry, you need to download it first::
123-
124-
codeql pack download microsoft/[email protected]
129+
To run an existing CodeQL query pack from the GitHub Container registry, you can specify one or more
130+
pack names and use the ``--download`` flag::
125131

126-
Afterwards, you can run the pack on a specific database::
132+
codeql database analyze --download <database> microsoft/[email protected] github/secutiry-queries --format=sarifv2.1.0 --output=query-results.sarif
127133

128-
codeql database analyze <database> microsoft/[email protected] <scope>/<other-pack> --format=sarifv2.1.0 --output=query-results.sarif
129-
130-
The ``analyze`` command above runs the default suite from ``microsoft/coding-standards v1.0.0`` and the latest version of ``scope/other-pack`` on the specified database.
134+
The ``analyze`` command above runs the default suite from ``microsoft/coding-standards v1.0.0`` and the latest version of ``github/secutiry-queries`` on the specified database.
131135
For further information about default suites, see ":ref:`Publishing and using CodeQL packs <publishing-and-using-codeql-packs>`".
132136

137+
For more information about CodeQL packs, see :doc:`About CodeQL Packs <about-codeql-packs>`.
138+
133139
Running query suites
134140
~~~~~~~~~~~~~~~~~~~~
135141

@@ -176,7 +182,7 @@ Integrating a CodeQL pack into a code scanning workflow in GitHub
176182

177183
.. include:: ../reusables/beta-note-package-management.rst
178184

179-
You can use CodeQL query packs in your Code Scanning setup. This allows you to select query packs published by various sources and use them to analyze your code.
185+
You can use CodeQL query packs in your Code Scanning setup. This allows you to select query packs published by various sources and use them to analyze your code.
180186
For more information, see "`Using CodeQL query packs in the CodeQL action <https://docs.github.com/en/code-security/secure-coding/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-codeql-query-packs/>`_" or "`Downloading and using CodeQL query packs in your CI system <https://docs.github.com/en/code-security/secure-coding/using-codeql-code-scanning-with-your-existing-ci-system/configuring-codeql-cli-in-your-ci-system#downloading-and-using-codeql-query-packs>`_."
181187

182188

@@ -206,28 +212,28 @@ A SARIF results file is generated. Specifying ``--format=sarif-latest`` ensures
206212
that the results are formatted according to the most recent SARIF specification
207213
supported by CodeQL.
208214

209-
.. _including-query-help-for-custom-codeql-queries-in-sarif-files:
215+
.. _including-query-help-for-custom-codeql-queries-in-sarif-files:
210216

211-
Including query help for custom CodeQL queries in SARIF files
217+
Including query help for custom CodeQL queries in SARIF files
212218
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
213219

214220
If you use the CodeQL CLI to to run code scanning analyses on third party CI/CD systems,
215221
you can include the query help for your custom queries in SARIF files generated during an analysis.
216-
After uploading the SARIF file to GitHub, the query help is shown in the code scanning UI for any
217-
alerts generated by the custom queries.
222+
After uploading the SARIF file to GitHub, the query help is shown in the code scanning UI for any
223+
alerts generated by the custom queries.
218224

219-
From CodeQL CLI 2.7.1 onwards, you can include markdown-rendered query help in SARIF files
225+
From CodeQL CLI 2.7.1 onwards, you can include markdown-rendered query help in SARIF files
220226
by providing the ``--sarif-add-query-help`` option when running
221-
``codeql database analyze``.
227+
``codeql database analyze``.
222228
For more information, see `Configuring CodeQL CLI in your CI system <https://docs.github.com/en/code-security/code-scanning/using-codeql-code-scanning-with-your-existing-ci-system/configuring-codeql-cli-in-your-ci-system#analyzing-a-codeql-database>`__
223229
in the GitHub documentation.
224230

225231
You can write query help for custom queries directly in a markdown file and save it alongside the
226-
corresponding query. Alternatively, for consistency with the standard CodeQL queries,
227-
you can write query help in the ``.qhelp`` format. Query help written in ``.qhelp``
232+
corresponding query. Alternatively, for consistency with the standard CodeQL queries,
233+
you can write query help in the ``.qhelp`` format. Query help written in ``.qhelp``
228234
files can't be included in SARIF files, and they can't be processed by code
229-
scanning so must be converted to markdown before running
230-
the analysis. For more information, see ":ref:`Query help files <query-help-files>`"
235+
scanning so must be converted to markdown before running
236+
the analysis. For more information, see ":ref:`Query help files <query-help-files>`"
231237
and ":doc:`Testing query help files <testing-query-help-files>`."
232238

233239
Results

0 commit comments

Comments
 (0)