Publicamos atualizações frequentes em nossa documentação, e a tradução desta página ainda pode estar em andamento. Para obter as informações mais recentes, acesse a documentação em inglês. Se houver problemas com a tradução desta página, entre em contato conosco.

Enabling code scanning for a repository

You can enable Varredura de código for your project's repository.

If you have write permissions to a repository, you can enable Varredura de código for that repository.

Varredura de código is available if you have an Segurança Avançada license.

Neste artigo

Nota: Varredura de código está atualmente em versão beta e sujeito a alterações. Para obter mais informações sobre a participação no beta, inscreva-se aqui.

Observação: O administrador do site deve habilitar Varredura de código para your GitHub Enterprise Server instance antes de usar este recurso. Se você desejar usar o GitHub Actions para fazer a varredura do seu código, o administrador do site também deverá habilitar o GitHub Actions e configurar a infraestrutura necessária. Para obter mais informações, consulte "Configurar o Varredura de código para seu aplicativo ".

Options for enabling Varredura de código

You decide how you generate Varredura de código alerts, and which tools you use, at a repository level. GitHub Enterprise Server provides fully integrated support for CodeQL analysis, and also supports analysis using third-party tools. For more information, see "About CodeQL."

Tipo de análise Opções para gerar alertas
CodeQL Usar GitHub Actions (consulte "Habilitar Varredura de código usando ações") ou usar o Executor do CodeQL em um sistema contínuo de integração contínua (CI) de terceiros (consulte "Varrendo o código em execução no seu sistema de CI").
Third‑party Usar GitHub Actions (consulte "Habilitar Varredura de código usando ações") ou geradas externamente e subidas em GitHub Enterprise Server (consulte "Fazer upload de um arquivo SARIF em GitHub").

Enabling Varredura de código using actions

  1. No GitHub Enterprise Server, navegue até a página principal do repositório.

  2. No seu nome de repositório, clique em Segurança.

    Guia de segurança

  3. To the right of "Varredura de código", click Set up Varredura de código.

    "Set up Varredura de código" button to the right of "Varredura de código" in the Security Overview

  4. Under "Get started with Varredura de código", click Set up this workflow on the Fluxo de trabalho de análise do CodeQL or on a third-party workflow.

    "Set up this workflow" button under "Get started with Varredura de código" heading

  5. To customize how Varredura de código scans your code, edit the workflow.

    Generally you can commit the Fluxo de trabalho de análise do CodeQL 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.

    For more information, see "Configuring Varredura de código."

  6. Use the Start commit drop-down, and type a commit message.

    Start commit

  7. Choose whether you'd like to commit directly to the default branch, or create a new branch and start a pull request.

    Choose where to commit

  8. Click Commit new file or Propose new file.

In the default Fluxo de trabalho de análise do CodeQL, Varredura de código 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, Varredura de código will now commence.

Viewing the logging output from Varredura de código

After enabling Varredura de código for your repository, you can watch the output of the actions as they run.

  1. No nome do seu repositório, clique em Ações.

    Aba Ações na navegação principal do repositório

    You'll see a list that includes an entry for running the Varredura de código workflow.

    Actions list showing Varredura de código workflow

  2. Click the entry for the Varredura de código workflow.

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

    Log output from the Varredura de código 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 Varredura de código alerts that were identified. For more information, see "Managing Varredura de código alerts for your repository."

Note: If you raised a pull request to add the Varredura de código workflow to the repository, alerts from that pull request aren't displayed directly on the Varredura de código 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 Varredura de código page.

Click the "n alerts found" link

Understanding the pull request checks

Each Varredura de código 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 Varredura de código 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 Varredura de código analysis entry to see logging data. This allows you to debug a problem if the analysis job failed. For example, for Varredura de código analysis of compiled languages, this can happen if the action can't build the code.

Varredura de código pull request checks

When the Varredura de código jobs complete, GitHub works out whether any alerts were added by the pull request and adds the "Varredura de código results / TOOL NAME" entry to the list of checks. After Varredura de código 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 Varredura de código to the repository, you will initially see a "Missing analysis" message when you click Details on the "Varredura de código results / TOOL NAME" check.

Missing analysis for commit message

Reasons for the "missing analysis" message

After Varredura de código 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 Varredura de código 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 Varredura de código 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 Varredura de código 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 Varredura de código 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 Varredura de código.

  • 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 Varredura de código on this latest commit, then push a change to the pull request to retrigger Varredura de código.

Next steps

After enabling Varredura de código, and allowing its actions to complete, you can:

Esse documento ajudou você?

Privacy policy

Ajude-nos a tornar esses documentos ótimos!

Todos os documentos do GitHub são de código aberto. Você percebeu que algo que está errado ou não está claro? Envie um pull request.

Faça uma contribuição

Ou, aprenda como contribuir.