Skip to content

Commit d3683ec

Browse files
committed
Fix artifacts:validate and sonar:check to pass when working with newly created project
1 parent 9a9a072 commit d3683ec

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

doc/changes/unreleased.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22

33
## Bugfixes
44

5-
* #489: Fixed .pre-commit-config.yaml to use existing nox tasks
5+
* #489: Fixed .pre-commit-config.yaml to use existing nox tasks
6+
* #490: Fixed artifacts:validate & sonar:check to work for newly created projects

exasol/toolbox/nox/_artifacts.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import re
44
import shutil
55
import sqlite3
6+
import subprocess
67
import sys
78
from collections.abc import Iterable
89
from pathlib import Path
@@ -184,8 +185,29 @@ def _copy_artifacts(source: Path, dest: Path, files: Iterable[str]):
184185

185186

186187
def _prepare_coverage_xml(session: Session, source: Path) -> None:
187-
command = ["coverage", "xml", "-o", COVERAGE_XML, "--include", f"{source}/*"]
188-
session.run(*command)
188+
# we do not want to fail the coverage constraint for sonar, as sonar does this for us
189+
command = [
190+
"coverage",
191+
"xml",
192+
"-o",
193+
COVERAGE_XML,
194+
"--include",
195+
f"{source}/*",
196+
"--fail-under=0",
197+
]
198+
output = subprocess.run(
199+
command, capture_output=True, text=True, check=False
200+
) # type: ignore
201+
202+
if output.returncode != 0:
203+
if output.stderr.strip() == "No data to report.":
204+
# Assuming that previous steps passed in the CI, this indicates, as
205+
# is in the case for newly created projects that no coverage over the
206+
# `source` files was found. To allow Sonar to report, we create
207+
# a dummy file which will toss a warning but otherwise successfully execute.
208+
Path(COVERAGE_XML).touch()
209+
else:
210+
session.error(output.returncode)
189211

190212

191213
def _upload_to_sonar(

0 commit comments

Comments
 (0)