Jaypore CI

> Jaypore CI: Minimal, Offline, Local CI system.
Log | Files | Refs | README

commit 0c6595ee1305fa8e32ab3eb9e758ef8c489e46e3
parent e08d713c0c05ab7d14c9556de6d1a7ec214e4d49
Author: arjoonn <arjoonn@noreply.localhost>
Date:   Sat, 14 Jan 2023 16:14:29 +0000

Fix job execution ordering (!20)

Branch auto created by JayporeCI

<details>
    <summary>JayporeCi: 🟢 43674000d7</summary>

```mermaid
flowchart TB

            subgraph Pipeline
                direction TB

            end

            subgraph Docker
                direction TB

                s_Docker(( )) -.-> Docker_0(JciEnv):::passed
                s_Docker(( )) -.-> Docker_1(Jci):::passed
            end

            subgraph Jobs
                direction TB

                s_Jobs(( )) -.-> Jobs_0(black):::passed
                s_Jobs(( )) -.-> Jobs_1(pylint):::passed
                s_Jobs(( )) -.-> Jobs_2(pytest):::passed
            end

            subgraph Publish
                direction TB

                s_Publish(( )) -.-> Publish_0(PublishPypi):::passed
                s_Publish(( )) -.-> Publish_1(DockerHubJcienv):::passed
                s_Publish(( )) -.-> Publish_2(PublishDocs):::passed
                s_Publish(( )) -.-> Publish_3(DockerHubJci):::passed
            end

            Pipeline ---> Docker

            Docker ---> Jobs

            Jobs ---> Publish

            classDef pending fill:#aaa, color:black, stroke:black,stroke-width:2px,stroke-dasharray: 5 5;
            classDef skipped fill:#aaa, color:black, stroke:black,stroke-width:2px;
            classDef assigned fill:#ddd, color:black, stroke:black,stroke-width:2px;
            classDef running fill:#bae1ff,color:black,stroke:black,stroke-width:2px,stroke-dasharray: 5 5;
            classDef passed fill:#88d8b0, color:black, stroke:black;
            classDef failed fill:#ff6f69, color:black, stroke:black;
            classDef timeout fill:#ffda9e, color:black, stroke:black;
```

Co-authored-by: arjoonn sharma <arjoonn@midpathsoftware.com>
Reviewed-on: https://gitea.midpathsoftware.com/midpath/jaypore_ci/pulls/20

Diffstat:
Mjaypore_ci/executors/mock.py | 13++++---------
Mjaypore_ci/jci.py | 4+---
Mpyproject.toml | 2+-
Mtests/conftest.py | 4+++-
Mtests/test_jaypore_ci.py | 19++++++++++++++++---
5 files changed, 25 insertions(+), 17 deletions(-)

diff --git a/jaypore_ci/executors/mock.py b/jaypore_ci/executors/mock.py @@ -97,7 +97,7 @@ class Mock(Executor): for l in job.name.lower().replace(" ", "_") if l in "abcdefghijklmnopqrstuvwxyz_1234567890" ) - return f"{self.get_net()}_{name}" + return name def run(self, job: "Job") -> str: """ @@ -111,8 +111,7 @@ class Mock(Executor): if name in self.__status__: return None run_id = uuid.uuid4().hex - self.__log__.append((name, run_id, "Start")) - self.__log__.append((name, run_id, "Complete")) + self.__log__.append((name, run_id, "Run")) self.__status__[name] = self.__status__[run_id] = True self.logging().info( "Run job", @@ -135,9 +134,5 @@ class Mock(Executor): is_running, exit_code, logs = False, 0, "" return is_running, exit_code, logs - def get_log(self, query): - return [ - (i, name, *log) - for i, (name, *log) in enumerate(self.__log__) - if name == query - ] + def get_execution_order(self): + return {name: i for i, (name, *log) in enumerate(self.__log__)} diff --git a/jaypore_ci/jci.py b/jaypore_ci/jci.py @@ -458,9 +458,7 @@ flowchart {self.graph_direction} for stage in self.stages: # --- Trigger starting jobs jobs = {name: job for name, job in self.jobs.items() if job.stage == stage} - for name in { - job.name for job in jobs.values() if job.parents and not job.children - }: + for name in {job.name for job in jobs.values() if not job.parents}: jobs[name].trigger() # --- monitor and ensure all jobs run while not all(job.is_complete() for job in jobs.values()): diff --git a/pyproject.toml b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "jaypore_ci" -version = "0.1.2" +version = "0.1.3" description = "" authors = ["arjoonn sharma <arjoonn.94@gmail.com>"] diff --git a/tests/conftest.py b/tests/conftest.py @@ -7,4 +7,6 @@ from jaypore_ci import jci, executors, remotes def pipeline(): executor = executors.Mock() remote = remotes.Mock(branch="test_branch", sha="fake") - yield jci.Pipeline(executor=executor, remote=remote, poll_interval=0) + p = jci.Pipeline(executor=executor, remote=remote, poll_interval=0) + p.render_report = lambda: "" + yield p diff --git a/tests/test_jaypore_ci.py b/tests/test_jaypore_ci.py @@ -11,9 +11,8 @@ def test_simple_linear_jobs(pipeline): with pipeline as p: p.job("lint", "x") p.job("test", "x", depends_on=["lint"]) - lint_i = [i for i, *_ in pipeline.executor.get_log("lint")] - test_i = [i for i, *_ in pipeline.executor.get_log("test")] - assert all(lint < test for lint in lint_i for test in test_i) + order = pipeline.executor.get_execution_order() + assert order["lint"] < order["test"] def test_no_duplicate_names(pipeline): @@ -28,3 +27,17 @@ def test_dependency_has_to_be_defined_before_child(pipeline): with pipeline as p: p.job("x", "x", depends_on=["y"]) p.job("y", "y") + + +def test_call_chain_is_followed(pipeline): + with pipeline as p: + for name in "pq": + p.job(name, name) + p.job("x", "x") + p.job("y", "y", depends_on=["x"]) + p.job("z", "z", depends_on=["y"]) + for name in "ab": + p.job(name, name) + order = pipeline.executor.get_execution_order() + # assert order == {} + assert order["x"] < order["y"] < order["z"]