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

uranusjr 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 2d1aaab9ec0 Use pre-commit hook to keep Java versions in sync (#68448)
2d1aaab9ec0 is described below

commit 2d1aaab9ec034feb09323befb25a36a8457bb46d
Author: Tzu-ping Chung <[email protected]>
AuthorDate: Sat Jun 13 04:39:10 2026 +0800

    Use pre-commit hook to keep Java versions in sync (#68448)
---
 .github/workflows/ci-amd.yml                       |   5 -
 .github/workflows/ci-arm.yml                       |   5 -
 .github/workflows/codeql-analysis.yml              |   5 -
 .pre-commit-config.yaml                            |  12 ++
 .../main/kotlin/airflow-jvm-conventions.gradle.kts |   7 +-
 scripts/ci/prek/check_java_sdk_version_in_sync.py  | 132 +++++++++++++++++++++
 scripts/docker/install_jdk.sh                      |   5 -
 7 files changed, 146 insertions(+), 25 deletions(-)

diff --git a/.github/workflows/ci-amd.yml b/.github/workflows/ci-amd.yml
index dc339cf1c5c..43276945a9c 100644
--- a/.github/workflows/ci-amd.yml
+++ b/.github/workflows/ci-amd.yml
@@ -54,11 +54,6 @@ env:
   GITHUB_REPOSITORY: ${{ github.repository }}
   GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
   GITHUB_USERNAME: ${{ github.actor }}
-  # Keep these in sync:
-  # - jvmTarget, languageVersion, and sourceCompatibility in java-sdk/buildSrc
-  # - TEMURIN_VERSION in scripts/docker/install_jdk.sh
-  # - JAVA_VERSION in .github/workflows/ci-amd.yml and 
.github/workflows/ci-arm.yml
-  # - java-version in .github/workflows/codeql-analysis.yml
   JAVA_VERSION: '11'
   SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
   VERBOSE: "true"
diff --git a/.github/workflows/ci-arm.yml b/.github/workflows/ci-arm.yml
index 4514ebef0fc..688408aa8e4 100644
--- a/.github/workflows/ci-arm.yml
+++ b/.github/workflows/ci-arm.yml
@@ -44,11 +44,6 @@ env:
   GITHUB_REPOSITORY: ${{ github.repository }}
   GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
   GITHUB_USERNAME: ${{ github.actor }}
-  # Keep these in sync:
-  # - jvmTarget, languageVersion, and sourceCompatibility in java-sdk/buildSrc
-  # - TEMURIN_VERSION in scripts/docker/install_jdk.sh
-  # - JAVA_VERSION in .github/workflows/ci-amd.yml and 
.github/workflows/ci-arm.yml
-  # - java-version in .github/workflows/codeql-analysis.yml
   JAVA_VERSION: '11'
   SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
   VERBOSE: "true"
diff --git a/.github/workflows/codeql-analysis.yml 
b/.github/workflows/codeql-analysis.yml
index e267afc1456..624368905e3 100644
--- a/.github/workflows/codeql-analysis.yml
+++ b/.github/workflows/codeql-analysis.yml
@@ -114,11 +114,6 @@ jobs:
         with:
           persist-credentials: false
 
-      # Keep these in sync:
-      # - jvmTarget, languageVersion, and sourceCompatibility in 
java-sdk/buildSrc
-      # - TEMURIN_VERSION in scripts/docker/install_jdk.sh
-      # - JAVA_VERSION in .github/workflows/ci-amd.yml and 
.github/workflows/ci-arm.yml
-      # - java-version in .github/workflows/codeql-analysis.yml
       - name: Setup Java
         if: matrix.language == 'java'
         uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654  # 
v5.2.0
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 5d5c2329aae..171cacf1459 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -255,6 +255,18 @@ repos:
         files: ^\.github/workflows/ci-(arm|amd)\.yml$
         pass_filenames: false
         require_serial: true
+      - id: check-java-sdk-version-in-sync
+        name: Check Java SDK JDK version is consistent across build files
+        entry: ./scripts/ci/prek/check_java_sdk_version_in_sync.py
+        language: python
+        files: >
+          (?x)
+          ^\.github/workflows/ci-(arm|amd)\.yml$|
+          ^\.github/workflows/codeql-analysis\.yml$|
+          
^java-sdk/buildSrc/src/main/kotlin/airflow-jvm-conventions\.gradle\.kts$|
+          ^scripts/docker/install_jdk\.sh$
+        pass_filenames: false
+        require_serial: true
       - id: check-partition-mapper-defaults-in-sync
         name: Check partition-mapper core/SDK sync (FanOutMapper table + 
SegmentWindow/FixedKeyMapper)
         entry: ./scripts/ci/prek/check_partition_mapper_defaults_in_sync.py
diff --git 
a/java-sdk/buildSrc/src/main/kotlin/airflow-jvm-conventions.gradle.kts 
b/java-sdk/buildSrc/src/main/kotlin/airflow-jvm-conventions.gradle.kts
index 2d541933fc0..5a5c6b873aa 100644
--- a/java-sdk/buildSrc/src/main/kotlin/airflow-jvm-conventions.gradle.kts
+++ b/java-sdk/buildSrc/src/main/kotlin/airflow-jvm-conventions.gradle.kts
@@ -30,11 +30,8 @@ repositories {
     mavenCentral()
 }
 
-// Keep these in sync:
-// - jvmTarget, languageVersion, and sourceCompatibility here
-// - TEMURIN_VERSION in scripts/docker/install_jdk.sh
-// - JAVA_VERSION in .github/workflows/ci-amd.yml and 
.github/workflows/ci-arm.yml
-// - java-version in .github/workflows/codeql-analysis.yml
+// The versions below are kept in sync with the other build files by a 
pre-commit hook.
+// See: scripts/ci/prek/check_java_sdk_version_in_sync.py
 java {
     toolchain {
         languageVersion.set(JavaLanguageVersion.of(11))
diff --git a/scripts/ci/prek/check_java_sdk_version_in_sync.py 
b/scripts/ci/prek/check_java_sdk_version_in_sync.py
new file mode 100644
index 00000000000..02e696b7278
--- /dev/null
+++ b/scripts/ci/prek/check_java_sdk_version_in_sync.py
@@ -0,0 +1,132 @@
+#!/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.
+"""
+Verify the Java SDK JDK version is consistent across all files that declare it.
+
+The authoritative version lives in five places that must stay in sync:
+
+- .github/workflows/ci-amd.yml
+  -> env.JAVA_VERSION
+- .github/workflows/ci-arm.yml
+  -> env.JAVA_VERSION
+- .github/workflows/codeql-analysis.yml
+  -> steps[].with.java-version
+- java-sdk/buildSrc/src/main/kotlin/airflow-jvm-conventions.gradle.kts
+  -> java.toolchain.languageVersion.set(JavaLanguageVersion.of(<n>))
+  -> java.sourceCompatibility = JavaVersion.VERSION_<n>
+  -> kotlin.compilerOptions.jvmTarget = JvmTarget.JVM_<n>
+- scripts/docker/install_jdk.sh
+  -> TEMURIN_VERSION="<n>"
+"""
+
+from __future__ import annotations
+
+import dataclasses
+import pathlib
+import re
+import sys
+
+
[email protected]
+class VersionSite:
+    """A single location that declares the Java version."""
+
+    label: str
+    path: pathlib.Path
+    pattern: re.Pattern[str]
+
+    def extract(self) -> str | None:
+        """Find version string with regex."""
+        if m := self.pattern.search(self.path.read_text()):
+            return m.group(1)
+        return None
+
+
+REPO_ROOT = pathlib.Path(__file__).resolve().parents[3]
+
+WORKFLOWS = REPO_ROOT.joinpath(".github", "workflows")
+SDK_CONVENTION = 
REPO_ROOT.joinpath("java-sdk/buildSrc/src/main/kotlin/airflow-jvm-conventions.gradle.kts")
+
+SITES = [
+    VersionSite(
+        label=".github/workflows/ci-amd.yml  (env.JAVA_VERSION)",
+        path=WORKFLOWS.joinpath("ci-amd.yml"),
+        pattern=re.compile(r"^\s+JAVA_VERSION:\s+'(\d+)'", re.MULTILINE),
+    ),
+    VersionSite(
+        label=".github/workflows/ci-arm.yml  (env.JAVA_VERSION)",
+        path=WORKFLOWS.joinpath("ci-arm.yml"),
+        pattern=re.compile(r"^\s+JAVA_VERSION:\s+'(\d+)'", re.MULTILINE),
+    ),
+    VersionSite(
+        label=".github/workflows/codeql-analysis.yml  
(steps[].with.java-version)",
+        path=WORKFLOWS.joinpath("codeql-analysis.yml"),
+        pattern=re.compile(r"^\s+java-version:\s+'(\d+)'", re.MULTILINE),
+    ),
+    VersionSite(
+        label="java-sdk/buildSrc/.../airflow-jvm-conventions.gradle.kts  
(JavaLanguageVersion.of(...))",
+        path=SDK_CONVENTION,
+        pattern=re.compile(r"JavaLanguageVersion\.of\((\d+)\)"),
+    ),
+    VersionSite(
+        label="java-sdk/buildSrc/.../airflow-jvm-conventions.gradle.kts  
(JavaVersion.VERSION_...)",
+        path=SDK_CONVENTION,
+        pattern=re.compile(r"JavaVersion\.VERSION_(\d+)"),
+    ),
+    VersionSite(
+        label="java-sdk/buildSrc/.../airflow-jvm-conventions.gradle.kts  
(JvmTarget.JVM_...)",
+        path=SDK_CONVENTION,
+        pattern=re.compile(r"JvmTarget\.JVM_(\d+)"),
+    ),
+    VersionSite(
+        label="scripts/docker/install_jdk.sh  (TEMURIN_VERSION)",
+        path=REPO_ROOT.joinpath("scripts", "docker", "install_jdk.sh"),
+        pattern=re.compile(r'^readonly TEMURIN_VERSION="(\d+)"', re.MULTILINE),
+    ),
+]
+
+
+def main() -> int:
+    results = [(site, site.extract()) for site in SITES]
+
+    if not_found := [(site, v) for site, v in results if v is None]:
+        for site, _ in not_found:
+            print(f"ERROR: Java version pattern not found in 
{site.path.relative_to(REPO_ROOT)}")
+            print(f"       Pattern: {site.pattern.pattern!r}")
+        return len(not_found)
+
+    versions = {v for _, v in results}
+    if len(versions) == 1:
+        (version,) = versions
+        print(f"OK: Java SDK version is consistently {version} across all 
{len(SITES)} locations.")
+        return 0
+
+    print("ERROR: Java SDK version is inconsistent across files:")
+    print()
+    col = max(len(site.label) for site, _ in results)
+    for site, version in results:
+        print(f"  {site.label:<{col}}  {version}")
+    print()
+    print("Update all locations to the same version, or adjust the patterns 
in")
+    print(f"  {pathlib.Path(__file__).relative_to(REPO_ROOT)}")
+    print("if the pattern no longer matches.")
+    return 1
+
+
+if __name__ == "__main__":
+    sys.exit(main())
diff --git a/scripts/docker/install_jdk.sh b/scripts/docker/install_jdk.sh
index 1c93483c80c..bfdb9db4ee6 100755
--- a/scripts/docker/install_jdk.sh
+++ b/scripts/docker/install_jdk.sh
@@ -23,11 +23,6 @@ set -euo pipefail
 
 common::get_colors
 
-# Keep these in sync:
-# - jvmTarget, languageVersion, and sourceCompatibility in java-sdk/buildSrc
-# - TEMURIN_VERSION in scripts/docker/install_jdk.sh
-# - JAVA_VERSION in .github/workflows/ci-amd.yml and 
.github/workflows/ci-arm.yml
-# - java-version in .github/workflows/codeql-analysis.yml
 readonly TEMURIN_VERSION="11"
 
 # Fast path: skip if the right JDK is already on PATH (e.g. repeated container 
starts

Reply via email to