Skip to content
Merged
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
31 changes: 24 additions & 7 deletions scripts/ci/pre_commit/compile_www_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
from __future__ import annotations

import hashlib
import importlib.util
import os
import re
import shutil
import subprocess
import sys
from pathlib import Path

# NOTE!. This script is executed from node environment created by pre-commit and this environment
Expand Down Expand Up @@ -52,17 +52,18 @@ def get_directory_hash(directory: Path, skip_path_regexp: str | None = None) ->
f"To run this script, run the ./{__file__} command"
)

if __name__ == "__main__":
www_directory = AIRFLOW_SOURCES_PATH / "airflow" / "www"

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.parent.mkdir(exist_ok=True, parents=True)
www_hash_file = AIRFLOW_SOURCES_PATH / ".build" / "www" / www_hash_file_name
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 = www_hash_file.read_text() if www_hash_file.exists() else ""
new_hash = get_directory_hash(www_directory, skip_path_regexp=r".*node_modules.*")
if new_hash == old_hash:
print("The WWW directory has not changed! Skip regeneration.")
sys.exit(0)
return
else:
shutil.rmtree(node_modules_directory, ignore_errors=True)
shutil.rmtree(dist_directory, ignore_errors=True)
Expand All @@ -71,4 +72,20 @@ def get_directory_hash(directory: Path, skip_path_regexp: str | None = None) ->
subprocess.check_call(["yarn", "install", "--frozen-lockfile"], cwd=os.fspath(www_directory))
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)
www_hash_file.write_text(new_hash)


def is_fab_provider_installed() -> bool:
return importlib.util.find_spec("airflow.providers.fab") is not None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ups, this change in this function broke main :-(
https://github.com/apache/airflow/actions/runs/12399970802/job/34616478712

I assume we need to find another method to check if FAB is installed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Propose to fix via #45058



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