Commit 57d7d02d authored by Pierre Smeyers's avatar Pierre Smeyers
Browse files

refactor: add check job function

parent ea50ac42
Loading
Loading
Loading
Loading
+29 −22
Original line number Diff line number Diff line
@@ -440,6 +440,33 @@ def _check_report(
    return err_count


def _check_job(job_name: str, tpl_body, job_prefix) -> int:
    err_count = 0

    # check non-hiden jobs rules
    if not job_name.startswith("."):
        # check: all jobs are prefixed with the template prefix
        if not job_name.startswith(job_prefix) or (
            len(job_name) > len(job_prefix) and job_name[len(job_prefix)] != "-"
        ):
            print(
                f"  {AnsiColors.RED}✕ job <{job_name}>: doesn't start with prefix ({job_prefix}){AnsiColors.RESET}"
            )
            err_count += 1

        # check: tbc reports are compliant to naming convention
        reports = tpl_body[job_name].get("artifacts", {}).get("reports", {})
        for type, paths in reports.items():
            if type == "coverage_report":
                paths = paths["path"]
            if isinstance(paths, str):
                paths = [paths]
            for path in paths:
                err_count += _check_report(job_name, type, path)

    return err_count


def _check_tpl(
    kicker: dict[str, any],
    root_kicker: Optional[dict[str, any]],
@@ -468,30 +495,10 @@ def _check_tpl(
    # check jobs
    # ----------
    for name, body in tpl_body.items():
        if name.startswith("."):
            # hidden
            continue
        if "stage" not in body and "extends" not in body:
            # not a job?
            # not a job?,
            continue
        # check: all jobs are prefixed with the template prefix
        if not name.startswith(job_prefix) or (
            len(name) > len(job_prefix) and name[len(job_prefix)] != "-"
        ):
            print(
                f"  {AnsiColors.RED}✕ job <{name}>: doesn't start with prefix ({job_prefix}){AnsiColors.RESET}"
            )
            err_count += 1

        # check: tbc reports are compliant to naming convention
        reports = body.get("artifacts", {}).get("reports", {})
        for type, paths in reports.items():
            if type == "coverage_report":
                paths = paths["path"]
            if isinstance(paths, str):
                paths = [paths]
            for path in paths:
                err_count += _check_report(name, type, path)
        err_count += _check_job(name, tpl_body, job_prefix)

    # check variables
    # ---------------