Skip to content

Commit bc17d06

Browse files
authored
Merge pull request #10105 from github/aeisenberg/about-codeql-packs
Merge and update `about-ql-packs` with `about-codeql-packs`
2 parents e174123 + 9e6e37a commit bc17d06

19 files changed

+531
-522
lines changed

docs/codeql/codeql-cli/about-codeql-packs.rst

Lines changed: 275 additions & 35 deletions
Large diffs are not rendered by default.

docs/codeql/codeql-cli/about-ql-packs.rst

Lines changed: 0 additions & 245 deletions
This file was deleted.

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

Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@ You can also specify:
5858
- a path to a directory containing query files
5959
- a path to a query suite file
6060
- the name of a CodeQL query pack
61-
If omitted, the default query suite for the language
62-
of the database being analyzed will be used. For more information, see the
63-
:ref:`examples <database-analyze-examples>` below.
61+
- with an optional version range
62+
- with an optional path to a query, directory, or query suite inside the pack
63+
64+
If omitted, the default query suite for the language of the database being analyzed will be used. For more information, see the :ref:`examples <database-analyze-examples>` below.
6465

6566
- ``--sarif-category``: an identifying category for the results. Used when
6667
you want to upload more than one set of results for a commit.
@@ -122,6 +123,14 @@ You can also run your own custom queries with the ``database analyze`` command.
122123
For more information about preparing your queries to use with the CodeQL CLI,
123124
see ":doc:`Using custom queries with the CodeQL CLI <using-custom-queries-with-the-codeql-cli>`."
124125

126+
If you do not have the CodeQL repository checked out, you can execute the same queries by specifying the query pack name and the path to the queries::
127+
128+
codeql database analyze --download <javascript-database> codeql/javascript-queries:Declarations/UnusedVariable.ql --format=csv --output=js-analysis/js-results.csv
129+
130+
Use the ``--download`` flag to download the query pack if it isn't yet available locally.
131+
132+
.. _run-query-pack:
133+
125134
Running a CodeQL pack
126135
~~~~~~~~~~~~~~~~~~~~~
127136

@@ -135,6 +144,34 @@ pack names and use the ``--download`` flag::
135144
The ``analyze`` command above runs the default suite from ``microsoft/coding-standards v1.0.0`` and the latest version of ``github/security-queries`` on the specified database.
136145
For further information about default suites, see ":ref:`Publishing and using CodeQL packs <publishing-and-using-codeql-packs>`".
137146

147+
Running all queries in a directory
148+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
149+
150+
You can run all the queries located in a directory by providing the directory
151+
path, rather than listing all the individual query files. Paths are searched
152+
recursively, so any queries contained in subfolders will also be executed.
153+
154+
.. pull-quote::
155+
156+
Important
157+
158+
You should avoid specifying the root of a :ref:`core CodeQL query pack
159+
<standard-codeql-query-packs>` when executing ``database analyze``
160+
as it might contain some special queries that aren't designed to be used with
161+
the command. Rather, :ref:`run the query pack <run-query-pack>` to include the
162+
pack's default queries in the analysis, or run one of the
163+
code scanning query suites.
164+
165+
For example, to execute all Python queries contained in the ``Functions`` directory you would run::
166+
167+
codeql database analyze <python-database> ../ql/python/ql/src/Functions/ --format=sarif-latest --output=python-analysis/python-results.sarif
168+
169+
When the analysis has finished, a SARIF results file is generated. Specifying ``--format=sarif-latest`` ensures
170+
that the results are formatted according to the most recent SARIF specification
171+
supported by CodeQL.
172+
173+
.. _including-query-help-for-custom-codeql-queries-in-sarif-files:
174+
138175
Running a subset of queries in a CodeQL pack
139176
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
140177

@@ -192,10 +229,10 @@ For more information, see `Analyzing a CodeQL database <https://docs.github.com/
192229
or `Code scanning API <https://docs.github.com/en/rest/reference/code-scanning>`__ in the GitHub documentation.
193230

194231
CodeQL query suites are ``.qls`` files that use directives to select queries to run
195-
based on certain metadata properties. The standard QL packs have metadata that specify
232+
based on certain metadata properties. The standard CodeQL packs have metadata that specify
196233
the location of the query suites used by code scanning, so the CodeQL CLI knows where to find these
197234
suite files automatically, and you don't have to specify the full path on the command line.
198-
For more information, see ":ref:`About QL packs <standard-ql-packs>`."
235+
For more information, see ":ref:`About CodeQL packs <standard-codeql-packs>`."
199236

200237
The standard query suites are stored at the following paths in
201238
the CodeQL repository::
@@ -227,35 +264,6 @@ Integrating a CodeQL pack into a code scanning workflow in GitHub
227264
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.
228265
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>`_."
229266

230-
231-
Running all queries in a directory
232-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
233-
234-
You can run all the queries located in a directory by providing the directory
235-
path, rather than listing all the individual query files. Paths are searched
236-
recursively, so any queries contained in subfolders will also be executed.
237-
238-
.. pull-quote::
239-
240-
Important
241-
242-
You shouldn't specify the root of a :doc:`QL pack
243-
<about-ql-packs>` when executing ``database analyze``
244-
as it contains some special queries that aren't designed to be used with
245-
the command. Rather, to run a wide range of useful queries, run one of the
246-
LGTM.com query suites.
247-
248-
For example, to execute all Python queries contained in the ``Functions``
249-
directory you would run::
250-
251-
codeql database analyze <python-database> ../ql/python/ql/src/Functions/ --format=sarif-latest --output=python-analysis/python-results.sarif
252-
253-
A SARIF results file is generated. Specifying ``--format=sarif-latest`` ensures
254-
that the results are formatted according to the most recent SARIF specification
255-
supported by CodeQL.
256-
257-
.. _including-query-help-for-custom-codeql-queries-in-sarif-files:
258-
259267
Including query help for custom CodeQL queries in SARIF files
260268
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
261269

docs/codeql/codeql-cli/codeql-cli-reference.rst

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,19 @@
33
CodeQL CLI reference
44
====================
55

6-
Learn more about the files you can use when running CodeQL processes and the results format and exit codes that CodeQL generates.
6+
Learn more about the files you can use when running CodeQL processes and the results format and exit codes that CodeQL generates.
77

88
.. toctree::
99
:titlesonly:
1010
:hidden:
1111

1212
about-codeql-packs
13-
about-ql-packs
1413
query-reference-files
1514
sarif-output
1615
exit-codes
1716
extractor-options
1817

19-
- :doc:`About CodeQL packs <about-codeql-packs>`: CodeQL packs are created with the CodeQL CLI and are used to create, depend on, publish, and run CodeQL queries and libraries.
20-
- :doc:`About QL packs <about-ql-packs>`: QL packs are used to organize the files used in CodeQL analysis. They
21-
contain queries, library files, query suites, and important metadata.
18+
- :doc:`About CodeQL packs <about-codeql-packs>`: CodeQL packs are created with the CodeQL CLI and are used to create, depend on, publish, and run CodeQL queries, libraries, and query suites.
2219
- :doc:`Query reference files <query-reference-files>`: A query reference file is text file that defines the location of one query to test.
2320
- :doc:`SARIF output <sarif-output>`: CodeQL supports SARIF as an output format for sharing static analysis results.
2421
- :doc:`Exit codes <exit-codes>`: The CodeQL CLI reports the status of each command it runs as an exit code.

0 commit comments

Comments
 (0)