From e0a43e7a5ed4bf6e2597f13b4e829744cbbd5716 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jiri=20Dan=C4=9Bk?= Date: Fri, 31 May 2024 19:29:19 +0200 Subject: [PATCH] squash-me, use new job with fake registry for handling pull request --- .github/workflows/build-notebooks-TEMPLATE.yaml | 2 ++ .github/workflows/build-notebooks-pr.yaml | 7 ++++--- ci/gen_gha_matrix_jobs.py | 16 ++++++++++------ ...try.conf => insecure_localhost_registry.conf} | 0 4 files changed, 16 insertions(+), 9 deletions(-) rename ci/{insecure-localhost-registry.conf => insecure_localhost_registry.conf} (100%) diff --git a/.github/workflows/build-notebooks-TEMPLATE.yaml b/.github/workflows/build-notebooks-TEMPLATE.yaml index e7b804d07..13ff9ae13 100644 --- a/.github/workflows/build-notebooks-TEMPLATE.yaml +++ b/.github/workflows/build-notebooks-TEMPLATE.yaml @@ -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 }} diff --git a/.github/workflows/build-notebooks-pr.yaml b/.github/workflows/build-notebooks-pr.yaml index e1380370a..12eb52780 100644 --- a/.github/workflows/build-notebooks-pr.yaml +++ b/.github/workflows/build-notebooks-pr.yaml @@ -1,5 +1,5 @@ --- -"name": "Build Notebooks", +"name": "Build Notebooks" "permissions": "packages": "read" "on": @@ -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 diff --git a/ci/gen_gha_matrix_jobs.py b/ci/gen_gha_matrix_jobs.py index 8d766bb18..ede2d717a 100644 --- a/ci/gen_gha_matrix_jobs.py +++ b/ci/gen_gha_matrix_jobs.py @@ -1,3 +1,4 @@ +import itertools import json import os import pathlib @@ -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 = [] @@ -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: @@ -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: diff --git a/ci/insecure-localhost-registry.conf b/ci/insecure_localhost_registry.conf similarity index 100% rename from ci/insecure-localhost-registry.conf rename to ci/insecure_localhost_registry.conf