-
Notifications
You must be signed in to change notification settings - Fork 2.9k
ci: migrate coverage gating from Codecov to GitHub Actions #8111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b2ed78b
Refactor CI Summary
yurishkuro d74f86d
fix
yurishkuro f7a72f5
fix
yurishkuro d1cc27a
fix
yurishkuro 116068b
fix
yurishkuro f2e523f
fix
yurishkuro 82aee79
Merge branch 'main' into fix-codecov-gate
yurishkuro f37379e
fix
yurishkuro 4910ef4
fix
yurishkuro 62acdbb
fix
yurishkuro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| #!/usr/bin/env python3 | ||
| # Copyright (c) 2026 The Jaeger Authors. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Filters a Go coverage profile in-place by applying the same exclusions defined | ||
| # in .codecov.yml so coverage metrics stay in sync between this gate and Codecov. | ||
| # | ||
| # Usage: | ||
| # python3 scripts/e2e/filter_coverage.py <coverage.out> [path/to/.codecov.yml] | ||
|
|
||
| import fnmatch | ||
| import os | ||
| import sys | ||
|
|
||
|
|
||
| def load_exclusions(codecov_path: str) -> list[str]: | ||
| """Return raw glob patterns from the ignore: section of .codecov.yml.""" | ||
| patterns = [] | ||
| in_ignore = False | ||
| with open(codecov_path) as f: | ||
| for line in f: | ||
| stripped = line.strip() | ||
| if stripped == 'ignore:': | ||
| in_ignore = True | ||
| elif in_ignore: | ||
| if stripped.startswith('#'): | ||
| continue | ||
| if stripped.startswith('- '): | ||
| patterns.append(stripped[2:].strip('"').strip("'")) | ||
| elif stripped and not line[0].isspace(): | ||
| in_ignore = False | ||
| return patterns | ||
|
|
||
|
|
||
| def read_module_path() -> str: | ||
| """ | ||
| Read the Go module path so we can strip it from coverage import paths | ||
| to produce repo-relative paths that match the .codecov.yml patterns. | ||
| """ | ||
| go_mod_path = os.path.join(os.path.dirname(codecov_path), 'go.mod') | ||
| with open(go_mod_path) as f: | ||
| for line in f: | ||
| if line.startswith('module '): | ||
| return line.split()[1].strip() | ||
| raise ValueError(f'no module directive found in {go_mod_path}') | ||
|
|
||
|
|
||
| def should_exclude(path: str, patterns: list[str]) -> bool: | ||
| """Return True if path matches any exclusion pattern. | ||
|
|
||
| Patterns with wildcards are matched via fnmatch. Patterns without | ||
| wildcards are treated as plain path prefixes. | ||
| """ | ||
| for pattern in patterns: | ||
| if '*' in pattern or '?' in pattern: | ||
| if fnmatch.fnmatch(path, pattern): | ||
| return True | ||
| else: | ||
| if path.startswith(pattern): | ||
| return True | ||
| return False | ||
|
|
||
|
|
||
| def main() -> None: | ||
| if len(sys.argv) < 2: | ||
| print(f'usage: {sys.argv[0]} <coverage.out> [.codecov.yml]', file=sys.stderr) | ||
| sys.exit(1) | ||
|
|
||
| coverage_path = sys.argv[1] | ||
| codecov_path = sys.argv[2] if len(sys.argv) > 2 else '.codecov.yml' | ||
|
|
||
| try: | ||
| exclusions = load_exclusions(codecov_path) | ||
| except FileNotFoundError: | ||
| print(f'error: {codecov_path} not found', file=sys.stderr) | ||
| sys.exit(1) | ||
|
|
||
| module_prefix = read_module_path(go_mod_path) + '/' | ||
| kept = skipped = 0 | ||
|
yurishkuro marked this conversation as resolved.
|
||
| kept_lines = [] | ||
|
yurishkuro marked this conversation as resolved.
Outdated
|
||
| with open(coverage_path) as f: | ||
| for line in f: | ||
| if line.startswith('mode:'): | ||
| kept_lines.append(line) | ||
| continue | ||
| # Coverage lines: "github.com/.../file.go:line.col,line.col stmts count" | ||
| # Extract the file path (everything before the first colon). | ||
| import_path = line.split(':')[0] | ||
| # Strip module prefix to get a repo-relative path for matching. | ||
| if import_path.startswith(module_prefix): | ||
| path = import_path[len(module_prefix):] | ||
| else: | ||
| path = import_path | ||
| if should_exclude(path, exclusions): | ||
| skipped += 1 | ||
| else: | ||
| kept_lines.append(line) | ||
| kept += 1 | ||
|
|
||
| with open(coverage_path, 'w') as f: | ||
| f.writelines(kept_lines) | ||
|
|
||
| print(f'filter_coverage: kept {kept}, excluded {skipped} lines', file=sys.stderr) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| main() | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.