rich7420 commented on code in PR #5841:
URL: https://github.com/apache/datafusion-comet/pull/5841#discussion_r4709815584
##########
dev/ci/compute-changes.py:
##########
@@ -645,11 +678,26 @@ def release_branch_allows(job, event):
def compute(files, event):
- """Return {job: bool}, folding the path filter and the event policy."""
- return {
- name: event_allows(name, event) and matches(patterns, files)
+ """Return a new {output: bool} mapping for consumers and their native
build.
+
+ `files` is a reusable sequence of repository-relative changed paths;
+ `event` has the fields described by event_allows(). Neither input is
+ mutated. Manual dispatch selects every route even with no changed files;
+ other events require both path and event matches. The shared native build
+ is selected only after those decisions, taking the union of every caller's
+ routes, so Hive alone can start its producer and a denied opt-in route
+ cannot start an unused producer. Unknown events select nothing.
Configuration
+ lookup failures propagate as KeyError rather than returning partial output.
+ """
+ manual = event.get("name") == "workflow_dispatch"
+ outputs = {
+ name: event_allows(name, event) and (manual or matches(patterns,
files))
for name, patterns in FILTERS.items()
}
+ outputs["build_linux_native"] = any(
Review Comment:
When rebasing onto main, could the early return for fork syncs in
`compute()` (#7705) also derive `build_linux_native`, so the producer isn't
skipped?
##########
.github/workflows/build_linux_native.yml:
##########
@@ -0,0 +1,86 @@
+# 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.
+
+# Single producer for the default Linux CI native library. The umbrella runs
+# this whenever any Linux, Spark SQL, or Iceberg test consumer is selected.
+name: Build Linux Native Library
+
+on:
+ workflow_call:
+
+permissions:
+ contents: read
+
+env:
+ RUST_VERSION: stable
+ RUST_BACKTRACE: 1
+
+jobs:
+ build-native:
Review Comment:
For the rebase, could these new and moved jobs carry over the
`timeout-minutes` settings now on main (#7679)?
##########
dev/ci/check-ci-config.py:
##########
@@ -878,50 +909,365 @@ def check_docs_deploy_guard():
return False
-def artifact_names(path):
- """Return ([upload names], [download names]) for one workflow file."""
- uploads, downloads = [], []
+def artifact_steps(path):
+ """Return artifact steps and their direct `with:` inputs."""
+ artifacts = []
lines = path.read_text(encoding="utf-8").splitlines()
for index, line in enumerate(lines):
if UPLOAD_USES.search(line):
- bucket = uploads
+ kind = "upload"
elif DOWNLOAD_USES.search(line):
- bucket = downloads
+ kind = "download"
else:
continue
+ indent = len(line) - len(line.lstrip())
+ body = []
for following in lines[index + 1:]:
- if NEW_STEP.match(following):
- break # step ended without a `name:`; download-all, or the
default
- match = WITH_NAME.match(following)
- if match:
- bucket.append(match.group(1))
- break
- return uploads, downloads
+ if following.strip() and not following.lstrip().startswith("#"):
+ if NEW_STEP.match(following) or len(following) -
len(following.lstrip()) < indent:
+ break
+ body.append(following)
+ text = "\n".join(body)
+ with_key = re.search(r"^( +)with:\s*$", text, re.MULTILINE)
+ if with_key:
+ with_indent = len(with_key.group(1))
+ inputs = block_mapping(block_mapping(text,
with_indent)["with"][1], with_indent + 2)
+ artifacts.append((kind, {key: scalar(value) for key, (value, _) in
inputs.items()}))
+ return artifacts
-def check_artifact_names():
- ci = (WORKFLOWS / "ci.yml").read_text(encoding="utf-8")
+def artifact_names(path):
+ """Return ([upload names], [download names]) for one workflow file."""
+ steps = artifact_steps(path)
+ return tuple([inputs["name"] for kind, inputs in steps if kind == expected
and "name" in inputs]
+ for expected in ("upload", "download"))
+
+
+def block_mapping(text, indent):
+ """Read block-style keys at the workflow files' conventional indentation.
+
+ This only inspects the small mapping subset needed by the guards below;
+ actionlint remains responsible for validating GitHub Actions YAML syntax.
+ Values are (inline value, indented body), so scalar inputs and nested
+ workflow/job mappings can be checked without a third-party YAML dependency.
+ """
+ pattern = re.compile(r"^" + " " * indent + r"([\w-]+):[^\S\n]*(.*)$",
re.MULTILINE)
+ matches = list(pattern.finditer(text))
+ return {
+ match.group(1): (match.group(2).strip(),
+ text[match.end():matches[index + 1].start()
+ if index + 1 < len(matches) else len(text)])
+ for index, match in enumerate(matches)
+ }
+
+
+def scalar(value):
+ return value.strip().strip("\"'")
+
+
+def linux_mode_input_failures(workflows, name, expected):
+ """Check each Linux caller's mode expression, including folded YAML
scalars."""
+ ci = (workflows / "ci.yml").read_text(encoding="utf-8")
+ jobs = block_mapping(block_mapping(ci, 0).get("jobs", ("", ""))[1], 2)
+ failures = []
+ for job_id in LINUX_MODE_CALLERS:
+ fields = block_mapping(jobs.get(job_id, ("", ""))[1], 4)
+ inputs = block_mapping(fields.get("with", ("", ""))[1], 6)
+ value, body = inputs.get(name, ("", ""))
+ expression = body if value in {"|", "|-", ">", ">-"} else value
+ actual = " ".join(line.strip() for line in expression.splitlines()
+ if line.strip() and not
line.lstrip().startswith("#"))
+ if actual != expected:
+ failures.append(f"ci.yml: {job_id} must pass {name}: {expected}")
+ return failures
+
+
+def linux_profile_failures(workflows):
+ """Keep profile selection connected after splitting out the native
producer."""
+ failures = linux_mode_input_failures(workflows, "profiles",
PROFILES_EXPRESSION)
+ path = workflows / "pr_build_linux.yml"
+ if not path.exists():
+ return failures + [f"{path}: Linux test workflow is missing"]
+ text = path.read_text(encoding="utf-8")
+ jobs = block_mapping(block_mapping(text, 0).get("jobs", ("", ""))[1], 2)
+ prepare = jobs.get("prepare-matrix", ("", ""))[1]
+ outputs = block_mapping(block_mapping(prepare, 4).get("outputs", ("",
""))[1], 6)
+ if outputs.get("profile-matrix", ("", ""))[0] != "${{
steps.profiles.outputs.matrix }}":
+ failures.append(f"{path}: prepare-matrix must publish
steps.profiles.outputs.matrix")
+ test = jobs.get("linux-test", ("", ""))[1]
+ strategy = block_mapping(block_mapping(test, 4).get("strategy", ("",
""))[1], 6)
+ matrix = block_mapping(strategy.get("matrix", ("", ""))[1], 8)
+ if ("prepare-matrix" not in dependencies(test)
+ or matrix.get("profile", ("", ""))[0]
+ != "${{ fromJSON(needs.prepare-matrix.outputs.profile-matrix) }}"):
+ failures.append(f"{path}: linux-test must consume prepare-matrix's
profile-matrix output")
+ return failures
+
+
+def dependencies(job):
+ value, body = block_mapping(job, 4).get("needs", ("", ""))
+ if value.startswith("[") and value.endswith("]"):
+ return {scalar(item) for item in value[1:-1].split(",")}
+ if value:
+ return {scalar(value)}
+ return {scalar(item) for item in re.findall(r"^\s+- (.+)$", body,
re.MULTILINE)}
+
+
+def shared_native_failures(workflows, jobs, artifacts):
+ """Validate the sole allowed cross-workflow artifact producer/consumer
edge."""
+ failures = []
+ producer_uses = f"./.github/workflows/{SHARED_NATIVE_WORKFLOW}"
+ calls = [job_id for job_id, (_, body) in jobs.items()
+ if scalar(block_mapping(body, 4).get("uses", ("", ""))[0]) ==
producer_uses]
+ if calls != [SHARED_NATIVE_JOB]:
+ failures.append(f"ci.yml: expected exactly one {SHARED_NATIVE_JOB}
call to {producer_uses}")
+
+ if SHARED_NATIVE_JOB in jobs:
+ body = jobs[SHARED_NATIVE_JOB][1]
+ if "changes" not in dependencies(body):
+ failures.append(f"ci.yml: {SHARED_NATIVE_JOB} must need changes")
+ if "strategy" in block_mapping(body, 4):
+ failures.append(f"ci.yml: {SHARED_NATIVE_JOB} must not use a
matrix")
+ for filename, (uploads, _) in artifacts.items():
+ if filename != SHARED_NATIVE_WORKFLOW and SHARED_NATIVE_ARTIFACT in
uploads:
+ failures.append(f"{filename}: only {SHARED_NATIVE_WORKFLOW} may
upload '{SHARED_NATIVE_ARTIFACT}'")
+
+ producer = workflows / SHARED_NATIVE_WORKFLOW
+ if not producer.exists():
+ failures.append(f"{producer}: shared native producer is missing")
+ else:
+ producer_jobs = block_mapping(
+ block_mapping(producer.read_text(encoding="utf-8"), 0).get("jobs",
("", ""))[1], 2)
+ uploads = artifacts[SHARED_NATIVE_WORKFLOW][0]
+ if len(producer_jobs) != 1 or uploads != [SHARED_NATIVE_ARTIFACT]:
+ failures.append(f"{producer}: expected one job uploading
'{SHARED_NATIVE_ARTIFACT}' once")
+ for _, body in producer_jobs.values():
+ if "strategy" in block_mapping(body, 4):
+ failures.append(f"{producer}: shared native producer must not
use a matrix")
+
+ seen_consumers = set()
+ for job_id, (_, body) in jobs.items():
+ fields = block_mapping(body, 4)
+ called = scalar(fields.get("uses", ("",
""))[0]).removeprefix("./.github/workflows/")
+ if called not in SHARED_NATIVE_CONSUMERS:
+ continue
+ seen_consumers.add(called)
+ if not {"changes", SHARED_NATIVE_JOB}.issubset(dependencies(body)):
+ failures.append(f"ci.yml: {job_id} must need changes and
{SHARED_NATIVE_JOB}")
+ inputs = block_mapping(fields.get("with", ("", ""))[1], 6)
+ if scalar(inputs.get(SHARED_NATIVE_INPUT, ("", ""))[0]) !=
SHARED_NATIVE_ARTIFACT:
+ failures.append(f"ci.yml: {job_id} must pass
{SHARED_NATIVE_INPUT}: {SHARED_NATIVE_ARTIFACT}")
+
+ for filename in sorted(SHARED_NATIVE_CONSUMERS):
+ path = workflows / filename
+ if filename not in seen_consumers:
+ failures.append(f"ci.yml: shared native consumer {filename} is not
called")
+ if not path.exists():
+ failures.append(f"{path}: shared native consumer is missing")
+ continue
+ text = path.read_text(encoding="utf-8")
+ declaration = text
+ for key, indent in (("on", 0), ("workflow_call", 2), ("inputs", 4),
+ (SHARED_NATIVE_INPUT, 6)):
+ declaration = block_mapping(declaration, indent).get(key, ("",
""))[1]
+ fields = block_mapping(declaration, 8)
+ if (scalar(fields.get("required", ("", ""))[0]) != "true"
+ or scalar(fields.get("type", ("", ""))[0]) != "string"):
+ failures.append(f"{path}: {SHARED_NATIVE_INPUT} must be a required
string input")
+ uploads, downloads = artifacts[filename]
+ if SHARED_NATIVE_EXPRESSION not in downloads:
+ failures.append(f"{path}: must download
{SHARED_NATIVE_EXPRESSION}")
+ if any(name.startswith("native-lib") or name ==
SHARED_NATIVE_EXPRESSION for name in uploads):
+ failures.append(f"{path}: native library must only be uploaded by
{SHARED_NATIVE_WORKFLOW}")
+ native_destinations = [inputs.get("name") for kind, inputs in
artifact_steps(path)
+ if kind == "download" and inputs.get("path",
"").startswith("native/target")]
+ if (any(name.startswith("native-lib") for name in downloads)
+ or any(name != SHARED_NATIVE_EXPRESSION for name in
native_destinations)):
+ failures.append(f"{path}: native downloads must use
{SHARED_NATIVE_EXPRESSION}")
+ if re.search(r"^\s*(?:cargo build\b|make (?:release|core)\b)", text,
re.MULTILINE):
+ failures.append(f"{path}: must consume the shared native library
instead of building it")
+ return failures
+
+
+def linux_checks_failures(workflows, jobs):
+ """Keep lint, compile-only and debug Rust checks independent of native
CI."""
+ failures = []
+ body = jobs.get(LINUX_CHECKS_JOB, ("", ""))[1]
+ fields = block_mapping(body, 4)
+ expected_uses = f"./.github/workflows/{LINUX_CHECKS_WORKFLOW}"
+ if scalar(fields.get("uses", ("", ""))[0]) != expected_uses:
+ failures.append(f"ci.yml: {LINUX_CHECKS_JOB} must call
{expected_uses}")
+ if dependencies(body) != {"changes"}:
+ failures.append(f"ci.yml: {LINUX_CHECKS_JOB} must need only changes,
independently of native CI")
+
+ def condition(job):
+ value, body = block_mapping(job, 4).get("if", ("", ""))
+ text = body if value in {"|", ">"} else value
+ return " ".join(line.strip() for line in text.splitlines()
+ if line.strip() and not line.lstrip().startswith("#"))
+
+ if condition(body) != condition(jobs.get("pr_build_linux", ("", ""))[1]):
+ failures.append(f"ci.yml: {LINUX_CHECKS_JOB} must use the Linux test
selection condition")
+
+ checks = workflows / LINUX_CHECKS_WORKFLOW
+ if not checks.exists():
+ failures.append(f"{checks}: independent Linux checks workflow is
missing")
+ return failures
+ text = checks.read_text(encoding="utf-8")
+ check_jobs = block_mapping(block_mapping(text, 0).get("jobs", ("",
""))[1], 2)
+ missing = INDEPENDENT_LINUX_JOBS - check_jobs.keys()
+ if missing:
+ failures.append(f"{checks}: independent jobs are missing: {',
'.join(sorted(missing))}")
+ events = block_mapping(text, 0).get("on", ("", ""))[1]
+ workflow_call = block_mapping(events, 2).get("workflow_call", ("", ""))[1]
+ inputs = block_mapping(block_mapping(workflow_call, 4).get("inputs", ("",
""))[1], 6)
+ if SHARED_NATIVE_INPUT in inputs or any(
+ kind == "download" and (inputs.get("name",
"").startswith("native-lib")
+ or inputs.get("path",
"").startswith("native/target"))
+ for kind, inputs in artifact_steps(checks)):
+ failures.append(f"{checks}: independent Linux checks must not consume
the shared native artifact")
+
+ consumers = workflows / "pr_build_linux.yml"
+ if consumers.exists():
+ consumer_jobs = block_mapping(
+ block_mapping(consumers.read_text(encoding="utf-8"),
0).get("jobs", ("", ""))[1], 2)
+ misplaced = INDEPENDENT_LINUX_JOBS & consumer_jobs.keys()
+ if misplaced:
+ failures.append(f"{consumers}: independent jobs must stay in
{LINUX_CHECKS_WORKFLOW}: "
+ f"{', '.join(sorted(misplaced))}")
+ return failures
+
+
+def native_selection_failures(jobs):
+ """Return errors when workflow gates diverge from the Python selector.
+
+ `jobs` is the ci.yml job mapping returned by block_mapping, with each value
+ holding an inline scalar and indented body. The selector maps actual caller
+ IDs to tuples of selection outputs; each caller must use exactly their OR
+ (a single comparison for one output), and export every output directly.
+ For example, spark_4_1 accepts either its core or Hive output, while the
+ producer has one derived output. Expressions are compared, not evaluated.
+ Inputs and files are not mutated; import/read errors propagate.
+ """
+ consumers = load_filters().NATIVE_CONSUMERS
+ actual_consumers = {
+ job_id for job_id, (_, body) in jobs.items()
+ if scalar(block_mapping(body, 4).get("uses", ("", ""))[0])
+ .removeprefix("./.github/workflows/") in SHARED_NATIVE_CONSUMERS
+ }
+ failures = []
+ if actual_consumers != consumers.keys():
+ failures.append("ci.yml: native consumer calls must match
NATIVE_CONSUMERS "
+ "in compute-changes.py")
+ changes = block_mapping(jobs.get("changes", ("", ""))[1], 4)
+ outputs = block_mapping(changes.get("outputs", ("", ""))[1], 6)
+ selections = {SHARED_NATIVE_JOB: (SHARED_NATIVE_JOB,), **consumers}
+ for job_id, routes in selections.items():
+ fields = block_mapping(jobs.get(job_id, ("", ""))[1], 4)
+ expected = " || ".join(f"needs.changes.outputs.{output} == 'true'" for
output in routes)
+ if fields.get("if", ("", ""))[0] != expected:
+ failures.append(f"ci.yml: {job_id} must select exactly {expected}")
+ for output in routes:
+ if outputs.get(output, ("", ""))[0] != f"${{{{
steps.compute.outputs.{output} }}}}":
+ failures.append(f"ci.yml: changes must export
steps.compute.outputs.{output}")
+ return failures
+
+
+def job_steps(job):
+ """Return ordered step mappings from a conventional workflow job body.
+
+ `job` is the indented text from block_mapping. Only the direct `steps:`
+ list at six spaces is read; each result uses block_mapping's (scalar,
+ body) values. Replacing each list marker with spaces lets that existing
+ parser read step keys at eight spaces without inspecting nested actions.
+ This reads a string, mutates nothing, and returns an empty list if absent;
+ actionlint remains responsible for other YAML layouts and syntax errors.
+ """
+ body = block_mapping(job, 4).get("steps", ("", ""))[1]
+ starts = list(re.finditer(r"^ - ", body, re.MULTILINE))
+ return [block_mapping(" " + body[start.end():
+ starts[index + 1].start() if index + 1 < len(starts)
else len(body)], 8)
+ for index, start in enumerate(starts)]
+
+
+def linux_maven_bootstrap_failures(workflows):
+ """Return errors for Linux Maven runs without a prior reliable bootstrap.
+
+ `workflows` is a directory Path. Read only the two Linux reusable workflows
+ and their direct job steps; composite actions own their internal bootstrap.
+ Each direct ./mvnw run needs an earlier maven-bootstrap step in the same
job
+ with no `if` and with failures propagated. Comments and non-run fields do
+ not count as commands. No files or mappings are mutated; missing workflows
+ produce errors, other file-read errors propagate, and success returns [].
+ """
+ failures = []
+ for filename in LINUX_MAVEN_WORKFLOWS:
+ path = workflows / filename
+ if not path.exists():
+ failures.append(f"{path}: Linux Maven workflow is missing")
+ continue
+ jobs = block_mapping(block_mapping(path.read_text(encoding="utf-8"), 0)
+ .get("jobs", ("", ""))[1], 2)
+ for job_id, (_, body) in jobs.items():
+ bootstrapped = False
+ for step in job_steps(body):
+ if (scalar(step.get("uses", ("", ""))[0]) in
{MAVEN_BOOTSTRAP_ACTION, "./.github/actions/setup-builder"}
+ and "if" not in step
+ and scalar(step.get("continue-on-error", ("false",
""))[0]) == "false"):
+ bootstrapped = True
+ value, script = step.get("run", ("", ""))
+ script = script if value in {"|", ">", "|-", ">-", "|+", ">+"}
else scalar(value)
+ commands = "\n".join(line for line in script.splitlines()
+ if not line.lstrip().startswith("#"))
+ if (re.search(r"(?<![\w./])\./mvnw(?:\s|$)", commands)
+ or scalar(step.get("uses", ("", ""))[0]) ==
"./.github/actions/setup-spark-builder") and not bootstrapped:
+ failures.append(f"{path}: {job_id} must bootstrap Maven
unconditionally "
+ "with failures propagated before running
./mvnw")
+ return failures
+
+
+def artifact_failures(workflows):
+ """Return artifact, routing, independence, and Linux Maven bootstrap
errors.
+
+ `workflows` is a directory Path containing ci.yml and the reusable
workflows.
+ Files and parsed mappings are read only. An empty list means all invariants
+ passed; file-read and selector-import errors propagate to the caller.
+ """
+ ci = (workflows / "ci.yml").read_text(encoding="utf-8")
+ jobs = block_mapping(block_mapping(ci, 0).get("jobs", ("", ""))[1], 2)
call_counts = {}
for called in re.findall(r"uses:\s*\./\.github/workflows/(\S+)", ci):
call_counts[called] = call_counts.get(called, 0) + 1
- failures = []
- for path in sorted(WORKFLOWS.glob("*.y*ml")):
- uploads, downloads = artifact_names(path)
- if call_counts.get(path.name, 0) > 1:
+ artifacts = {path.name: artifact_names(path) for path in
sorted(workflows.glob("*.y*ml"))}
+ failures = shared_native_failures(workflows, jobs, artifacts)
+ failures.extend(linux_checks_failures(workflows, jobs))
+ failures.extend(native_selection_failures(jobs))
+ failures.extend(linux_maven_bootstrap_failures(workflows))
+ shared_wiring_valid = not failures
Review Comment:
Could this be computed right after `shared_native_failures(...)`? An
unrelated failure, like a missing Maven bootstrap step, also prints eight
"downloaded but never uploaded" errors for me.
--
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]