Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .rat-excludes
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,17 @@ PKG-INFO
.openapi-generator-ignore
version.txt
v1*.yaml
v2*.yaml
_private_ui*.yaml

# Front end generated files
api-generated.ts
openapi-gen
pnpm-lock.yaml

# python generated file
generated.py
auth_generated.py

# hash files
www-hash.txt
1 change: 1 addition & 0 deletions providers/fab/www-hash.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dcce95d1f3f0f8e01c1e94c3915367e3acc00c022f76ebb8efad935cafe36d03
19 changes: 9 additions & 10 deletions scripts/ci/pre_commit/compile_fab_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@
import sys
from pathlib import Path

from common_precommit_utils import AIRFLOW_ROOT_PATH

# NOTE!. This script is executed from node environment created by pre-commit and this environment
# Cannot have additional Python dependencies installed. We should not import any of the libraries
# here that are not available in stdlib! You should not import common_precommit_utils.py here because
# They are importing rich library which is not available in the node environment.

AIRFLOW_SOURCES_PATH = Path(__file__).parents[3].resolve()
WWW_HASH_FILE = AIRFLOW_SOURCES_PATH / ".build" / "www" / "hash.txt"
FAB_PROVIDER_ROOT_PATH = AIRFLOW_ROOT_PATH / "providers" / "fab"
FAB_PROVIDER_WWW_PATH = FAB_PROVIDER_ROOT_PATH / "src" / "airflow" / "providers" / "fab" / "www"
FAB_PROVIDER_WWW_HASH_FILE = FAB_PROVIDER_ROOT_PATH / "www-hash.txt"


def get_directory_hash(directory: Path, skip_path_regexp: str | None = None) -> str:
Expand All @@ -58,10 +61,9 @@ def get_directory_hash(directory: Path, skip_path_regexp: str | None = None) ->
def compile_assets(www_directory: Path, www_hash_file_name: str):
node_modules_directory = www_directory / "node_modules"
dist_directory = www_directory / "static" / "dist"
www_hash_file = AIRFLOW_SOURCES_PATH / ".build" / "www" / www_hash_file_name
www_hash_file.parent.mkdir(exist_ok=True, parents=True)
FAB_PROVIDER_WWW_HASH_FILE.parent.mkdir(exist_ok=True, parents=True)
if node_modules_directory.exists() and dist_directory.exists():
old_hash = www_hash_file.read_text() if www_hash_file.exists() else ""
old_hash = FAB_PROVIDER_WWW_HASH_FILE.read_text() if FAB_PROVIDER_WWW_HASH_FILE.exists() else ""
new_hash = get_directory_hash(www_directory, skip_path_regexp=r".*node_modules.*")
if new_hash == old_hash:
print(f"The '{www_directory}' directory has not changed! Skip regeneration.")
Expand All @@ -87,12 +89,9 @@ def compile_assets(www_directory: Path, www_hash_file_name: str):
sys.exit(result.returncode)
subprocess.check_call(["yarn", "run", "build"], cwd=os.fspath(www_directory), env=env)
new_hash = get_directory_hash(www_directory, skip_path_regexp=r".*node_modules.*")
www_hash_file.write_text(new_hash)
FAB_PROVIDER_WWW_HASH_FILE.write_text(new_hash + "\n")


if __name__ == "__main__":
# Compile assets for fab provider
fab_provider_www_directory = (
AIRFLOW_SOURCES_PATH / "providers" / "fab" / "src" / "airflow" / "providers" / "fab" / "www"
)
compile_assets(fab_provider_www_directory, "hash_fab.txt")
compile_assets(FAB_PROVIDER_WWW_PATH, "hash_fab.txt")