bitflicker64 commented on code in PR #3271: URL: https://github.com/apache/hugegraph/pull/3271#discussion_r4191336537
########## .github/scripts/ci-policy.py: ########## @@ -0,0 +1,573 @@ +#!/usr/bin/env python3 +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Conservative CI selection and GitHub-verified test receipt reuse.""" + +import argparse +import base64 +import hashlib +import io +import json +import os +from pathlib import Path +import subprocess +import zipfile +from urllib.parse import urlencode + +MODULES = { + "server": ["server", "commons", "struct", "pd", "store", "hstore", "cluster", "docker", "helm", "dependency_license"], + "toolchain": ["client", "loader", "tools", "spark", "hubble", "go"], +} +PREFIXES = { + "server": {"hugegraph-server/": "server", "hugegraph-commons/": "commons", + "hugegraph-struct/": "struct", "hugegraph-pd/": "pd", "hugegraph-store/": "store", + "hugegraph-cluster-test/": "cluster", "docker/": "docker", "helm/": "helm"}, + "toolchain": {"hugegraph-client/": "client", "hugegraph-client-go/": "go", + "hugegraph-loader/": "loader", "hugegraph-tools/": "tools", + "hugegraph-spark-connector/": "spark", "hugegraph-hubble/": "hubble"}, +} +WORKFLOWS = { + "server": {"server-ci.yml": MODULES["server"], "commons-ci.yml": ["commons"], + "pd-store-ci.yml": ["pd", "store", "hstore"], "cluster-test-ci.yml": ["cluster"], + "docker-build-ci.yml": ["docker"], "helm-chart-ci.yml": ["helm"], + "codeql-analysis.yml": [], "riscv64-ci.yml": ["server"], "check-dependencies.yml": ["dependency_license"]}, + "toolchain": {"client-ci.yml": ["client"], "client-go-ci.yml": ["go"], + "loader-ci.yml": ["loader"], "tools-ci.yml": ["tools"], + "spark-connector-ci.yml": ["spark"], "hubble-ci.yml": ["hubble"], + "codeql-analysis.yml": []}, +} +DEPENDENTS = { + "server": {"commons": ["server", "pd", "store", "hstore", "cluster"], + "struct": ["server", "pd", "store", "hstore", "cluster"], + "server": ["pd", "store", "hstore", "cluster"], "pd": ["store", "hstore", "cluster"], + "store": ["hstore", "cluster"], "hstore": ["cluster"]}, + "toolchain": {"client": ["loader", "tools", "spark", "hubble"], "loader": ["hubble"]}, +} + + +def git(*args): + return subprocess.check_output(["git", *args], text=True).strip() + + +def api(path, binary=False): + result = subprocess.run(["gh", "api", "--method", "GET", path], check=True, capture_output=True, timeout=30) + return result.stdout if binary else json.loads(result.stdout) + + +def documentation(path, mode="100644"): + """Only prose and static documentation assets; never source or config.""" + if mode != "100644": + return False + p = Path(path) + prose_names = {"README.md", "README_CN.md", "README_ZH.md", "AGENTS.md"} + module_roots = {prefix.rstrip("/") for mapping in PREFIXES.values() for prefix in mapping} + module_roots.update("hugegraph-server/" + module for module in [ + "hugegraph-api", "hugegraph-core", "hugegraph-dist", "hugegraph-example", + "hugegraph-hbase", "hugegraph-hstore", "hugegraph-rocksdb", "hugegraph-test"]) + if p.name in prose_names and (str(p.parent) == "." or str(p.parent) in module_roots): + return True + return path.startswith("docs/") and p.suffix.lower() in {".md", ".rst", ".txt", ".png", ".jpg", ".jpeg", ".svg"} + + +def unsafe_documentation(ref, paths): + entries = subprocess.check_output(["git", "ls-tree", "-rz", "--full-tree", ref]).split(b"\0") + for entry in entries: + if not entry: + continue + metadata, name = entry.split(b"\t", 1) + path = name.decode("utf-8", "surrogateescape") + if path in paths and documentation(path) and metadata.split(b" ", 1)[0] != b"100644": + return True + return False + + +def select(project, paths): + selected = set() + for path in paths: + if documentation(path): + continue + if project == "server" and (Path(path).name == "pom.xml" or path.startswith("install-dist/")): + selected.add("dependency_license") + if path.startswith(".github/workflows/") and Path(path).name in WORKFLOWS[project]: + selected.update(WORKFLOWS[project][Path(path).name]) + continue + if path.endswith(".proto"): + return set(MODULES[project]) + if project == "server" and path == "hugegraph-commons/hugegraph-common/src/main/resources/version.properties": + selected.update(["commons", "docker"]) + continue + if project == "server" and path == "hugegraph-store/hg-store-dist/src/assembly/static/bin/util.sh": + selected.update(["store", "docker"]) + continue + if project == "toolchain" and path.startswith("hugegraph-client/assembly/travis/"): + selected.update(["client", "go"]) + continue + if project == "server": + if path.startswith("hugegraph-server/hugegraph-hstore/"): + selected.update(["server", "hstore"]) + continue + if path.startswith("hugegraph-server/hugegraph-dist/"): Review Comment: Important: Server distribution changes select the Docker suite here, but PD and Store distribution changes do not, although the PD and Store images ship those files. `select("server", ["hugegraph-pd/hg-pd-dist/src/assembly/static/conf/application.yml"])` returns suites `[cluster, pd_store]`, and so do the Store `conf/application.yml` and `bin/start-hugegraph-pd.sh`. For comparison, `hugegraph-server/hugegraph-dist/.../conf/rest-server.properties` returns `[cluster, docker, pd_store, server_memory, server_rocksdb]`. `hugegraph-pd/Dockerfile:63` copies the assembled PD dist into the image, and `hugegraph-pd/hg-pd-dist/docker/docker-entrypoint.sh:146` starts it with `bin/start-hugegraph-pd.sh`. The PD readiness, registered-store and 401/authenticated `/v1/stores` checks in `docker-deployment.py` depend on that config, and they are the only tests that start the images. A change to the PD auth block in `application.yml` would pass `affected-module-tests` without them. `docs/ci.md` line 10 says distribution changes get Docker coverage, and on master Docker Build CI ran for `hugegraph-pd/**` and `hugegraph-store/**`. Please route `hugegraph-pd/hg-pd-dist/` and `hugegraph-store/hg-store-dist/` to `docker` as well as `pd`/`store`, as this branch does for `hugegraph-server/hugegraph-dist/`, and add a `test_ci_policy.py` case for each. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
