unity-builder/dist/remote-builder/handleCaching.sh

80 lines
2.0 KiB
Bash
Raw Normal View History

#!/bin/sh
cacheFolderFull=$1
2021-07-12 22:46:21 +00:00
branchName=$2
libraryFolderFull=$3
2021-07-31 21:41:55 +00:00
gitLFSDestinationFolder=$4
purgeRemoteBuilderCache=$5
cacheFolderWithBranch="$cacheFolderFull/$branchName"
2021-08-01 01:04:38 +00:00
lfsCacheFolder="$cacheFolderFull/$branchName/lfs"
libraryCacheFolder="$cacheFolderFull/$branchName/lib"
2021-08-01 01:04:38 +00:00
echo ' '
2021-07-27 22:23:02 +00:00
2021-08-01 01:04:38 +00:00
echo "LFS cache for branch: $branchName"
mkdir -p "$lfsCacheFolder"
ls -lh "$lfsCacheFolder"
2021-08-01 01:07:23 +00:00
echo ' '
2021-07-27 20:45:49 +00:00
echo "Library cache for branch: $branchName"
2021-08-01 01:04:38 +00:00
mkdir -p "$libraryCacheFolder"
ls -lh "$libraryCacheFolder"
echo ' '
2021-07-27 20:45:49 +00:00
2021-08-01 01:04:38 +00:00
# if the unity git project has included the library delete it and echo a warning
2021-07-27 22:40:48 +00:00
if [ -d "$libraryFolderFull" ]; then
rm -r "$libraryFolderFull"
2021-08-01 01:04:38 +00:00
echo "!Warning!: The Unity library was included in the git repository (this isn't usually a good practice)"
2021-07-27 20:45:49 +00:00
fi
echo "Checking cache"
2021-07-12 22:36:40 +00:00
# Restore library cache
2021-08-01 01:04:38 +00:00
latestLibraryCacheFile=$(ls -t "$libraryCacheFolder" | egrep -i -e '\\.zip$' | head -1)
2021-08-01 01:04:38 +00:00
if [ ! -z "$latestLibraryCacheFile" ]; then
echo "Library cache exists from build $latestLibraryCacheFile from $branchName"
echo 'Creating empty Library folder for cache'
mkdir "$libraryFolderFull"
2021-08-01 01:04:38 +00:00
unzip -q "$libraryCacheFolder/$latestLibraryCacheFile" -d "$libraryFolderFull"
fi
2021-07-12 22:36:40 +00:00
# Restore LFS cache
2021-08-01 01:04:38 +00:00
if [[ ! -v "$LFS_ASSETS_HASH" ]]; then
latestLFSCacheFile=LFS_ASSETS_HASH
else
latestLFSCacheFile=$(ls -t "$cacheFolderWithBranch/lfs" | egrep -i -e '\\.zip$' | head -1)
fi
2021-07-31 21:41:55 +00:00
2021-08-01 01:04:38 +00:00
if [ ! -z "$latestLFSCacheFile" ]; then
echo "LFS cache exists from build $latestLFSCacheFile from $branchName"
rm -r "$gitLFSDestinationFolder"
mkdir -p "$gitLFSDestinationFolder"
2021-08-01 03:17:59 +00:00
unzip -q "$gitLFSDestinationFolder/$latestLFSCacheFile" -d "$gitLFSDestinationFolder"
2021-07-31 21:41:55 +00:00
fi
2021-07-12 22:36:40 +00:00
2021-08-01 01:14:42 +00:00
echo ' '
du -sch "$gitLFSDestinationFolder"
du -sch "$latestLibraryCacheFile"
echo ' '
2021-07-31 22:27:59 +00:00
du -sch "$cacheFolderWithBranch"
2021-08-01 01:14:42 +00:00
echo ' '
2021-07-31 22:27:59 +00:00
du -sch "$cacheFolderFull"
2021-08-01 01:14:42 +00:00
echo ' '
2021-07-31 22:27:59 +00:00
echo "purge $purgeRemoteBuilderCache"
# purge cache
if [ "$purgeRemoteBuilderCache" == "true" ]; then
2021-07-31 21:48:02 +00:00
rm -r "$cacheFolderFull"
fi
2021-08-01 01:14:42 +00:00
echo ' '
2021-08-01 01:04:38 +00:00
git lfs pull
2021-08-01 03:17:59 +00:00
zip -r $LFS_ASSETS_HASH -d "$gitLFSDestinationFolder"
2021-08-01 01:14:42 +00:00
cp $LFS_ASSETS_HASH "$lfsCacheFolder"
2021-08-01 01:07:23 +00:00
2021-08-01 01:14:42 +00:00
echo ' '