Skip to content

Commit 8c3595e

Browse files
mchammer01CopilotCopilotCopilotmyarb
authored
Code Coverage automatic enablement (Code Quality) [GA] (#61587)
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Melanie Yarbrough <11952755+myarb@users.noreply.github.com> Co-authored-by: AlonaHlobina <54394529+AlonaHlobina@users.noreply.github.com> Copilot-Session: cc516c8e-bdeb-4490-85c3-6ef91946419a
1 parent e3f2076 commit 8c3595e

6 files changed

Lines changed: 97 additions & 7 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
title: Automatic code coverage setup
3+
shortTitle: Automatic code coverage
4+
intro: 'An AI-powered agent can analyze your repository and generate a working code coverage workflow, so you can start tracking test coverage without manually authoring CI configuration.'
5+
versions:
6+
feature: code-quality
7+
product: '{% data reusables.gated-features.code-quality-availability %}'
8+
contentType: concepts
9+
category:
10+
- Improve code quality
11+
---
12+
13+
When you use automatic setup for code coverage, an AI-powered agent analyzes your repository, identifies your test framework, and opens a pull request with a coverage workflow ready for review.
14+
15+
**There is no additional cost for using this feature.**
16+
17+
## How the agent works
18+
19+
The agent works in three phases:
20+
21+
1. **Discovery:** The agent reads your CI configuration, documentation, and build files to understand your project structure and identify your test framework.
22+
1. **Execution:** The agent installs dependencies, builds the project, and runs your tests with coverage enabled. If coverage tooling is not already configured, the agent adds it to your project configuration (for example, `vitest.config.ts` or `jest.config.js`).
23+
1. **Workflow integration:** If the agent produces a valid coverage report, it checks whether your repository already has a {% data variables.product.prodname_actions %} workflow that runs tests on pull requests. If so, the agent augments that workflow with a coverage upload step. If not, it creates a new workflow file and opens a pull request.
24+
25+
## When the agent stops
26+
27+
The agent may stop before opening a pull request in the following situations:
28+
29+
* **No tests found.** The agent couldn't find tests to instrument, so there's nothing to generate coverage for.
30+
* **Can't reproduce the build.** Missing private registries, proprietary SDKs, or system dependencies prevent the agent from verifying the test suite.
31+
32+
If the agent stops or produces unexpected results, you can review the agent's session log for details. Navigate to the **Tasks** tab in your repository to find the session associated with the workflow generation attempt.
33+
* **Unsupported coverage report conversion.** The agent won't reconstruct Cobertura XML from reports that only expose aggregated counters. For example, JaCoCo XML does not contain enough line and branch structure for a trustworthy Cobertura upload, so JVM projects that only produce JaCoCo XML may need manual setup instead.
34+
## Pull request outcomes
35+
36+
> [!NOTE]
37+
> The agent opens the pull request immediately with an initial planning commit that contains no code changes. The actual implementation commit typically arrives a few minutes later. If the pull request initially shows 0 changed files, wait a few minutes and refresh the page.
38+
39+
If the agent successfully opens a pull request, the pull request may be in one of these states:
40+
41+
* **Mergeable as-is:** The workflow completes successfully in CI and coverage uploads correctly.
42+
* **Ready to iterate:** The workflow runs but requires adjustments (for example, missing secrets, self-hosted runner configuration, or path differences between local verification and CI).
43+
* **Useful as a reference:** Maintainers may prefer to configure coverage themselves, using the agent's pull request as a starting point for the build and test commands it discovered.
44+
45+
## Further reading
46+
47+
* [AUTOTITLE](/code-security/how-tos/maintain-quality-code/set-up-code-coverage#automatic-setup)
48+
* [AUTOTITLE](/code-security/concepts/code-quality/code-quality)

content/code-security/concepts/code-quality/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ contentType: concepts
88
children:
99
- /code-quality
1010
- /enablement-at-scale
11+
- /automatic-code-coverage-setup
1112
---

content/code-security/how-tos/maintain-quality-code/enable-code-quality.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,5 @@ If you're rolling out the feature across many teams, we recommend you pilot on a
5959

6060
## Next steps
6161

62-
* **Add code coverage:** Upload reported code coverage from your test suite to see coverage results directly on pull requests. See [AUTOTITLE](/code-security/how-tos/maintain-quality-code/set-up-code-coverage).
62+
* **Add code coverage:** Upload reported code coverage from your test suite to see coverage results directly on pull requests. {% data reusables.code-quality.workflow-generation %}
6363
* **For your organization:** Understand the code health of your repositories at a glance. See [AUTOTITLE](/code-security/how-tos/maintain-quality-code/explore-code-quality).

content/code-security/how-tos/maintain-quality-code/set-up-code-coverage.md

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,55 @@ category:
1414
- Improve code quality
1515
---
1616

17+
You can set up code coverage for your repository in two ways:
18+
19+
* **Automatic setup:** Use the AI-powered agent to generate a workflow automatically. Choose this option if:
20+
* You want to get started quickly without writing YAML configuration.
21+
* Your project uses common test frameworks and build patterns.
22+
* You're comfortable iterating on an AI-generated workflow.
23+
* **Manual setup:** Configure your CI workflow yourself. Choose this option if:
24+
* You need precise control over the coverage process.
25+
* You have complex CI requirements (such as private registries or custom build steps).
26+
* You want to understand exactly how coverage is configured.
27+
28+
## Automatic setup
29+
30+
You can use the automatic setup option to generate a working code coverage workflow without manually authoring CI configuration. An agent analyzes your repository, identifies your test framework, and opens a pull request with a coverage workflow ready for review.
31+
32+
> [!NOTE]
33+
> Automatic setup uses AI to generate the workflow file. There is no additional cost for using this feature.
34+
35+
### Prerequisites for automatic setup
36+
37+
* {% data variables.product.prodname_code_quality_short %} is enabled for your repository. See [AUTOTITLE](/code-security/how-tos/maintain-quality-code/enable-code-quality).
38+
* Your repository has an existing test suite.
39+
40+
### Generating a coverage workflow automatically
41+
42+
{% data reusables.repositories.navigate-to-repo %}
43+
{% data reusables.repositories.sidebar-settings %}
44+
1. In the sidebar, under "Security", click **{% data variables.code-quality.code_quality_ui_settings %}** to display the "{% data variables.code-quality.code_quality_ui %}" page.
45+
1. In the "Code coverage analysis" section, click the **Setup** dropdown box.
46+
1. In the list, select **Generate workflow with AI**. Wait for the agent to analyze your repository. The agent opens a draft pull request and posts a checklist of the steps it is working through.
47+
1. To review the pull request, click **Review pull request**.
48+
Review the pull request once the agent completes its work. The pull request description summarizes the changes, including any project configuration updates, workflow file changes, and coverage output settings.
49+
1. If the workflow runs successfully in CI and coverage uploads correctly, merge the pull request.
50+
51+
If the workflow needs adjustments, see [AUTOTITLE](/code-security/concepts/code-quality/automatic-code-coverage-setup) for guidance on the different outcomes and how to iterate.
52+
53+
For more information about how the agent works and what to expect, see [AUTOTITLE](/code-security/concepts/code-quality/automatic-code-coverage-setup).
54+
55+
## Manual setup
56+
1757
Built-in code coverage lets you track how thoroughly your tests exercise your code, without adding a third-party service to your toolchain or budget. In the following procedures, you will generate a Cobertura XML coverage report from your test suite, upload it to {% data variables.product.github %}, and view the coverage results on your pull requests.
1858

19-
## Prerequisites
59+
### Prerequisites for manual setup
2060

2161
* {% data variables.product.prodname_code_quality_short %} is enabled for your repository.
2262
* Your repository has a test suite that runs in {% data variables.product.prodname_actions %}.
2363
* Your test framework can produce a coverage report in **Cobertura XML** format.
2464

25-
## Step 1: Generate a Cobertura XML coverage report
65+
### Step 1: Generate a Cobertura XML coverage report
2666

2767
Configure your test framework to output a coverage report in the Cobertura XML format. Code coverage works with any programming language that can produce this format.
2868

@@ -40,7 +80,7 @@ Configure your test framework to output a coverage report in the Cobertura XML f
4080
> [!TIP]
4181
> If your framework isn't listed above, check its documentation for Cobertura output support. Many tools either support it directly or can convert to Cobertura XML from other formats.
4282
43-
## Step 2: Upload the coverage report
83+
### Step 2: Upload the coverage report
4484

4585
After your tests generate a Cobertura XML report, upload it to {% data variables.product.github %} so coverage results appear on pull requests.
4686

@@ -117,7 +157,7 @@ jobs:
117157
label: code-coverage/pytest
118158
```
119159
120-
## Step 3: View coverage results on pull requests
160+
### Step 3: View coverage results on pull requests
121161
122162
1. Open a pull request (or push to an existing one) that triggers the workflow you configured.
123163
1. After the workflow completes, look for a comment from `{% data variables.code-quality.pr_commenter %}` on the pull request. The comment includes:

content/code-security/responsible-use/security-and-quality-ai-features.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ GitHub's security and quality platform includes several AI-powered capabilities
4040
* **Copilot Autofix for code scanning**: Automatically generates fix suggestions for CodeQL alerts on pull requests and the default branch.
4141
* **Generic secret detection**: Uses a model to identify unstructured secrets in source code that deterministic pattern matching cannot find.
4242
* **Custom pattern regex generator**: Uses AI to generate regular expressions for custom secret scanning patterns from natural language descriptions.
43-
* **GitHub Code Quality**: Surfaces code quality issues and offers LLM-powered fix suggestions on pull requests and the default branch.
43+
* **GitHub Code Quality**: Surfaces code quality issues and offers LLM-powered fix suggestions on pull requests and the default branch. Also provides AI-powered automatic generation of code coverage workflows.
4444

4545
Copilot Autofix is an expansion of code scanning that provides users with targeted recommendations to help them fix code scanning alerts, avoiding the introduction of new security vulnerabilities. Potential fixes are generated automatically by large language models (LLMs) using data from the codebase and from code scanning analysis. Copilot Autofix is available for CodeQL analysis and does not require a GitHub Copilot subscription.
4646

@@ -50,7 +50,7 @@ Secret scanning's generic secret detection is an AI-powered expansion of secret
5050

5151
Secret scanning's custom pattern regular expression generator makes it possible to define custom secret scanning patterns without knowledge of regular expressions. Users input a natural language description of what they want to detect, along with optional example strings, and the generator produces up to three candidate regular expressions. These patterns can then be validated via the dry-run mechanism before being deployed as custom patterns. The regular expression generator does not require a GitHub Copilot subscription.
5252

53-
GitHub Code Quality helps users improve code reliability, maintainability, and overall project health by surfacing actionable feedback and offering automatic fixes for findings in pull requests and on the default branch. When Code Quality is enabled, two types of analysis run: CodeQL quality queries identify problems with the maintainability, reliability, or style of code, and LLM-powered analysis provides additional insights beyond what deterministic engines can find. When a quality issue is detected, Copilot Autofix suggests a relevant fix. On pull requests, results are displayed as comments left by the `github-code-quality` bot. On the default branch, LLM-powered findings are displayed in the **AI findings** dashboard under the **{% octicon "shield" aria-hidden="true" aria-label="shield" %} {% ifversion security-and-quality-tab %}Security and quality{% else %}Security{% endif %}** tab.
53+
GitHub Code Quality helps users improve code reliability, maintainability, and overall project health by surfacing actionable feedback and offering automatic fixes for findings in pull requests and on the default branch. When Code Quality is enabled, two types of analysis run: CodeQL quality queries identify problems with the maintainability, reliability, or style of code, and LLM-powered analysis provides additional insights beyond what deterministic engines can find. When a quality issue is detected, Copilot Autofix suggests a relevant fix. On pull requests, results are displayed as comments left by the `github-code-quality` bot. On the default branch, LLM-powered findings are displayed in the **AI findings** dashboard under the **{% octicon "shield" aria-hidden="true" aria-label="shield" %} {% ifversion security-and-quality-tab %}Security and quality{% else %}Security{% endif %}** tab. Additionally, Code Quality can automatically generate a code coverage CI workflow for your repository using an AI-powered agent, reducing the manual effort required to set up coverage tracking.
5454

5555
The primary supported language for GitHub Code Security AI features is English.
5656

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
You can use the automatic setup option to generate a workflow with an AI-powered agent, or configure your workflow manually. See [AUTOTITLE](/code-security/how-tos/maintain-quality-code/set-up-code-coverage).

0 commit comments

Comments
 (0)