Some users prefer working with CodeQL query sources directly in order to work on or contribute to open source shared queries.
1. Download the CodeQL CLI tar archive
El paquete de descarga de la CodeQL CLI es un archivo tar que contiene herramientas, scripts y varios archivos específicos de CodeQL. Si no tienes una licencia de GitHub Enterprise, al descargar este archivo aceptas los términos y condiciones de GitHub CodeQL.
Debes descargar el conjunto de CodeQL desde https://github.com/github/codeql-action/releases. La agrupación contiene lo siguiente:
- El producto de CodeQL CLI
- Una versión compatible de las consultas y bibliotecas de https://github.com/github/codeql
- Versiones precompiladas de todas las consultas incluidas en la agrupación
Nota:
Para GitHub Enterprise Server 3.20, se recomienda la versión de CodeQL CLI 2.23.9.
Debe usar siempre el conjunto de CodeQL. Esto garantiza la compatibilidad y también da un rendimiento mucho mejor que una descarga independiente del CodeQL CLI y una verificación de las consultas de CodeQL. Si solo vas a ejecutar la CLI en una plataforma específica, descarga el archivo codeql-bundle-PLATFORM.tar.zst adecuado. Como alternativa, puedes descargar codeql-bundle.tar.zst, que contiene la CLI para todas las plataformas compatibles.
También hay variantes tar.gz del conjunto, que son idénticas a las variantes tar.zst, excepto que se comprimen mediante el algoritmo gzip menos eficaz. La única razón para descargar las variantes tar.gz es si usa herramientas de descompresión anteriores que no admiten el algoritmo de compresión Zstandard.
2. Create a new CodeQL directory
Create a new directory where you can place the CLI and any queries and libraries
you want to use. For example, $HOME/codeql-home.
The CLI’s built-in search operations automatically look in all of its sibling directories for the files used in database creation and analysis. Keeping these components in their own directory prevents the CLI searching unrelated sibling directories while ensuring all files are available without specifying any further options on the command line.
3. Obtain a local copy of the CodeQL queries
The CodeQL repository contains
the queries and libraries required for CodeQL analysis of all supported languages.
Clone a copy of this repository into codeql-home.
By default, the root of the cloned repository will be called codeql.
Rename this folder codeql-repo to avoid conflicting with the CodeQL CLI that you will extract in step 1. If you use git on the command line, you can
clone and rename the repository in a single step by running
git clone [email protected]:github/codeql.git codeql-repo in the codeql-home folder.
Within this repository, the queries and libraries are organized into CodeQL packs. Along with the queries themselves, CodeQL packs contain important metadata that tells the CodeQL CLI how to process the query files. For more information, see Creación y uso de paquetes de CodeQL.
Nota:
There are different versions of the CodeQL queries available for different users. Check out the correct version for your use case:
- For the queries that are intended to be used with the latest CodeQL CLI release, check out the branch tagged
codeql-cli/latest. You should use this branch for databases you’ve built using the CodeQL CLI or recently downloaded from GitHub. - For the most up to date CodeQL queries, check out the
mainbranch. This branch represents the very latest version of CodeQL’s analysis.
4. Extract the CodeQL CLI tar archive
Extract the tar archive into the directory you created in step 2.
For example, if the path to your copy of the CodeQL repository is $HOME/codeql-home/codeql-repo, then extract the CLI into
$HOME/codeql-home/.
5. Launch codeql
Una vez extraído, puedes ejecutar procesos de CodeQL mediante el archivo ejecutable codeql de dos maneras:
- Ejecutando
<extraction-root>/codeql/codeql, donde<extraction-root>es la carpeta en la que has extraído el paquete de la CodeQL CLI. - Agregando
<extraction-root>/codeqlaPATH, para poder ejecutar el archivo ejecutable simplemente comocodeql.
A partir de este momento, ya puedes ejecutar comandos de CodeQL. Para ver una lista completa de los comandos de CodeQL CLI, consulta Manual de comandos de la CLI de CodeQL.
6. Verify your CodeQL CLI setup
CodeQL CLI has subcommands you can execute to verify that you are correctly set up to create and analyze databases:
- Run
codeql resolve languagesto show which languages are available for database creation. This will list the languages supported by default in your CodeQL CLI package. - Run
codeql resolve qlpacksto show which CodeQL packs the CLI can find. This will display the names of all the CodeQL packs directly available to the CodeQL CLI. This should include:- Query packs for each supported language, for example,
codeql/{language}-queries. These packs contain the standard queries that will be run for each analysis. - Library packs for each supported language, for example,
codeql/{language}-all. These packs contain query libraries, such as control flow and data flow libraries, that may be useful to query writers. - Example packs for each supported language, for example,
codeql/{language}-examples. These packs contain useful snippets of CodeQL that query writers may find useful. - Legacy packs that ensure custom queries and libraries created using older products are compatible with your version of CodeQL.
- Query packs for each supported language, for example,