Skip to content

Commit

Permalink
squash-me, use new job with fake registry for handling pull request
Browse files Browse the repository at this point in the history
  • Loading branch information
jiridanek committed May 31, 2024
1 parent 8be6898 commit fe9e503
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/build-notebooks-pr.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
"name": "Build Notebooks",
"name": "Build Notebooks"
"permissions":
"packages": "read"
"on":
Expand All @@ -13,7 +13,7 @@ jobs:
matrix: ${{ steps.gen.outputs.matrix }}
steps:
- uses: actions/checkout@v4
- run: python3 gen_gha_matrix_jobs.py
- run: python3 ci/gen_gha_matrix_jobs.py
id: gen

# base images
Expand All @@ -25,4 +25,5 @@ jobs:
uses: ./.github/workflows/build-notebooks-TEMPLATE.yaml
with:
target: "${{ matrix.target }}"
github: "${{ toJSON(github) }}"
secrets: inherit
16 changes: 10 additions & 6 deletions ci/gen_gha_matrix_jobs.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import itertools
import json
import os
import pathlib
Expand Down Expand Up @@ -110,12 +111,16 @@ def write_github_workflow_file(tree: dict[str, list[str]], path: pathlib.Path) -
json.dump(workflow, f, sort_keys=False, indent=4)
print(file=f)


def flatten(list_of_lists):
return list(itertools.chain.from_iterable(list_of_lists))

def compute_leafs_in_dependency_tree(tree: dict[str, list[str]]) -> list[str]:
key_set = set(tree.keys())
value_set = set(*tree.values())
value_set = set(flatten(tree.values()))
return [key for key in key_set if key not in value_set]

def print_github_actions_pr_matrix(tree: dict[str, list[str]], leafs: list[str]) -> str:
def print_github_actions_pr_matrix(tree: dict[str, list[str]], leafs: list[str]) -> list[str]:
"""Outputs GitHub matrix definition Json
"""
targets = []
Expand All @@ -131,7 +136,7 @@ def print_github_actions_pr_matrix(tree: dict[str, list[str]], leafs: list[str])
targets.append(leaf)

matrix = {"target": targets}
return f"matrix={json.dumps(matrix, separators=(",", ":"))}"
return [f"matrix={json.dumps(matrix, separators=(',', ':'))}"]


def main() -> None:
Expand All @@ -143,10 +148,9 @@ def main() -> None:
write_github_workflow_file(tree, project_dir / ".github" / "workflows" / "build-notebooks.yaml")

leafs = compute_leafs_in_dependency_tree(tree)
output = print_github_actions_pr_matrix(leafs)

write_github_workflow_file(tree)
output = print_github_actions_pr_matrix(tree, leafs)

print("leafs", leafs)
print(*output, sep="\n")
with open(os.environ["GITHUB_OUTPUT"], "at") as f:
for line in output:
Expand Down

0 comments on commit fe9e503

Please sign in to comment.