Skip to content

Commit

Permalink
Make cache for generator predictable
Browse files Browse the repository at this point in the history
This commit adds sorting of ZuulJobs entries so when cached
the produced output is always predictable and repeatable
across multiple calls to generator, no matter who, where
and when executes the code. This should allow us to include
small incremental changes in cache file when regenerating
the cache periodically for any upstream changes.
  • Loading branch information
sdatko committed Jan 25, 2024
1 parent c3e11ea commit 71b14ad
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion znoyder/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def fetch_osp_projects(branch: str, filters: dict) -> list:

@cache('path', readable=True)
def discover_upstream_jobs(path, templates, pipelines):
return finder.find_jobs(path, templates, pipelines)
return sorted(finder.find_jobs(path, templates, pipelines))


def discover_jobs(project_name, osp_tag, directory,
Expand Down
2 changes: 1 addition & 1 deletion znoyder/lib/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def save(self):
self._cache,
Dumper=NoAliasDumper,
default_flow_style=False,
sort_keys=False,
sort_keys=True,
width=math.inf,
)
file.write(data)
Expand Down
6 changes: 6 additions & 0 deletions znoyder/lib/zuul.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,12 @@ def __eq__(self, other) -> bool:
and self.pipeline == other.pipeline
)

def __lt__(self, other) -> bool:
if self.name == other.name:
return self.pipeline < other.pipeline

return self.name < other.name

def really_equal(self, other) -> bool:
return type(other) is type(self) and (
self.name == other.name
Expand Down

0 comments on commit 71b14ad

Please sign in to comment.