Compare commits

...
Author SHA1 Message Date
admin 8769dd1132 Cache Unity Library for iOS TestFlight builds 2026-06-22 06:54:00 -07:00
2 changed files with 112 additions and 0 deletions
+7
View File
@@ -160,11 +160,18 @@ jobs:
- name: Ensure Unity version installed
run: ./ci/github_actions/ensure_unity_installed.sh ios
- name: Restore Unity Library cache
run: ./ci/github_actions/unity_library_cache.sh restore ios
- name: Build iOS Unity Project
id: build
run: |
./ci/github_actions/build_unity_ios.sh "$EAGLE0_BUILD_DIR/eagle0iOS"
- name: Save Unity Library cache
if: success()
run: ./ci/github_actions/unity_library_cache.sh save ios
- name: Upload Addressables to CDN
if: success() && github.event.inputs.skip_upload != 'true'
env:
+105
View File
@@ -0,0 +1,105 @@
#!/usr/bin/env bash
set -euo pipefail
COMMAND=${1:?Usage: unity_library_cache.sh restore|save <build-target>}
BUILD_TARGET=${2:?Usage: unity_library_cache.sh restore|save <build-target>}
PROJECT_DIR="src/main/csharp/net/eagle0/clients/unity/eagle0"
LIBRARY_DIR="$PROJECT_DIR/Library"
MARKER_FILE="$LIBRARY_DIR/.eagle0-library-cache-key"
COMPLETE_FILE=".complete"
CACHE_ROOT=${UNITY_LIBRARY_CACHE_RSYNC_URL:-rsync://lappy/unity-library-cache}
UNITY_VERSION=$(grep "m_EditorVersion:" "$PROJECT_DIR/ProjectSettings/ProjectVersion.txt" | head -1 | sed 's/m_EditorVersion: //')
PROJECT_HASH=$(
git ls-files -s -- \
"$PROJECT_DIR/Assets" \
"$PROJECT_DIR/Packages" \
"$PROJECT_DIR/ProjectSettings" \
| shasum -a 256 \
| awk '{print $1}'
)
CACHE_KEY="macos-${BUILD_TARGET}-${UNITY_VERSION}-${PROJECT_HASH}"
CACHE_URL="${CACHE_ROOT%/}/${CACHE_KEY}"
restore_cache() {
echo "Unity Library cache key: $CACHE_KEY"
if [ -d "$LIBRARY_DIR" ]; then
if [ ! -f "$MARKER_FILE" ]; then
echo "Existing Unity Library has no cache marker; removing it before restore."
rm -rf "$LIBRARY_DIR"
elif [ "$(cat "$MARKER_FILE")" != "$CACHE_KEY" ]; then
echo "Existing Unity Library cache key differs; removing it before restore."
echo "Existing: $(cat "$MARKER_FILE")"
echo "Current: $CACHE_KEY"
rm -rf "$LIBRARY_DIR"
else
echo "Existing Unity Library already matches cache key."
return 0
fi
fi
local complete_marker
complete_marker=$(mktemp)
if ! rsync -q "${CACHE_URL}/${COMPLETE_FILE}" "$complete_marker"; then
echo "No complete Unity Library cache found at $CACHE_URL"
rm -f "$complete_marker"
return 0
fi
rm -f "$complete_marker"
echo "Restoring Unity Library from $CACHE_URL"
mkdir -p "$LIBRARY_DIR"
if ! rsync -a --delete "${CACHE_URL}/" "$LIBRARY_DIR/"; then
echo "Unity Library cache restore failed; removing partial restore."
rm -rf "$LIBRARY_DIR"
return 0
fi
printf '%s\n' "$CACHE_KEY" > "$MARKER_FILE"
echo "Unity Library cache restore complete."
}
save_cache() {
if [ ! -d "$LIBRARY_DIR" ]; then
echo "Unity Library does not exist; nothing to cache."
return 0
fi
echo "Saving Unity Library cache to $CACHE_URL"
printf '%s\n' "$CACHE_KEY" > "$MARKER_FILE"
rm -f "$LIBRARY_DIR/$COMPLETE_FILE"
if ! rsync -a --delete "$LIBRARY_DIR/" "${CACHE_URL}/"; then
echo "WARNING: Unity Library cache save failed."
return 0
fi
local complete_marker
complete_marker=$(mktemp)
printf '%s\n' "$CACHE_KEY" > "$complete_marker"
if ! rsync -q "$complete_marker" "${CACHE_URL}/${COMPLETE_FILE}"; then
echo "WARNING: Unity Library cache completion marker upload failed."
rm -f "$complete_marker"
return 0
fi
rm -f "$complete_marker"
echo "Unity Library cache save complete."
}
case "$COMMAND" in
restore)
restore_cache
;;
save)
save_cache
;;
*)
echo "Usage: unity_library_cache.sh restore|save <build-target>"
exit 2
;;
esac