Skip to content

Commit fa7b10d

Browse files
Shaunak01dremdem
andauthored
HelpersTask616_Document_coverage_with_Codecov (#624)
* checkpoint * test * checkpoint * test * tets * checkpoint * checkpoint * fix * checkpoint * Checkpoint Pre-commit checks: - 'check_master' passed - 'check_author' passed - 'check_file_size' passed - 'check_python_compile' passed - 'check_gitleaks' passed All checks passed ✅ * FIX Pre-commit checks: - 'check_master' passed - 'check_author' passed - 'check_file_size' passed - 'check_python_compile' passed - 'check_gitleaks' passed All checks passed ✅ * Checkpoint Pre-commit checks: - 'check_master' passed - 'check_author' passed - 'check_file_size' passed - 'check_python_compile' passed - 'check_gitleaks' passed All checks passed ✅ * Checkpoint Pre-commit checks: - 'check_master' passed - 'check_author' passed - 'check_file_size' passed - 'check_python_compile' passed - 'check_gitleaks' passed All checks passed ✅ --------- Co-authored-by: Vlad <[email protected]>
1 parent a30b664 commit fa7b10d

File tree

8 files changed

+352
-0
lines changed

8 files changed

+352
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,352 @@
1+
<!-- toc -->
2+
3+
- [Codecov Integration and Coverage Setup Documentation](#codecov-integration-and-coverage-setup-documentation)
4+
* [Setting Up Codecov](#setting-up-codecov)
5+
* [Coverage Configuration](#coverage-configuration)
6+
* [GitHub Actions Workflow](#github-actions-workflow)
7+
+ [Workflow Schedule](#workflow-schedule)
8+
+ [Workflow Jobs](#workflow-jobs)
9+
* [Codecov Configuration](#codecov-configuration)
10+
* [Viewing Coverage Reports](#viewing-coverage-reports)
11+
* [Running Coverage Locally](#running-coverage-locally)
12+
* [System Behavior: When the Test Coverage Workflow Fails or Continues](#system-behavior-when-the-test-coverage-workflow-fails-or-continues)
13+
* [Additional Functionalities and Extensions](#additional-functionalities-and-extensions)
14+
* [Coverage Behavior and Best Practices](#coverage-behavior-and-best-practices)
15+
* [Troubleshooting](#troubleshooting)
16+
17+
<!-- tocstop -->
18+
19+
# Codecov Integration and Coverage Setup Documentation
20+
21+
This documentation describes the setup and usage of Codecov integration for our
22+
repos. The purpose is to explain how Codecov coverage tracking is configured,
23+
the functionalities implemented, and how developers can interpret, interact
24+
with, and extend the coverage results.
25+
26+
## Setting Up Codecov
27+
28+
Codecov was integrated by adding necessary files and configuration steps:
29+
30+
Files and Directories Added
31+
32+
- [.coveragerc](/.coveragerc): Configures directories and files under coverage
33+
collection
34+
- [/.github/gh_requirements.txt](/.github/gh_requirements.txt): Lists
35+
dependencies necessary for the coverage workflow
36+
- [/.github/workflows/coverage_tests.yml](/.github/workflows/coverage_tests.yml):
37+
Defines GitHub Actions workflow for automated coverage runs
38+
39+
External setup
40+
41+
Applies default coverage settings across all repos to ensure consistency in
42+
reporting and behavior. If needed, individual repos can include their own
43+
`.codecov.yml` at the root to override specific global settings.
44+
45+
- [Global YAML](https://app.codecov.io/account/gh/causify-ai/yaml/.): Configures
46+
coverage collection of Codecov
47+
48+
## Coverage Configuration
49+
50+
The `.coveragerc` file defines coverage measurement settings:
51+
52+
- `Excluded Files`: These files are omitted from coverage reporting.
53+
```ini
54+
[report]
55+
omit =
56+
*/devops/compose/*
57+
*/helpers/test/outcomes/*/tmp.scratch/*
58+
```
59+
60+
## GitHub Actions Workflow
61+
62+
Coverage tests are automated via GitHub Actions -
63+
`.github/workflows/coverage_tests.yml`.
64+
65+
### Workflow Schedule
66+
67+
- Runs daily at midnight (UTC)
68+
- Can be manually triggered (`workflow_dispatch`)
69+
- Action fails if coverage drops by `1%` (including `fast`, `slow` and
70+
`superslow` tests)
71+
72+
### Workflow Jobs
73+
74+
1. Fast Tests Coverage:
75+
76+
- Runs daily or on manual trigger
77+
- Uploads report flagged as `fast`
78+
79+
2. Slow Tests Coverage:
80+
81+
- Runs daily or on manual trigger
82+
- Uploads report flagged as `slow`
83+
84+
3. Superslow Tests Coverage:
85+
86+
- Runs weekly on Monday or on manual trigger.
87+
- Uploads report flagged as `superslow`.
88+
89+
4. Each job:
90+
91+
- Generates an `XML` coverage report (`Global YAML`)
92+
- Uploads reports to `Codecov` with respective flags (`fast`, `slow`,
93+
`superslow`)
94+
95+
## Codecov Configuration
96+
97+
- Coverage flags and project-level checks are configured at Global yml -
98+
[https://app.codecov.io/account/gh/causify-ai/yaml/.](https://app.codecov.io/account/gh/causify-ai/yaml/.)
99+
- If required, you can add distinct repository configurations to the
100+
`.codecov.yml` file at the root of your repository. - You can change the
101+
threshold of coverage drops for a specific repo - You can add/ change patch
102+
settings or flags for a specific repo
103+
104+
1. Flag Management
105+
106+
The `carryforward` option allows Codecov to reuse the previous coverage data
107+
if a report is not submitted for a given flag in the current CI run. This is
108+
useful when certain test suites (e.g., slow or superslow) don't run in every
109+
cycle but should still be reflected in the coverage summary.
110+
111+
```yml
112+
flag_management:
113+
individual_flags:
114+
- name: fast
115+
carryforward: true
116+
- name: slow
117+
carryforward: true
118+
- name: superslow
119+
carryforward: true
120+
```
121+
122+
2. Comment Behavior
123+
124+
Codecov can automatically post a summary comment on PRs. This comment can be
125+
customized in layout, behavior, and verbosity.
126+
- `layout: "reach, diff, files"` : Displays overall coverage, diff coverage,
127+
and file-level detail
128+
- `behavior: default` : Overwrites the previous comment instead of posting a
129+
new one
130+
- `require_changes: false` : Posts the comment even when coverage doesn't
131+
change
132+
- `show_critical_paths: false` : Disables per-line comments in the PR diff
133+
view
134+
135+
```yml
136+
comment:
137+
layout: "reach, diff, files"
138+
behavior: default
139+
require_changes: false
140+
show_critical_paths: false
141+
```
142+
- When PR comment is enabled:
143+
144+
<img src="figs/coverage/image1.png" alt="alt text" width="1000"/>
145+
- When per-line comments in PR files is enabled:
146+
147+
<img src="figs/coverage/image2.png" alt="alt text" width="1000"/>
148+
149+
3. GitHub Check Annotations
150+
151+
Inline annotations in the GitHub `Files changed` view are disabled using the
152+
`github_checks.annotations` flag. This ensures a cleaner PR experience
153+
without coverage-based highlights on each line.
154+
155+
<img src="figs/coverage/image7.png" alt="alt text" width="1000"/>
156+
157+
4. Coverage Status Check:
158+
159+
This section configures the status checks that appear in GitHub pull
160+
requests. It defines both patch-level and project-level coverage checks and
161+
sets conditions for when they should run and how they should behave.
162+
- `project.default`: Defines the overall coverage check behavior.
163+
- `target`: auto automatically compares against the base branch of the PR.
164+
- `threshold: 1%` means the check will fail if coverage drops by `1%` or
165+
more.
166+
- `flags` scopes the project-level check to specific test suites (`fast`,
167+
`slow`, `superslow`).
168+
- `branches` limits the check to PRs targeting the `master` branch.
169+
- `patch: true`: Ensures Codecov always checks coverage on the changed lines
170+
in a PR, regardless of the base branch or flag.
171+
172+
```yml
173+
coverage:
174+
status:
175+
project:
176+
default:
177+
target: auto
178+
threshold: 1%
179+
flags:
180+
- fast
181+
- slow
182+
- superslow
183+
branches:
184+
- master
185+
patch: true
186+
```
187+
188+
<img src="figs/coverage/image3.png" alt="alt text" width="1000"/>
189+
190+
## Viewing Coverage Reports
191+
192+
Coverage results for the helpers repository are accessible via Codecov.
193+
194+
- Codecov UI link for helpers -
195+
[https://app.codecov.io/gh/causify-ai/helpers](https://app.codecov.io/gh/causify-ai/helpers)
196+
- Master Build Dashboard Notebook:
197+
[http://172.30.2.44/build/buildmeister_dashboard/Master_buildmeister_dashboard.latest.html#Code-coverage-HTML-page](http://172.30.2.44/build/buildmeister_dashboard/Master_buildmeister_dashboard.latest.html#Code-coverage-HTML-page)
198+
199+
## Running Coverage Locally
200+
201+
Developers can manually run coverage tasks locally via Invoke commands and
202+
generate html report:
203+
204+
- Fast Tests:
205+
206+
```yml
207+
invoke run_coverage --suite fast --generate-html-report
208+
```
209+
210+
- Slow Tests:
211+
212+
```yml
213+
invoke run_coverage --suite slow --generate-html-report
214+
```
215+
216+
- Superslow Tests:
217+
218+
```yml
219+
invoke run_coverage --suite superslow --generate-html-report
220+
```
221+
222+
- Review HTML coverage report
223+
- Run a local HTTP server to serve the HTML:
224+
```bash
225+
cd htmlcov
226+
python3 -m http.server 8000
227+
```
228+
- If you're running this on a remote server, set up SSH port forwarding:
229+
```bash
230+
ssh -i ~/.ssh/<private_key> -L 8000:localhost:8000 <user_name>@<server_ip>
231+
```
232+
- Then open your browser and go to:
233+
[http://localhost:8000](http://localhost:8000)
234+
235+
<img src="figs/coverage/image4.png" alt="alt text" width="1000"/>
236+
237+
## System Behavior: When the Test Coverage Workflow Fails or Continues
238+
239+
This section documents how the Test coverage workflow behaves under various
240+
failure conditions, specifically regarding the fast, slow, and superslow test
241+
suites.
242+
243+
1. Dependency / Setup Steps
244+
245+
Steps included:
246+
247+
- AWS credential configuration
248+
- Docker login
249+
- Cleanup
250+
- Code checkout
251+
- PYTHONPATH update
252+
- Dependency installation
253+
254+
Behavior:
255+
256+
- If any of these steps fail, the workflow fails immediately
257+
- No test suites (fast, slow, superslow) will run
258+
- This is intentional to prevent test execution in a broken or incomplete
259+
environment
260+
261+
2. Fast / Slow Test Steps
262+
263+
Steps included:
264+
265+
- `run_fast`
266+
- `upload_fast`
267+
- `run_slow`
268+
- `upload_slow`
269+
270+
These steps use `continue-on-error: true`.
271+
272+
Behavior:
273+
274+
- If any of these steps fail, the workflow continues without immediate failure
275+
- The superslow test will still run if the workflow is triggered on Monday
276+
(scheduled) or manually (workflow_dispatch)
277+
- However, the workflow may still fail at the end if fast/slow failures are
278+
detected by the final failure check step
279+
280+
3. Superslow Test Steps
281+
282+
Steps included:
283+
284+
- `run_superslow`
285+
- `upload_superslow`
286+
287+
These steps do not use `continue-on-error`.
288+
289+
Behavior:
290+
291+
- These steps run only:
292+
- On scheduled workflows that fall on a Monday (DAY_OF_WEEK == 1)
293+
- Or when the workflow is manually triggered
294+
- If either step fails, the workflow fails immediately
295+
- If both pass, the workflow continues to the final fast/slow check
296+
297+
4. Final Failure Check (Fast/Slow Only)
298+
299+
Step included:
300+
301+
- Fail if fast/slow test or upload failed
302+
303+
Behavior:
304+
305+
- This step runs at the very end of the workflow
306+
- It checks whether any of the fast/slow test or upload steps failed
307+
- If any of them failed, this step causes the entire job to fail using exit 1
308+
- This ensures that silent failures in fast/slow coverage are surfaced, even if
309+
superslow passes
310+
311+
| Step Type | Step Failed? | Superslow Runs? | Job Fails? |
312+
| ---------------- | ------------------------- | ----------------------- | ----------------------- |
313+
| Setup Step | Yes | No | Yes |
314+
| Fast Test | Yes | Yes (Mon/dispatch only) | Yes (after final check) |
315+
| Slow Test | Yes | Yes (Mon/dispatch only) | Yes (after final check) |
316+
| Superslow Test | Yes | n/a | Yes |
317+
| Final Fail Check | Yes (if fast/slow failed) | Already ran | Yes |
318+
319+
## Additional Functionalities and Extensions
320+
321+
Additional functionalities provided by Codecov that can be utilized or extended
322+
include:
323+
324+
- `Pull Request Comments`: Automatically generate detailed coverage summaries or
325+
line-by-line coverage comments directly in GitHub pull requests
326+
- `Coverage Badges`: Integrate coverage badges in the repository `README` to
327+
visibly show current coverage status
328+
329+
<img src="figs/coverage/image5.png" alt="alt text" width="1000"/>
330+
331+
- `Report Customization`: Configure detailed reporting settings to specify what
332+
information to display or omit in coverage summaries
333+
334+
## Coverage Behavior and Best Practices
335+
336+
- Coverage reports are uploaded regardless of test success to ensure coverage
337+
tracking consistency
338+
- Coverage flags (`fast`, `slow`, `superslow`) allow separate visibility and
339+
tracking
340+
- Fast test coverage:
341+
342+
<img src="figs/coverage/image6.png" alt="alt text" width="1000"/>
343+
344+
- Regular review of coverage differences (visible in PR checks and Codecov UI)
345+
is encouraged to maintain code quality
346+
347+
## Troubleshooting
348+
349+
- Check GitHub Actions logs for errors in coverage upload steps
350+
- Ensure `CODECOV_TOKEN` is correctly set as a GitHub secret
351+
- Validate workflow and coverage configuration files for correctness if issues
352+
arise
65.5 KB
Loading
210 KB
Loading
68.3 KB
Loading
508 KB
Loading
258 KB
Loading
270 KB
Loading
166 KB
Loading

0 commit comments

Comments
 (0)