This is an automated email from the ASF dual-hosted git repository.

kaxil pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new f2ef828d522 Skip Gradle in the Java SDK schema sync hook when the 
schema is already in sync (#73539)
f2ef828d522 is described below

commit f2ef828d522c16411c4055dbddeaabdc6f64acc6
Author: Kaxil Naik <[email protected]>
AuthorDate: Tue Sep 22 13:42:27 2026 +0100

    Skip Gradle in the Java SDK schema sync hook when the schema is already in 
sync (#73539)
---
 .pre-commit-config.yaml                            |  4 +-
 scripts/ci/prek/sync_java_sdk_supervisor_schema.py | 80 ++++++++++++++++++++++
 2 files changed, 82 insertions(+), 2 deletions(-)

diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index b9914c031ed..9b4b05b804a 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -272,8 +272,8 @@ repos:
       - id: sync-java-sdk-supervisor-schema
         name: Sync Java SDK supervisor schema with configured version
         description: "Download the Supervisor Schema when Java SDK's bundled 
schema.json drifts"
-        entry: ./java-sdk/gradlew -p ./java-sdk :sdk:syncSupervisorSchema
-        language: system
+        entry: ./scripts/ci/prek/sync_java_sdk_supervisor_schema.py
+        language: python
         pass_filenames: false
         files: >
           (?x)
diff --git a/scripts/ci/prek/sync_java_sdk_supervisor_schema.py 
b/scripts/ci/prek/sync_java_sdk_supervisor_schema.py
new file mode 100755
index 00000000000..d3f4d271a5f
--- /dev/null
+++ b/scripts/ci/prek/sync_java_sdk_supervisor_schema.py
@@ -0,0 +1,80 @@
+#!/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.
+"""
+Keep the Java SDK's bundled Supervisor Schema in sync with 
``airflowSupervisorSchemaVersion``.
+
+The Gradle task ``:sdk:syncSupervisorSchema`` downloads a fresh 
``schema.json`` when the
+``api_version`` inside it differs from the version declared in 
``java-sdk/gradle.properties``.
+Starting Gradle for that comparison costs over a minute on a cold CI runner 
(wrapper download,
+JVM start, plugin resolution), so this hook does the same comparison in Python 
first and only
+hands over to Gradle when the two versions actually differ.
+"""
+
+from __future__ import annotations
+
+import json
+import re
+import subprocess
+import sys
+from pathlib import Path
+
+REPO_ROOT = Path(__file__).resolve().parents[3]
+JAVA_SDK_DIR = REPO_ROOT / "java-sdk"
+GRADLE_PROPERTIES = JAVA_SDK_DIR / "gradle.properties"
+SCHEMA_FILE = JAVA_SDK_DIR / "sdk" / "schema" / "schema.json"
+
+VERSION_PATTERN = 
re.compile(r"^airflowSupervisorSchemaVersion\s*=\s*(\S+)\s*$", re.MULTILINE)
+
+
+def configured_version() -> str:
+    match = VERSION_PATTERN.search(GRADLE_PROPERTIES.read_text())
+    if not match:
+        print(f"airflowSupervisorSchemaVersion is not set in 
{GRADLE_PROPERTIES}", file=sys.stderr)
+        sys.exit(1)
+    return match.group(1)
+
+
+def bundled_version() -> str | None:
+    if not SCHEMA_FILE.exists():
+        return None
+    try:
+        with SCHEMA_FILE.open() as schema:
+            return json.load(schema).get("api_version")
+    except json.JSONDecodeError:
+        # A truncated or conflict-marked file counts as drift; Gradle 
overwrites it.
+        return None
+
+
+def main() -> int:
+    expected = configured_version()
+    actual = bundled_version()
+    if actual == expected:
+        print(f"Supervisor Schema is up-to-date (api_version={expected}).")
+        return 0
+    print(
+        f"Supervisor Schema api_version={actual!r} differs from configured 
{expected!r}, syncing via Gradle."
+    )
+    result = subprocess.run(
+        [str(JAVA_SDK_DIR / "gradlew"), "-p", str(JAVA_SDK_DIR), 
":sdk:syncSupervisorSchema"],
+        check=False,
+    )
+    return result.returncode
+
+
+if __name__ == "__main__":
+    sys.exit(main())

Reply via email to