diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 19e51afa2efed5..dc1138470764ac 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1433,4 +1433,9 @@ repos: pass_filenames: false files: ^airflow/migrations/versions/.*\.py$|^docs/apache-airflow/migrations-ref\.rst$ additional_dependencies: ['rich>=12.4.4'] + - id: check-zip-files + name: Forbid committing .zip files + entry: python ./scripts/ci/pre_commit/check_zip_files.py + language: python + files: \.zip$ ## ONLY ADD PRE-COMMITS HERE THAT REQUIRE CI IMAGE diff --git a/contributing-docs/08_static_code_checks.rst b/contributing-docs/08_static_code_checks.rst index b8ec98923166f5..9213b61d41de81 100644 --- a/contributing-docs/08_static_code_checks.rst +++ b/contributing-docs/08_static_code_checks.rst @@ -250,6 +250,8 @@ require Breeze Docker image to be built locally. +-----------------------------------------------------------+--------------------------------------------------------+---------+ | check-xml | Check XML files with xmllint | | +-----------------------------------------------------------+--------------------------------------------------------+---------+ +| check-zip-files | Forbid committing .zip files | * | ++-----------------------------------------------------------+--------------------------------------------------------+---------+ | codespell | Run codespell | | +-----------------------------------------------------------+--------------------------------------------------------+---------+ | compile-ui-assets | Compile ui assets (manual) | | diff --git a/dev/breeze/doc/images/output_static-checks.txt b/dev/breeze/doc/images/output_static-checks.txt index 5c6eac5d725ab0..4e3bf3c5037739 100644 --- a/dev/breeze/doc/images/output_static-checks.txt +++ b/dev/breeze/doc/images/output_static-checks.txt @@ -1 +1 @@ -8b916a8eceeecdae4936ee72ec060491 +6bb06b6e0cf75f8c01e2a1727edf4515 diff --git a/dev/breeze/src/airflow_breeze/pre_commit_ids.py b/dev/breeze/src/airflow_breeze/pre_commit_ids.py index 472a47a309035e..289bc0b9be2dd3 100644 --- a/dev/breeze/src/airflow_breeze/pre_commit_ids.py +++ b/dev/breeze/src/airflow_breeze/pre_commit_ids.py @@ -90,6 +90,7 @@ "check-urlparse-usage-in-code", "check-usage-of-re2-over-re", "check-xml", + "check-zip-files", "codespell", "compile-ui-assets", "compile-ui-assets-dev", diff --git a/scripts/ci/pre_commit/check_zip_files.py b/scripts/ci/pre_commit/check_zip_files.py new file mode 100644 index 00000000000000..e5b68ea9739744 --- /dev/null +++ b/scripts/ci/pre_commit/check_zip_files.py @@ -0,0 +1,51 @@ +#!/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. +from __future__ import annotations + +import subprocess +import sys + + +def get_staged_files(): + """Return a list of files that are staged for commit.""" + result = subprocess.run( + ["git", "diff", "--cached", "--name-only"], + capture_output=True, + text=True, + ) + if result.returncode != 0: + print("Error: Unable to retrieve staged files.", file=sys.stderr) + sys.exit(1) + return result.stdout.splitlines() + + +def main(): + staged_files = get_staged_files() + # Look for any file ending with .zip (case-insensitive) + zip_files = [f for f in staged_files if f.lower().endswith(".zip")] + if zip_files: + print("Error: Committing .zip files is not allowed.") + print("The following .zip file(s) were found in your staged changes:") + for file in zip_files: + print(" -", file) + sys.exit(1) + sys.exit(0) + + +if __name__ == "__main__": + main()