blob: b70bbdd7ee321e47f66d3839c6e8e9c292504701 [file] [log] [blame]
Euan Kempaabca2e2025-07-21 05:44:44 +00001#!/usr/bin/env bash
Josh Bleecher Snyder6ae637a2025-07-09 12:41:56 -07002set -e
3
Josh Bleecher Snyder39eb24f2025-07-10 01:46:33 +00004# Use a content-based hash of the webui dir to avoid unnecessary rebuilds.
5OUTPUT_DIR="embedded/webui-dist"
6# go:embed ignores files that start with a '.'
7HASH_FILE="$OUTPUT_DIR/.input_hash"
8
9calculate_input_hash() {
Josh Bleecher Snydere3e886b2025-07-17 15:31:16 -070010 local tmp=$(mktemp)
11 (
12 export GIT_INDEX_FILE="$tmp"
13 git read-tree --empty
14 git add webui/
15 git write-tree
16 )
17 rm -f "$tmp"
Josh Bleecher Snyder39eb24f2025-07-10 01:46:33 +000018}
19
20CURRENT_HASH=$(calculate_input_hash)
21
22if [ -f "$HASH_FILE" ] && [ -d "$OUTPUT_DIR" ]; then
Josh Bleecher Snydere3e886b2025-07-17 15:31:16 -070023 STORED_HASH=$(cat "$HASH_FILE")
24 if [ "$CURRENT_HASH" = "$STORED_HASH" ]; then
Josh Bleecher Snydere3e886b2025-07-17 15:31:16 -070025 exit 0
26 fi
Josh Bleecher Snyder39eb24f2025-07-10 01:46:33 +000027fi
28
29rm -rf "$OUTPUT_DIR"
30unset GOOS GOARCH && go run ./cmd/genwebui -- "$OUTPUT_DIR"
31echo "$CURRENT_HASH" >"$HASH_FILE"