diff --git a/doc/changes/unreleased.md b/doc/changes/unreleased.md index 0552e8d46..9e5430eda 100644 --- a/doc/changes/unreleased.md +++ b/doc/changes/unreleased.md @@ -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' @@ -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 \ No newline at end of file +* [#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 diff --git a/exasol/toolbox/metrics.py b/exasol/toolbox/metrics.py index 11872692f..1890e8edd 100644 --- a/exasol/toolbox/metrics.py +++ b/exasol/toolbox/metrics.py @@ -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"] diff --git a/exasol/toolbox/nox/_metrics.py b/exasol/toolbox/nox/_metrics.py index b662f8fd3..b5b9355e2 100644 --- a/exasol/toolbox/nox/_metrics.py +++ b/exasol/toolbox/nox/_metrics.py @@ -1,6 +1,8 @@ from __future__ import annotations import argparse +from dataclasses import dataclass +from pathlib import Path import nox from nox import Session @@ -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: """ @@ -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)