Skip to main content

About setup types for code scanning

Depending on your needs, GitHub offers a default or advanced setup for code scanning.

本文内容

About default setup

Default setup for code scanning is the quickest, easiest, most low-maintenance way to enable code scanning for your repository. Based on the code in your repository, default setup will automatically create a custom code scanning configuration. After enabling default setup, the code written in CodeQL-supported languages in your repository will be scanned:

  • On each push to the repository's default branch, or any protected branch. For more information on protected branches, see 关于受保护分支.
  • When creating or committing to a pull request based against the repository's default branch, or any protected branch, excluding pull requests from forks.
  • On a weekly schedule.

If you need more granular control over your code scanning configuration, you should instead configure advanced setup.

Supported languages

如果符合条件的存储库将来可能至少包含一种 CodeQL 支持的语言,我们建议为这些存储库启用默认设置。 如果在不包含任何 CodeQL 支持的语言的存储库上启用默认设置,则默认设置将不会运行任何扫描或使用任何 GitHub Actions 分钟。 如果将 CodeQL 支持的语言添加到仓库的默认分支,则默认设置将自动开始扫描 CodeQL 支持的语言,并使用 GitHub Actions 分钟。 有关 CodeQL 支持的语言的详细信息,请参阅“关于使用 CodeQL 进行代码扫描”。

If the code in a repository changes to include any CodeQL-supported languages, GitHub will automatically update the code scanning configuration to include the new language. If code scanning fails with the new configuration, GitHub will resume the previous configuration automatically so the repository does not lose code scanning coverage.

Available runners

You can use default setup for all CodeQL-supported languages on self-hosted runners or GitHub-hosted runners.

You can assign self-hosted runners for default setup by giving the runners the default code-scanning label, or you can optionally give them custom labels so that individual repositories can use different runners.

Unless you have a specific use case, we recommend that you only assign runners with the default code-scanning label. However, you may want to use custom labels to:

  • Assign more powerful self-hosted runners to critical repositories for faster code scanning analysis.
  • Run your code scanning analyses on a particular platform (for example, macOS).
  • Have granular control over the workload for your GitHub-hosted runners and self-hosted runners.

About advanced setup

Advanced setup for code scanning is helpful when you need to customize your code scanning. By creating and editing a workflow file, you can define how to build compiled languages, choose which queries to run, select the languages to scan, use a matrix build, and more. You also have access to all the options for controlling workflows, for example: changing the scan schedule, defining workflow triggers, specifying specialist runners to use.

You can also configure code scanning with third-party tools.

如果使用多个配置运行代码扫描,则警报有时会有多个分析源。 如果警报有多个分析源,你可在警报页上查看每个分析源的警报状态。 有关详细信息,请参阅“关于代码扫描警报”。

Next steps

You can enable default setup for a single repository, multiple repositories, or all repositories in an organization at the same time.

To configure advanced setup instead, see 配置代码扫描的高级设置.