ja ドキュメントには頻繁に更新が加えられ、その都度公開されています。本ページの翻訳はまだ未完成な部分があることをご了承ください。最新の情報については、英語のドキュメンテーションをご参照ください。本ページの翻訳に問題がある場合はこちらまでご連絡ください。

Enabling code scanning for a repository

プロジェクトのリポジトリで code scanning を有効化できます。

If you have write permissions to a repository, you can enable code scanning for that repository.

Code scanning is available for all public repositories and for private repositories owned by organizations where GitHub Advanced Security is enabled. 詳しい情報については、「GitHub Advanced Security について」を参照してください。


Options for enabling code scanning

You decide how you generate code scanning alerts, and which tools you use, at a repository level. GitHub provides fully integrated support for CodeQL analysis, and also supports analysis using third-party tools. 詳しい情報については、「CodeQL について」を参照してください。

Type of analysis Options for generating alerts
CodeQL Using GitHub Actions (see "Enabling code scanning using actions") or using the CodeQL runner in a third-party continuous integration (CI) system (see "Running code scanning in your CI system").
Third‑party Using GitHub Actions (see "Enabling code scanning using actions") or generated externally and uploaded to GitHub (see "Uploading a SARIF file to GitHub").

Enabling code scanning using actions

Using actions to run code scanning will use minutes. 詳しい情報については、「GitHub Actionsの支払いについて」を参照してください。

  1. GitHubで、リポジトリのメインページにアクセスしてください。

  2. リポジトリ名の下で Security(セキュリティ)をクリックしてください。


  3. To the right of "Code scanning", click Set up code scanning.

    "Set up code scanning" button to the right of "Code scanning" in the Security Overview

  4. Under "Get started with code scanning", click Set up this workflow on the CodeQL analysis workflow or on a third-party workflow.

    "Set up this workflow" button under "Get started with code scanning" heading

  5. To customize how code scanning scans your code, edit the workflow.

    Generally you can commit the CodeQL analysis workflow without making any changes to it. However, many of the third-party workflows require additional configuration, so read the comments in the workflow before committing.

    詳しい情報については、「code scanning を設定する」を参照してください。

  6. [Start commit] ドロップダウンを使用して、コミットメッセージを入力します。


  7. デフォルトブランチに直接コミットするか、新しいブランチを作成してプルリクエストを開始するかを選択します。


  8. [Commit new file] または [Propose new file] をクリックします。

In the default CodeQL analysis workflow, code scanning is configured to analyze your code each time you either push a change to the default branch or any protected branches, or raise a pull request against the default branch. As a result, code scanning will now commence.

Bulk enabling code scanning

You can enable code scanning in many repositories in bulk using a script. For an example of a script that raises pull requests to add a GitHub Actions workflow to multiple repositories, see the jhutchings1/Create-ActionsPRs repository.

Viewing the logging output from code scanning

After enabling code scanning for your repository, you can watch the output of the actions as they run.

  1. リポジトリ名の下でActions(アクション)をクリックしてください。


    You'll see a list that includes an entry for running the code scanning workflow. The text of the entry is the title you gave your commit message.

    Actions list showing code scanning workflow

  2. Click the entry for the code scanning workflow.

  3. Click the job name on the left. For example, Analyze (LANGUAGE).

    Log output from the code scanning workflow

  4. Review the logging output from the actions in this workflow as they run.

  5. Once all jobs are complete, you can view the details of any code scanning alerts that were identified. For more information, see "Managing code scanning alerts for your repository."

Note: If you raised a pull request to add the code scanning workflow to the repository, alerts from that pull request aren't displayed directly on the Code scanning page until the pull request is merged. If any alerts were found you can view these, before the pull request is merged, by clicking the n alerts found link in the banner on the Code scanning page.

Click the "n alerts found" link

Understanding the pull request checks

Each code scanning workflow you enable to run on pull requests always has at least two entries listed in the checks section of a pull request. There is one entry for each of the analysis jobs in the workflow, and a final one for the results of the analysis.

The names of the code scanning analysis checks take the form: "TOOL NAME / JOB NAME (TRIGGER)." For example, for CodeQL, analysis of C++ code has the entry "CodeQL / Analyze (cpp) (pull_request)." You can click Details on a code scanning analysis entry to see logging data. This allows you to debug a problem if the analysis job failed. For example, for code scanning analysis of compiled languages, this can happen if the action can't build the code.

code scanning pull request checks

When the code scanning jobs complete, GitHub works out whether any alerts were added by the pull request and adds the "Code scanning results / TOOL NAME" entry to the list of checks. After code scanning has been performed at least once, you can click Details to view the results of the analysis. If you used a pull request to add code scanning to the repository, you will initially see a "Missing analysis" message when you click Details on the "Code scanning results / TOOL NAME" check.

Missing analysis for commit message

Reasons for the "missing analysis" message

After code scanning has analyzed the code in a pull request, it needs to compare the analysis of the topic branch (the branch you used to create the pull request) with the analysis of the base branch (the branch into which you want to merge the pull request). This allows code scanning to compute which alerts are newly introduced by the pull request, which alerts were already present in the base branch, and whether any existing alerts are fixed by the changes in the pull request. Initially, if you use a pull request to add code scanning to a repository, the base branch has not yet been analyzed, so it's not possible to compute these details. In this case, when you click through from the results check on the pull request you will see the "Missing analysis for base commit SHA-HASH" message.

There are other situations where there may be no analysis for the latest commit to the base branch for a pull request. These include:

  • The pull request has been raised against a branch other than the default branch, and this branch hasn't been analyzed.

    To check whether a branch has been scanned, go to the Code scanning page, click the Branch drop-down and select the relevant branch.

    Choose a branch from the Branch drop-down menu

    The solution in this situation is to add the name of the base branch to the on:push and on:pull_request specification in the code scanning workflow on that branch and then make a change that updates the open pull request that you want to scan.

  • The latest commit on the base branch for the pull request is currently being analyzed and analysis is not yet available.

    Wait a few minutes and then push a change to the pull request to retrigger code scanning.

  • An error occurred while analyzing the latest commit on the base branch and analysis for that commit isn't available.

    Merge a trivial change into the base branch to trigger code scanning on this latest commit, then push a change to the pull request to retrigger code scanning.


After enabling code scanning, and allowing its actions to complete, you can:

Did this doc help you?

Privacy policy

Help us make these docs great!

All GitHub docs are open source. See something that's wrong or unclear? Submit a pull request.

Make a contribution

OR, learn how to contribute.