blob: ee9659d1e446235c94c4ce7843ba4e7c6fb7ea02 [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() {
12 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"
20}
21
22CURRENT_HASH=$(calculate_input_hash)
23
24if [ -f "$HASH_FILE" ] && [ -d "$OUTPUT_DIR" ]; then
25 STORED_HASH=$(cat "$HASH_FILE")
26 if [ "$CURRENT_HASH" = "$STORED_HASH" ]; then
Philip Zeyliger09b86f42025-07-16 16:23:03 -070027 echo "No changes, skipping rebuild"
Josh Bleecher Snyder39eb24f2025-07-10 01:46:33 +000028 exit 0
29 fi
30fi
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"