Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/tests/coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ scenario -- new.py; multi_report other.py=1; run_chec
scenario -- new.py; multi_report new.py=1; run_check pass 'new source file present in the reports'
scenario -- new.py; multi_report /app/other.py=1; run_check fail 'new file flagged with out-of-workspace absolute report paths'
scenario -- tests/new.py; multi_report other.py=1; run_check pass 'new file outside the reported directories is not flagged'
scenario -- src/new.test.ts; multi_report src/a.ts=1; run_check pass 'new colocated .test. file is not flagged'
scenario -- src/new.spec.tsx; multi_report src/a.tsx=1; run_check pass 'new colocated .spec. file is not flagged'
scenario -- src/__tests__/new.ts; multi_report src/__tests__/a.ts=1; run_check pass 'new file under __tests__ is not flagged'
scenario -- test_new.py conftest.py new_test.py; multi_report other.py=1; run_check pass 'new pytest files are not flagged'
scenario -- src/new.ts; multi_report src/a.ts=1; run_check fail 'new colocated source file is still flagged'
scenario -- src/testing.ts; multi_report src/a.ts=1; run_check fail 'source file with test in its name is still flagged'
scenario -- 'a*b.py'; multi_report 'a*b.py=1'; run_check pass 'path with glob characters'
scenario -- ; : > empty.py; git add . && git commit -q -m empty; multi_report other.py=1; run_check pass 'new empty file is not flagged'
scenario -- new.md; multi_report other.py=1; run_check pass 'new non-source file is not flagged'
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@ jobs:
# Files outside every directory holding reported files (tests, tooling) are usually excluded on purpose.
d = str(Path(path).parent)
return any(d == r or d.endswith('/' + r) or r.endswith('/' + d) or (d == '.' and r.startswith('/')) for r in report_dirs)

def is_test_file(path):
# Test files colocated with the sources (vitest/jest, pytest, go) are never in the reports.
p = Path(path)
return ('__tests__' in p.parts or '.test.' in p.name or '.spec.' in p.name
or re.fullmatch(r'test_.*\.py|.*_test\.(py|go)|conftest\.py', p.name) is not None)
executable = covered = 0
missed, unreported = [], []
for status, path in zip(tokens[0::2], tokens[1::2]):
Expand All @@ -199,7 +205,7 @@ jobs:
start, count = int(m.group(1)), int(m.group(2) or 1)
added.update(range(start, start + count))
if match is None:
if status == 'A' and added and Path(path).suffix in report_suffixes and in_reported_dir(path):
if status == 'A' and added and Path(path).suffix in report_suffixes and in_reported_dir(path) and not is_test_file(path):
unreported.append(path)
continue
data = lines[match]
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@ The job fails when no report is found or when the reports hold no branch data. C

Report paths are resolved against the files tracked by the repository (exact path, the Cobertura `<source>` roots, or a unique suffix match), so the same file reported under several prefixes counts once. A report path that is a suffix of several tracked files, or a `.xml` file in a `coverage-*` artifact that is not a Cobertura report (invalid XML, or a root other than `<coverage>`), fails the job: emit repository-relative paths (`relative_files = true` in coverage.py) and upload only coverage reports.

On a pull request, a new non-empty file with the extension of the reported files, in a directory holding reported files, and absent from the reports fails the job, so an untested new module cannot hide from the patch figure. Test files are exempt, since coverage tools never report them: names containing `.test.` or `.spec.`, paths under `__tests__/`, `test_*.py`, `*_test.py`, `*_test.go` and `conftest.py`.

A job that `needs` a test job is skipped when that job fails, and a skipped required check counts as passed. So `coverage` is not a required check itself: the caller's single required tests check (`Tests success`) is an `if: always()` gate that `needs` the test jobs **and** `coverage`, and fails when any of them is not successful. Call `coverage` without an `if`.

```yaml
Expand Down