Skip to content

#428: Fixed detecting report coverage failures #429

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
8 changes: 6 additions & 2 deletions doc/changes/unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Summary

With #420, any GitHub repos using the PTB for **documentation** will also need to
With #420, any GitHub repos using the PTB for **documentation** will also need to
reconfigure the GitHub Pages settings for each repo:
1. Go to the affected repo's GitHub page
2. Select 'Settings'
Expand Down Expand Up @@ -30,4 +30,8 @@ permissions to be increased for specific jobs.
## ✨ Features

* [#161](https://github.com/exasol/python-toolbox/issues/161): Added support for installing extras & not using a cache to the python-environment action
* [#408](https://github.com/exasol/python-toolbox/issues/408): Added support for GitHub runners who do not per default have pipx to use the python-environment action
* [#408](https://github.com/exasol/python-toolbox/issues/408): Added support for GitHub runners who do not per default have pipx to use the python-environment action

## Bugfixes

* #428: Fixed detecting report coverage failures
16 changes: 10 additions & 6 deletions exasol/toolbox/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,20 @@ def total_coverage(file: Union[str, Path]) -> float:
encoding="utf-8",
)
stdout = p.stdout.strip()
if (p.returncode == 1) and (stdout == "No data to report."):
print(

if p.returncode != 0:
message = (
f"The following command"
f" returned non-zero exit status {p.returncode}:\n"
f' {" ".join(p.args)}\n'
f"{stdout}\n"
"Returning total coverage 100 %.",
file=sys.stderr,
f"{stdout}"
)
return 100.0
if (p.returncode == 1) and (stdout == "No data to report."):
print(f"{message}\nReturning total coverage 100 %.", file=sys.stderr)
return 100.0
else:
raise RuntimeError(message)

with open(report, encoding="utf-8") as r:
data = json.load(r)
total: float = data["totals"]["percent_covered"]
Expand Down
34 changes: 27 additions & 7 deletions exasol/toolbox/nox/_metrics.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from __future__ import annotations

import argparse
from dataclasses import dataclass
from pathlib import Path

import nox
from nox import Session
Expand All @@ -13,6 +15,21 @@
from noxconfig import PROJECT_CONFIG


@dataclass
class RequiredFile:
"""
Describes a required file and the related nox task to generate this
file.
"""

def __init__(self, file: Path | str, task: str):
self.file = file if isinstance(file, Path) else PROJECT_CONFIG.root / file
self.task = task

def __str__(self) -> str:
return f"{self.file.name} generated by `{self.task}`"


@nox.session(name="project:report", python=False)
def report(session: Session) -> None:
"""
Expand Down Expand Up @@ -45,14 +62,17 @@ def report(session: Session) -> None:
help="Output format to produce.",
choices=formats,
)
required_files = (
PROJECT_CONFIG.root / ".coverage",
PROJECT_CONFIG.root / ".lint.txt",
PROJECT_CONFIG.root / ".security.json",
)
if not all(file.exists() for file in required_files):
required_files = [
RequiredFile(".coverage", "test:coverage"),
RequiredFile(".lint.txt", "lint:code"),
RequiredFile(".security.json", "lint:security"),
]
if missing_files := [f for f in required_files if not f.file.exists()]:
missing = "\n- file ".join(str(f) for f in missing_files)
session.error(
"Please make sure you run the `test:coverage`, `lint:security` and the `lint:code` target first"
"Some required files are missing.\n"
"Please make sure you run the related nox tasks first:\n"
f"{missing}"
)
sha1 = str(
session.run("git", "rev-parse", "HEAD", external=True, silent=True)
Expand Down