About the CodeQL analysis workflow and compiled languages
You set up GitHub to run code scanning for your repository by adding a GitHub Actions workflow to the repository. Note: This article refers to code scanning powered by CodeQL, not to code scanning resulting from the upload of third-party static analysis tools. For more information, see "Setting up code scanning for a repository."
通常、code scanning のデフォルトのワークフローを編集する必要はありません。 However, if required, you can edit the workflow to customize some of the settings. For example, you can edit GitHub's CodeQL analysis workflow to specify the frequency of scans, the languages or directories to scan, and what CodeQL code scanning looks for in your code. You might also need to edit the CodeQL analysis workflow if you use a specific set of commands to compile your code. For general information about configuring code scanning and editing workflow files, see "Configuring code scanning" and "Learn GitHub Actions."
CodeQL の autobuild について
Code scanning works by running queries against one or more databases. Each database contains a representation of all of the code in a single language in your repository. For the compiled languages C/C++, C#, and Java, the process of populating this database involves building the code and extracting data. CodeQL also runs a build for Go projects to set up the project. However, in contrast to the other compiled languages, all Go files in the repository are extracted, not just those that are built. Custom build commands are not supported for Go.
For the supported compiled languages, you can use the autobuild
action in the CodeQL analysis workflow to build your code. This avoids you having to specify explicit build commands for C/C++, C#, and Java.
If your workflow uses a language
matrix, autobuild
attempts to build each of the compiled languages listed in the matrix. Without a matrix autobuild
attempts to build the supported compiled language that has the most source files in the repository. With the exception of Go, analysis of other compiled languages in your repository will fail unless you supply explicit build commands.
注釈: GitHub Actions にセルフホストランナーを使用する場合、autobuild
プロセスを使用するために追加のソフトウェアをインストールする必要がある場合があります。 さらに、リポジトリに特定のバージョンのビルドツールが必要な場合は、手動でインストールする必要があります。 詳しい情報については、「GitHub ホストランナーの仕様」を参照してください。
C/C++
サポートされているシステムの種類 | システム名 |
---|---|
オペレーティングシステム | Windows, macOS, and Linux |
ビルドシステム | Windows: MSbuild and build scripts Linux and macOS: Autoconf, Make, CMake, qmake, Meson, Waf, SCons, Linux Kbuild, and build scripts |
autobuild
ステップの動作は、抽出を実行するオペレーティングシステムによって異なります。 On Windows, the autobuild
step attempts to autodetect a suitable build method for C/C++ using the following approach:
- Invoke
MSBuild.exe
on the solution (.sln
) or project (.vcxproj
) file closest to the root.autobuild
が最上位ディレクトリから同じ(最短)深度で複数のソリューションまたはプロジェクトファイルを検出した場合、それらすべてをビルドしようとします。 - Invoke a script that looks like a build script—build.bat, build.cmd, and build.exe (in that order).
On Linux and macOS, the autobuild
step reviews the files present in the repository to determine the build system used:
- ルートディレクトリでビルドシステムを探します。
- 何も見つからない場合は、C/C++ のビルドシステムで一意のディレクトリをサブディレクトリで検索します。
- 適切なコマンドを実行してシステムを設定します。
C
サポートされているシステムの種類 | システム名 |
---|---|
オペレーティングシステム | Windows、Linux |
ビルドシステム | .NET と MSbuild、およびビルドスクリプト |
autobuild
プロセスは、次のアプローチを使用して C# に適したビルドメソッドを自動検出しようとします。
- ルートに最も近いソリューション(
.sln
)またはプロジェクト(.csproj
)ファイルでdotnet build
を呼び出します。 - ルートに最も近いソリューションまたはプロジェクトファイルで
MSbuild
(Linux)またはMSBuild.exe
(Windows)を呼び出します。autobuild
が最上位ディレクトリから同じ(最短)深度で複数のソリューションまたはプロジェクトファイルを検出した場合、それらすべてをビルドしようとします。 - ビルドスクリプトのように見えるスクリプト、つまり build と build.sh(Linux の場合、この順序で)または build.bat、build.cmd、および build.exe(Windows の場合、この順序で)を呼び出します。
Java
サポートされているシステムの種類 | システム名 |
---|---|
オペレーティングシステム | Windows, macOS, and Linux (no restriction) |
ビルドシステム | Gradle、Maven、Ant |
autobuild
プロセスは、この戦略を適用して Java コードベースのビルドシステムを決定しようとします。
- ルートディレクトリでビルドファイルを検索します。 Gradle、Maven、Ant の各ビルドファイルを確認します。
- 最初に見つかったビルドファイルを実行します。 Gradle ファイルと Maven ファイルの両方が存在する場合は、Gradle ファイルが使用されます。
- それ以外の場合は、ルートディレクトリの直接サブディレクトリ内でビルドファイルを検索します。 1 つのサブディレクトリにのみビルドファイルが含まれている場合は、そのサブディレクトリで識別された最初のファイルを実行します(1 と同じ環境設定を使用)。 複数のサブディレクトリにビルドファイルが含まれている場合は、エラーを報告します。
コンパイル言語のビルドステップを追加する
If the C/C++, C#, or Java code in your repository has a non-standard build process, autobuild
may fail. You will need to remove the autobuild
step from the workflow, and manually add build steps. For information on how to edit the workflow file, see "Configuring code scanning."
autobuild
ステップを削除した後、run
ステップのコメントを外して、リポジトリに適したビルドコマンドを追加します。 ワークフロー run
ステップは、オペレーティングシステムのシェルを使用してコマンドラインプログラムを実行します。 これらのコマンドを変更し、さらにコマンドを追加して、ビルドプロセスをカスタマイズできます。
- run: |
make bootstrap
make release
run
キーワードに関する詳しい情報については、「"GitHub Actionsのためのワークフローの構文」を参照してください。
If your repository contains multiple compiled languages, you can specify language-specific build commands. For example, if your repository contains C/C++, C# and Java, and autobuild
correctly builds C/C++ and C# but fails to build Java, you could use the following configuration in your workflow, after the init
step. This specifies build steps for Java while still using autobuild
for C/C++ and C#:
- if: matrix.language == 'cpp' || matrix.language == 'csharp'
name: Autobuild
uses: github/codeql-action/autobuild@v1
- if: matrix.language == 'java'
name: Build Java
run: |
make bootstrap
make release
For more information about the if
conditional, see "Workflow syntax for GitHub Actions."
For more tips and tricks about why autobuild
won't build your code, see "Troubleshooting the CodeQL workflow."
If you added manual build steps for compiled languages and code scanning is still not working on your repository, contact GitHub Support or GitHub Premium Support.