Commit 741cbaec authored by Pierre Smeyers's avatar Pierre Smeyers
Browse files

feat: skip OK message if at least one warn

parent 3352dea9
Loading
Loading
Loading
Loading
+12 −3
Original line number Diff line number Diff line
@@ -216,6 +216,7 @@ def _check_var(
    expected_gl_input = tbc_var.to_gl()

    err_count = 0
    warn_count = 0

    # check variable declaration from Kicker
    # --------------------------------------
@@ -246,6 +247,7 @@ def _check_var(
            print(
                f"  {AnsiColors.YELLOW}⚠ <{tbc_var.name}/{expected_input_name}>: container images should use 'latest' tag by default ('{tag}' found){AnsiColors.RESET}"
            )
            warn_count += 1

    # check variable declaration from doc (warn only)
    # -----------------------------------
@@ -260,19 +262,23 @@ def _check_var(
            print(
                f"  {AnsiColors.YELLOW}⚠ <{tbc_var.name}/{expected_input_name}>: README default ({doc_var.default(tbc_var.type)}) doesn't match Kicker's ({expected_gl_input.default}){AnsiColors.RESET}"
            )
            warn_count += 1

        if doc_var.lock and not tbc_var.secret:
            print(
                f"  {AnsiColors.YELLOW}⚠ <{tbc_var.name}>: is not declared as a secret but has a lock in README{AnsiColors.RESET}"
            )
            warn_count += 1
        elif not doc_var.lock and tbc_var.secret:
            print(
                f"  {AnsiColors.YELLOW}⚠ <{tbc_var.name}>: is declared as a secret but has no lock in README{AnsiColors.RESET}"
            )
            warn_count += 1
        elif not has_no_input and expected_input_name != doc_var.input_name:
            print(
                f"  {AnsiColors.YELLOW}⚠ <{tbc_var.name}/{expected_input_name}>: has wrong input declared in README ({doc_var.input_name}){AnsiColors.RESET}"
            )
            warn_count += 1

    # retrieve declared input from template specs
    declared_input = tpl_spec["spec"]["inputs"].get(expected_input_name)
@@ -334,6 +340,7 @@ def _check_var(
        print(
            f"  {AnsiColors.YELLOW}⚠ <{tbc_var.name}/{expected_input_name}>: description doesn't match Kicker's{AnsiColors.RESET}"
        )
        warn_count += 1

    if actual_gl_input.default != expected_gl_input.default:
        print(
@@ -363,7 +370,7 @@ def _check_var(
        err_count += 1

    # print an OK message if no error was found
    if err_count == 0:
    if err_count == 0 and warn_count == 0:
        print(
            f"  {AnsiColors.GREEN}{AnsiColors.RESET} <{tbc_var.name}/{expected_input_name}>: OK"
        )
@@ -488,6 +495,7 @@ def _check_inheritance(tpl_body: dict[str, Any]) -> int:
    #
    for name, body in iter(job_bodies.items()):
        job_err_count = 0
        job_warn_count = 0
        # skip job with only partial overrides
        if not any(key in body for key in ["stage", "extends", "image"]):
            print(
@@ -496,7 +504,7 @@ def _check_inheritance(tpl_body: dict[str, Any]) -> int:
            continue
        base_job = body.get("extends", None)
        if is_single_job_tpl and base_job is not None:
            job_err_count += 1
            job_warn_count += 1
            print(
                f"  {AnsiColors.YELLOW}⚠ single job template: job '{name}' inherits another job{AnsiColors.RESET}"
            )
@@ -511,10 +519,11 @@ def _check_inheritance(tpl_body: dict[str, Any]) -> int:
                f"  {AnsiColors.RED}✕ job '{name}' inherits from non-hidden job '{base_job}'{AnsiColors.RESET}"
            )
        if base_job is not None and base_job not in job_bodies:
            job_warn_count += 1
            print(
                f"  {AnsiColors.YELLOW}⚠ job '{name}' inherits from '{base_job}' which is not defined in current template{AnsiColors.RESET}"
            )
        if job_err_count == 0:
        if job_err_count == 0 and job_warn_count == 0:
            print(
                f"  {AnsiColors.GREEN}{AnsiColors.RESET} job '{name}' inheritance: OK"
            )
+0 −1
Original line number Diff line number Diff line
@@ -38,7 +38,6 @@ def test_check_inheritance_multiple_job_inheritance_from_undefined(capfd: pytest
        "  \x1b[0;32m✓\x1b[0m job '.base-job' inheritance: OK\n"
        "  \x1b[0;32m✓\x1b[0m job 'prefix-job1' inheritance: OK\n"
        "  \x1b[0;33m⚠ job 'prefix-job2' inherits from '.undefined' which is not defined in current template\x1b[0m\n"
        "  \x1b[0;32m✓\x1b[0m job 'prefix-job2' inheritance: OK\n"
    )

def test_check_inheritance_multiple_job_inheritance_bad(capfd: pytest.CaptureFixture[str]):