MCPcopy
hub / github.com/saltstack/salt / upload_coverage

Function upload_coverage

tools/ci.py:447–554  ·  view source on GitHub ↗

Upload code coverage to codecov.

(ctx: Context, reports_path: pathlib.Path, commit_sha: str = None)

Source from the content-addressed store, hash-verified

445 },
446)
447def upload_coverage(ctx: Context, reports_path: pathlib.Path, commit_sha: str = None):
448 """
449 Upload code coverage to codecov.
450 """
451 codecov = shutil.which("codecov")
452 if not codecov:
453 ctx.error("Could not find the path to the 'codecov' binary")
454 ctx.exit(1)
455
456 if TYPE_CHECKING:
457 assert commit_sha is not None
458
459 codecov_args: list[str] = [
460 codecov,
461 "--nonZero",
462 "--sha",
463 commit_sha,
464 ]
465
466 from_pull_request = False
467
468 gh_event_path = os.environ.get("GITHUB_EVENT_PATH") or None
469 if gh_event_path is not None:
470 try:
471 gh_event = json.loads(open(gh_event_path, encoding="utf-8").read())
472 pr_event_data = gh_event.get("pull_request")
473 if pr_event_data:
474 from_pull_request = True
475 codecov_args.extend(["--parent", pr_event_data["base"]["sha"]])
476 except Exception as exc:
477 ctx.error(
478 f"Could not load the GH Event payload from {gh_event_path!r}:\n", exc # type: ignore[arg-type]
479 )
480
481 sleep_time = 15
482 for fpath in reports_path.glob("*.xml"):
483 if fpath.name in ("salt.xml", "tests.xml"):
484 flags = fpath.stem
485 else:
486 try:
487 section, distro_slug, _, _ = fpath.stem.split("..")
488 fips = ",fips"
489 except ValueError:
490 fips = ""
491 try:
492 section, distro_slug, _ = fpath.stem.split("..")
493 except ValueError:
494 ctx.error(
495 f"The file {fpath} does not respect the expected naming convention "
496 "'{salt|tests}..<distro-slug>..<nox-session>.xml'. Skipping..."
497 )
498 continue
499 flags = f"{section},{distro_slug}{fips}"
500
501 max_attempts = 3
502 current_attempt = 0
503 while True:
504 current_attempt += 1

Callers

nothing calls this directly

Calls 11

exitMethod · 0.80
openFunction · 0.50
errorMethod · 0.45
getMethod · 0.45
loadsMethod · 0.45
readMethod · 0.45
extendMethod · 0.45
infoMethod · 0.45
runMethod · 0.45
writeMethod · 0.45
sleepMethod · 0.45

Tested by

no test coverage detected