メモ
この記事では、このバージョンの GitHub Enterprise Server の初期リリースに含まれる CodeQL アクションのバージョンおよび関連する CodeQL CLI バンドルで使用できる機能について説明します。 エンタープライズでより新しいバージョンの CodeQL アクションを使用する場合は、この記事の GitHub Enterprise Cloud バージョンで最新の機能に関する情報を参照してください。 最新バージョンの使用方法については、「アプライアンス用コードスキャンの構成」を参照してください。
There are several approaches you can try to reduce the build time in a code scanning analysis.
Increase the memory or cores
You can increase the memory or disk space available on your runners. If you're using CodeQL for your code scanning analysis, you can review the recommended hardware resources for CodeQL to make sure your runners meet those requirements. For more information, see CodeQL を実行するための推奨ハードウェア リソース.
Use matrix builds to parallelize the analysis
To speed up analysis of workflows that involve multiple jobs, you can modify your workflow to use a matrix. For more information, see ワークフローでのジョブのバリエーションの実行.
The default CodeQL 分析ワークフロー uses a matrix of languages, which causes the analysis of each language to run in parallel. However, if you're using CodeQL with advanced setup and you have specified the languages you want to analyze directly in the "Initialize CodeQL" step, analysis of each language will happen sequentially. In this configuration, you can speed up your analysis by modifying your advanced setup workflow to use a matrix. For an example, see the workflow extract in Some languages were not analyzed with CodeQL advanced setup.
Reduce the amount of code being analyzed in a single workflow
Analysis time is typically proportional to the amount of code being analyzed. If you're using CodeQL with advanced setup, you can reduce the analysis time by reducing the amount of code being analyzed at once. For example, by excluding test code, or breaking analysis into multiple workflows that analyze only a subset of your code at a time.
build-mode: autobuildまたはbuild-mode: manualを使用する場合、Java、Kotlin、Go、C、C++、C# などのコンパイル済み言語の場合、CodeQL はワークフロー実行中にビルドされたすべてのコードを分析します。 分析するコードの量を制限するには、run ブロックで独自のビルド ステップを指定して、分析するコードのみをビルドします。 独自のビルド ステップの指定と、paths イベントや paths-ignore イベントでの pull_request フィルターまたは push フィルターの使用を組み合わせることで、特定のコードが変更されたときにのみワークフローが実行されるようにすることができます。 詳しくは、「GitHub Actions のワークフロー構文」をご覧ください。
JavaScript、Python、TypeScript などの言語の場合、CodeQL はソース コードをコンパイルせずに分析します。また、 build-mode: noneを使用してコンパイルされた言語の場合は、分析するコードの量を制限する追加の構成オプションを指定できます。 詳しくは、「コード スキャン用の高度なセットアップのカスタマイズ」をご覧ください。
If you split your CodeQL analysis into multiple workflows, we still recommend that you have at least one workflow which runs on a schedule which analyzes all of the code in your repository. Because CodeQL analyzes data flows between components, some complex security behaviors may only be detected on a complete build.
Run only during a schedule event
You may find that your analysis is slow during push or pull_request events. If so, you can set your analysis to only trigger on the schedule event. If you're using CodeQL for your code scanning analysis, you can configure this with an advanced setup workflow, but not in default setup. For more information, see GitHub Actions を理解する.
Check which queries or rules the workflow runs
Another option to reduce analysis time is to run only the queries or rules that you consider critical in workflows that run on pull requests. If you use a third-party tool for code scanning, you should refer to the documentation for the tool.
In CodeQL, there are two main query suites available for each language. If you have optimized the CodeQL database build and the process is still too long, you could reduce the number of queries you run. The default query suite is run automatically: it provides the best possible compromise between quality and speed.
If you're using CodeQL with advanced setup, you may be running extra queries or query suites in addition to the default queries. Check whether the workflow defines an additional query suite or additional queries to run using the queries element. You can experiment with disabling the additional query suite or queries. For more information, see コード スキャン用の高度なセットアップのカスタマイズ.