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
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,6 @@ repos:
- id: compile-fab-assets
name: Compile FAB provider assets
language: node
'types_or': [javascript, ts, tsx]
files: ^providers/fab/.*/www/
entry: ./scripts/ci/pre_commit/compile_fab_assets.py
pass_filenames: false
Expand Down

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"airflowDefaultTheme.css": "airflowDefaultTheme.48540e25fb1e474cef20.css",
"airflowDefaultTheme.js": "airflowDefaultTheme.48540e25fb1e474cef20.js",
"flash.css": "flash.02dea0c2ac20820e8d1b.css",
"flash.js": "flash.02dea0c2ac20820e8d1b.js",
"loadingDots.css": "loadingDots.96221bc8b6345c7d65b3.css",
"loadingDots.js": "loadingDots.96221bc8b6345c7d65b3.js",
"main.css": "main.49c4d5787ef1f247f004.css",
"main.js": "main.49c4d5787ef1f247f004.js",
"materialIcons.css": "materialIcons.4fd835641d53f81af3d3.css",
"materialIcons.js": "materialIcons.4fd835641d53f81af3d3.js",
"moment.js": "moment.6943aa3cca9cb1129a71.js",
"runtime.js": "runtime.3c1a5fcbb3c1b7c62ad7.js",
"743.js": "743.57634ddb93717b7c8c1a.js",
"airflowDefaultTheme.css": "airflowDefaultTheme.ad8dda5568e05025b227.css",
"airflowDefaultTheme.js": "airflowDefaultTheme.ad8dda5568e05025b227.js",
"flash.css": "flash.b79fc1a41842edaebd1e.css",
"flash.js": "flash.b79fc1a41842edaebd1e.js",
"loadingDots.css": "loadingDots.e0e7d08bf05145b507f1.css",
"loadingDots.js": "loadingDots.e0e7d08bf05145b507f1.js",
"main.css": "main.86c51bce5f9ddc8b144c.css",
"main.js": "main.86c51bce5f9ddc8b144c.js",
"materialIcons.css": "materialIcons.64ecd8081995e8cc1b62.css",
"materialIcons.js": "materialIcons.64ecd8081995e8cc1b62.js",
"moment.js": "moment.4dc2e04c449ec8a3b41c.js",
"runtime.js": "runtime.086dc01132a20c74861a.js",
"743.js": "743.365a1eb58dd47776b82f.js",
"jquery-ui.min.js": "jquery-ui.min.js",
"jquery-ui.min.css": "jquery-ui.min.css",
"oss-licenses.json": "oss-licenses.json",
Expand Down
2 changes: 1 addition & 1 deletion providers/fab/www-hash.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9c85fa59b691a60a47c7f37c1ab429a9229467634b77609113b18fd156738db7
83e6236e453a6c8de1e532a13c032e80f12bf22692a51f7eb49a87d8e8f662d8
26 changes: 16 additions & 10 deletions scripts/ci/pre_commit/compile_fab_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
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:
def get_directory_hash(directory: Path, skip_path_regexps: list[str]) -> str:
files = sorted(directory.rglob("*"))
if skip_path_regexp:
for skip_path_regexp in skip_path_regexps:
matcher = re.compile(skip_path_regexp)
files = [file for file in files if not matcher.match(os.fspath(file.resolve()))]
sha = hashlib.sha256()
Expand All @@ -57,19 +57,24 @@ def get_directory_hash(directory: Path, skip_path_regexp: str | None = None) ->

INTERNAL_SERVER_ERROR = "500 Internal Server Error"

SKIP_PATH_REGEXPS = [".*/node_modules.*"]

def compile_assets(www_directory: Path, www_hash_file_name: str):
node_modules_directory = www_directory / "node_modules"

def compile_assets(www_directory: Path):
dist_directory = www_directory / "static" / "dist"
FAB_PROVIDER_WWW_HASH_FILE.parent.mkdir(exist_ok=True, parents=True)
if node_modules_directory.exists() and dist_directory.exists():
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 dist_directory.exists():
old_hash = (
FAB_PROVIDER_WWW_HASH_FILE.read_text().strip() if FAB_PROVIDER_WWW_HASH_FILE.exists() else ""
)
new_hash = get_directory_hash(www_directory, skip_path_regexps=SKIP_PATH_REGEXPS)
if new_hash == old_hash:
print(f"The '{www_directory}' directory has not changed! Skip regeneration.")
return
print("The directory has changed, regenerating assets.")
print("Old hash: " + old_hash)
print("New hash: " + new_hash)
else:
shutil.rmtree(node_modules_directory, ignore_errors=True)
shutil.rmtree(dist_directory, ignore_errors=True)
env = os.environ.copy()
env["FORCE_COLOR"] = "true"
Expand All @@ -88,10 +93,11 @@ def compile_assets(www_directory: Path, www_hash_file_name: str):
print(result.stdout + "\n" + result.stderr)
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.*")
new_hash = get_directory_hash(www_directory, skip_path_regexps=SKIP_PATH_REGEXPS)
FAB_PROVIDER_WWW_HASH_FILE.write_text(new_hash + "\n")
print(f"Assets compiled successfully. New hash: {new_hash}")


if __name__ == "__main__":
# Compile assets for fab provider
compile_assets(FAB_PROVIDER_WWW_PATH, "hash_fab.txt")
compile_assets(FAB_PROVIDER_WWW_PATH)
Loading