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
Adds a second getting started, specifically for checking out the
codeql repo as a way to get the core queries.
This ensures that people wanting to work in the traditional way still
have the old docs available.
- ``--sarif-category``: an identifying category for the results. Used when
65
66
you want to upload more than one set of results for a commit.
@@ -68,12 +69,12 @@ You can also specify:
68
69
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.
69
70
70
71
- ``--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,
73
-
see ":ref:`Including query help for custom CodeQL queries in SARIF files <including-query-help-for-custom-codeql-queries-in-sarif-files>`."
72
+
in markdown to SARIF files (v2.1.0 or later) generated by the analysis. Query help stored in ``.qhelp`` files must be
73
+
converted to ``.md`` before running the analysis. For further information,
74
+
see ":ref:`Including query help for custom CodeQL queries in SARIF files <including-query-help-for-custom-codeql-queries-in-sarif-files>`."
74
75
75
76
- ``--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
+
If this flag is missing and a referenced CodeQL package is not available locally, the command will fail.
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.
135
136
For further information about default suites, see ":ref:`Publishing and using CodeQL packs <publishing-and-using-codeql-packs>`".
Copy file name to clipboardExpand all lines: docs/codeql/codeql-cli/getting-started-with-the-codeql-cli.rst
+124-2Lines changed: 124 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -30,6 +30,8 @@ to display in GitHub as code scanning alerts, see
30
30
`Installing CodeQL CLI in your CI system <https://docs.github.com/en/code-security/secure-coding/using-codeql-code-scanning-with-your-existing-ci-system/installing-codeql-cli-in-your-ci-system>`__
31
31
in the GitHub documentation.
32
32
33
+
.. _download-cli:
34
+
33
35
1. Download the CodeQL CLI zip package
34
36
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
35
37
@@ -107,6 +109,8 @@ simply extract the zip archive.
107
109
iii. ``/usr/bin/xattr -c codeql*.zip``
108
110
iv. ``unzip codeql*.zip``
109
111
112
+
.. _launch-codeql-cli:
113
+
110
114
3. Launch ``codeql``
111
115
~~~~~~~~~~~~~~~~~~~~
112
116
@@ -139,7 +143,7 @@ up to create and analyze databases:
139
143
- Run ``codeql resolve languages`` to show which languages are
140
144
available for database creation. This will list the languages supported by
141
145
default in your CodeQL CLI package.
142
-
- (Optional) You can download some ":ref"`CodeQL packs <about-codeql-packs>` containing pre-compiled queries you would like to run.
146
+
- (Optional) You can download some ":ref`CodeQL packs <about-codeql-packs>`" containing pre-compiled queries you would like to run.
143
147
To do this, run ``codeql pack download <pack-name> [...pack-name]``, where ``pack-name`` is the name of
144
148
the pack you want to download. The core query packs are a good place to start. They are:
145
149
@@ -150,9 +154,127 @@ up to create and analyze databases:
150
154
- ``codeql/python-queries``
151
155
- ``codeql/ruby-queries``
152
156
153
-
Alternatively, you can download query packs during the analysis by using the `--download` flag of the `codeql database analyze`
157
+
Alternatively, you can download query packs during the analysis by using the ``--download`` flag of the ``codeql database analyze``
154
158
command.
155
159
160
+
161
+
Checking out the CodeQL source code directly
162
+
--------------------------------------------
163
+
164
+
Some users prefer working with CodeQL query sources directly in order to work on or contribute to the Open Source shared queries. In
165
+
order to do this, the following steps are recommended. Note that the following instructions are a slightly more complicated alternative
166
+
to working with CodeQL packages as explained above.
167
+
168
+
1. Download the CodeQL CLI zip
169
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
170
+
171
+
Follow :ref:`step 1 from the previous section<download-cli>`.
172
+
173
+
2. Create a new CodeQL directory
174
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
175
+
176
+
Create a new directory where you can place the CLI and any queries and libraries
177
+
you want to use. For example, ``$HOME/codeql-home``.
178
+
179
+
The CLI's built-in search operations automatically look in all of its sibling
180
+
directories for the files used in database creation and analysis. Keeping these
181
+
components in their own directory prevents the CLI searching unrelated sibling
182
+
directories while ensuring all files are available without specifying any
183
+
further options on the command line.
184
+
185
+
.. _local-copy-codeql-queries:
186
+
187
+
3. Obtain a local copy of the CodeQL queries
188
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
189
+
190
+
The `CodeQL repository <https://github.com/github/codeql>`__ contains
191
+
the queries and libraries required for CodeQL analysis of C/C++, C#, Java,
192
+
JavaScript/TypeScript, Python, and Ruby.
193
+
Clone a copy of this repository into ``codeql-home``.
194
+
195
+
By default, the root of the cloned repository will be called ``codeql``.
196
+
Rename this folder ``codeql-repo`` to avoid conflicting with the CodeQL
197
+
CLI that you will extract in step 4. If you use git on the command line, you can
198
+
clone and rename the repository in a single step by running
199
+
``git clone [email protected]:github/codeql.git codeql-repo`` in the ``codeql-home`` folder.
200
+
201
+
The CodeQL libraries and queries for Go analysis live in the `CodeQL for Go
202
+
repository <https://github.com/github/codeql-go/>`__. Clone a copy of this
203
+
repository into ``codeql-home``.
204
+
205
+
The cloned repositories should have a sibling relationship.
206
+
For example, if the root of the cloned CodeQL repository is
207
+
``$HOME/codeql-home/codeql-repo``, then the root of the cloned CodeQL for Go
208
+
repository should be ``$HOME/codeql-home/codeql-go``.
209
+
210
+
Within these repositories, the queries and libraries are organized into QL
211
+
packs. Along with the queries themselves, QL packs contain important metadata
212
+
that tells the CodeQL CLI how to process the query files. For more information,
213
+
see ":doc:`About QL packs <about-ql-packs>`."
214
+
215
+
.. pull-quote:: Important
216
+
217
+
There are different versions of the CodeQL queries available for different
218
+
users. Check out the correct version for your use case:
219
+
220
+
- For the queries used on `LGTM.com <https://lgtm.com>`__, check out the
221
+
``lgtm.com`` branch. You should use this branch for databases you've built
222
+
using the CodeQL CLI, fetched from code scanning on GitHub, or recently downloaded from LGTM.com.
223
+
The queries on the ``lgtm.com`` branch are more likely to be compatible
224
+
with the ``latest`` CLI, so you'll be less likely to have to upgrade
225
+
newly-created databases than if you use the ``main`` branch. Older databases
226
+
may need to be upgraded before you can analyze them.
227
+
228
+
- For the most up to date CodeQL queries, check out the ``main`` branch.
229
+
This branch represents the very latest version of CodeQL's analysis. Even
230
+
databases created using the most recent version of the CLI may have to be
231
+
upgraded before you can analyze them. For more information, see
0 commit comments