Commit 63969047 authored by Pierre Smeyers's avatar Pierre Smeyers
Browse files

feat: forbid parallel-matrix in templates implementation

parent 22536608
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -453,7 +453,7 @@ def _check_report(
def _check_job(job_name: str, tpl_body, job_prefix) -> int:
    err_count = 0

    # check non-hiden jobs rules
    # check non-hidden jobs rules
    if not job_name.startswith(".") and job_name != "pages":
        # check: all jobs are prefixed with the template prefix
        if not job_name.startswith(job_prefix) or (
@@ -475,6 +475,13 @@ def _check_job(job_name: str, tpl_body, job_prefix) -> int:
            for path in paths:
                err_count += _check_report(job_name, type, path)

    # check 'parallel' keyword is not used in TBC internal implementation
    if tpl_body[job_name].get("parallel"):
        print(
            f"  {AnsiColors.RED}✕ job <{job_name}>: uses forbidden 'parallel' keyword{AnsiColors.RESET}"
        )
        err_count += 1

    return err_count


+16 −0
Original line number Diff line number Diff line
@@ -33,3 +33,19 @@ def test_check_job_bad_jobs(capfd: pytest.CaptureFixture[str]):
    assert out == (
        "  \x1b[0;31m✕ job <bad-prefix-job1>: doesn't start with prefix (prefix)\x1b[0m\n"
    )


def test_job_with_parallel_matrix(capfd: pytest.CaptureFixture[str]):
    tpl_body = {
        "workflow": None,
        "variables": None,
        "stages": None,
        ".hidden": None,
        "prefix-job1": {"parallel": {"matrix": [{"VAR": "value1"}, {"VAR": "value2"}]}},
    }

    res = checker._check_job("prefix-job1", tpl_body, "prefix")
    out, err = capfd.readouterr()
    assert out == (
        "  \x1b[0;31m✕ job <prefix-job1>: uses forbidden 'parallel' keyword\x1b[0m\n"
    )