blob: 356c0e3ce9b0fb812e4df901b012df41ea9694cf [file] [log] [blame]
Josh Bleecher Snyder6ae637a2025-07-09 12:41:56 -07001#!/bin/bash
2set -e
3
Philip Zeyliger09b86f42025-07-16 16:23:03 -07004echo "[$(date '+%H:%M:%S')] Starting webui build..."
5
Josh Bleecher Snyder39eb24f2025-07-10 01:46:33 +00006# Use a content-based hash of the webui dir to avoid unnecessary rebuilds.
7OUTPUT_DIR="embedded/webui-dist"
8# go:embed ignores files that start with a '.'
9HASH_FILE="$OUTPUT_DIR/.input_hash"
10
11calculate_input_hash() {
Josh Bleecher Snydere3e886b2025-07-17 15:31:16 -070012 local tmp=$(mktemp)
13 (
14 export GIT_INDEX_FILE="$tmp"
15 git read-tree --empty
16 git add webui/
17 git write-tree
18 )
19 rm -f "$tmp"
Josh Bleecher Snyder39eb24f2025-07-10 01:46:33 +000020}
21
22CURRENT_HASH=$(calculate_input_hash)
23
24if [ -f "$HASH_FILE" ] && [ -d "$OUTPUT_DIR" ]; then
Josh Bleecher Snydere3e886b2025-07-17 15:31:16 -070025 STORED_HASH=$(cat "$HASH_FILE")
26 if [ "$CURRENT_HASH" = "$STORED_HASH" ]; then
27 echo "No changes, skipping rebuild"
28 exit 0
29 fi
Josh Bleecher Snyder39eb24f2025-07-10 01:46:33 +000030fi
31
Philip Zeyliger09b86f42025-07-16 16:23:03 -070032echo "[$(date '+%H:%M:%S')] Removing old output directory..."
Josh Bleecher Snyder39eb24f2025-07-10 01:46:33 +000033rm -rf "$OUTPUT_DIR"
Philip Zeyliger09b86f42025-07-16 16:23:03 -070034echo "[$(date '+%H:%M:%S')] Running genwebui..."
Josh Bleecher Snyder39eb24f2025-07-10 01:46:33 +000035unset GOOS GOARCH && go run ./cmd/genwebui -- "$OUTPUT_DIR"
36echo "$CURRENT_HASH" >"$HASH_FILE"
Philip Zeyliger09b86f42025-07-16 16:23:03 -070037echo "[$(date '+%H:%M:%S')] Webui build completed"