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 e0a43e7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build-notebooks-TEMPLATE.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ jobs:
- name: "pull_request: make ${{ inputs.target }}"
run: |
# start a black hole container registry as make target always does a push
mkdir -p $HOME/.config/containers/registries.conf.d/
cp ci/insecure_localhost_registry.conf $HOME/.config/containers/registries.conf.d/insecure_localhost_registry.conf
go run ci/dev_null_container_registry.go &
# build and push the image
make ${{ inputs.target }}
Expand Down
7 changes: 4 additions & 3 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,16 +13,17 @@ 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
build:
needs: [ "gen" ]
needs: ["gen"]
strategy:
fail-fast: false
matrix: "${{ fromJson(needs.gen.outputs.matrix) }}"
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
File renamed without changes.

0 comments on commit e0a43e7

Please sign in to comment.