jason810496 commented on code in PR #77885:
URL: https://github.com/apache/airflow/pull/77885#discussion_r4766023218
##########
scripts/ci/prek/check_yaml_importer_schema_versions.py:
##########
@@ -111,26 +175,43 @@ def main() -> int:
"has no schema snapshot yet. The check activates once this PR
merges."
)
return 0
+ if snapshot == target_snapshot:
+ console.print("[green]Snapshot unchanged:[/] source changes do not
affect the YAML importer schema.")
+ return 0
- if Path(SNAPSHOT_PATH).read_text() != target_snapshot:
- console.print("[bold red]ERROR:[/] YAML importer schema changed but no
version was updated.")
- console.print("")
- console.print("The following files were changed:")
- for f in schema_source_files:
- console.print(f" - [magenta]{f}[/]")
- console.print("")
+ head = head_version(VERSIONS_INIT_PATH.read_text())
+ release = latest_release(RELEASE_NOTES_PATH.read_text())
Review Comment:
Could we read `RELEASE_NOTES.rst` from the target ref instead? A branch that
hasn't been rebased won't see newer releases, so the check passes.
##########
scripts/ci/prek/check_yaml_importer_schema_versions.py:
##########
@@ -111,26 +175,43 @@ def main() -> int:
"has no schema snapshot yet. The check activates once this PR
merges."
)
return 0
+ if snapshot == target_snapshot:
+ console.print("[green]Snapshot unchanged:[/] source changes do not
affect the YAML importer schema.")
+ return 0
- if Path(SNAPSHOT_PATH).read_text() != target_snapshot:
- console.print("[bold red]ERROR:[/] YAML importer schema changed but no
version was updated.")
- console.print("")
- console.print("The following files were changed:")
- for f in schema_source_files:
- console.print(f" - [magenta]{f}[/]")
- console.print("")
+ head = head_version(VERSIONS_INIT_PATH.read_text())
+ release = latest_release(RELEASE_NOTES_PATH.read_text())
+ if head is not None and release is not None and head > release.date:
Review Comment:
Could we check whether the head version is in the bundle at the latest
release tag? Version dates are planned ahead, like `2027-02-28`. If 3.5.0 ships
earlier, edits here still pass, and a later 3.4.x patch would wrongly fail.
##########
scripts/ci/prek/check_yaml_importer_schema_versions.py:
##########
@@ -79,30 +104,69 @@ def _target_ref() -> str:
return f"{remote}/{target_branch}"
-def _snapshot_on_target(ref: str) -> str | None:
- """Return the committed ``schema.json`` at *ref*, or ``None`` if it does
not exist there yet."""
+def _base_ref() -> str | None:
Review Comment:
Could we reuse `common_prek_utils.get_commit_base_ref` from #77886 once one
of them merges? It's the same helper.
##########
scripts/ci/prek/check_yaml_importer_schema_versions.py:
##########
@@ -79,30 +104,69 @@ def _target_ref() -> str:
return f"{remote}/{target_branch}"
-def _snapshot_on_target(ref: str) -> str | None:
- """Return the committed ``schema.json`` at *ref*, or ``None`` if it does
not exist there yet."""
+def _base_ref() -> str | None:
+ """
+ Return the ref the checked commit is based on, or ``None`` if it is
unknown.
+
+ prek passes ``--from-ref`` to hooks as ``PRE_COMMIT_FROM_REF``. Without it,
+ staged changes mean a commit is being made on top of ``HEAD``. Otherwise
the
+ checked-out tree is already committed (as when CI checks a list of files),
+ so comparing it with ``HEAD`` would always find it unchanged.
+ """
+ if from_ref := os.environ.get("PRE_COMMIT_FROM_REF"):
+ return from_ref
+ staged = subprocess.run(["git", "diff", "--cached", "--quiet"],
capture_output=True, check=False)
+ return "HEAD" if staged.returncode == 1 else None
Review Comment:
How about scoping this to the schema dir? Any staged file makes the base
`HEAD`, so `prek run --all-files` could pass an earlier unversioned schema
commit.
```suggestion
staged = subprocess.run(
["git", "diff", "--cached", "--quiet", "--", SCHEMA_DIR.as_posix()],
capture_output=True, check=False
)
return "HEAD" if staged.returncode == 1 else None
```
--
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]