amoghrajesh commented on code in PR #71754: URL: https://github.com/apache/airflow/pull/71754#discussion_r3859943128
########## scripts/ci/prek/update_ts_sdk_readme_matrix.py: ########## @@ -0,0 +1,102 @@ +#!/usr/bin/env python +# 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. +# /// script +# requires-python = ">=3.10,<3.11" +# dependencies = ["PyYAML>=6.0", "rich>=13.6.0"] +# /// +"""Regenerate the TypeScript SDK compatibility table in ``ts-sdk/README.md``. + +Renders the Markdown matrix from ``ts-sdk/capabilities.yaml`` between the AUTO-GENERATED markers. +Exits non-zero when the file changed so the contributor re-stages it. The hook also verifies that +the manifest's supervisor schema version matches the generated TypeScript runtime constant. +""" + +from __future__ import annotations + +import re +import sys +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent)) + +from common_prek_utils import console, insert_documentation +from lang_sdk_compat_matrix import ( + AIRFLOW_ROOT_PATH, + LANG_SDKS, + README_MATRIX_FOOTER, + README_MATRIX_HEADER, + CapabilitiesDoc, + load_capabilities, + render_markdown_table, +) + +SDK_ID = "ts" +TS_SUPERVISOR = AIRFLOW_ROOT_PATH / "ts-sdk" / "src" / "generated" / "supervisor.ts" +SCHEMA_VERSION_PATTERN = re.compile(r'^export const SUPERVISOR_API_VERSION = "(?P<version>[^"]+)" as const;$') + + +def read_ts_schema_version() -> str | None: + """Read ``SUPERVISOR_API_VERSION`` from the generated TypeScript runtime source.""" + for line in TS_SUPERVISOR.read_text().splitlines(): + if match := SCHEMA_VERSION_PATTERN.fullmatch(line): + return match["version"] + return None + + +def check_schema_version(doc: CapabilitiesDoc) -> bool: + """Whether the manifest agrees with the generated TypeScript supervisor schema version. + + Unlike the Java sibling hook (which treats an unreadable gradle property as an implicit pass), + a ``None`` read here — the generated source is missing or its format no longer matches + ``SCHEMA_VERSION_PATTERN`` — is deliberately treated as a mismatch: silently skipping the check + would let capabilities.yaml drift from the runtime undetected. + """ + ts_version = read_ts_schema_version() + declared = doc["supervisor_schema_version"] + if ts_version == declared: + return True + console.print( + f"[red]ts-sdk/capabilities.yaml declares supervisor_schema_version {declared!r} but " + f"src/generated/supervisor.ts SUPERVISOR_API_VERSION is {ts_version!r}. " + "Update capabilities.yaml to match.[/]" + ) + return False Review Comment: The error message sends the contributor to the wrong file when it can't read the version. `read_ts_schema_version()` returns None for two different problems: a) the manifest and the runtime disagree, b) or the constant was not found at all (file missing, or SCHEMA_VERSION_PATTERN no longer matches the generated line). If the constant is missing, editing `capabilities.yaml` cannot fix anything. Split the two cases so the second one says the constant was not found in `src/generated/supervisor.ts` and points at the generator -- 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]
