unity-builder/dist/cloud-runner/handleCaching.sh

88 lines
2.4 KiB
Bash
Raw Normal View History

#!/bin/sh
cacheFolderFull=$1
2021-08-15 13:46:18 +00:00
libraryFolderFull=$2
gitLFSDestinationFolder=$3
2021-08-17 22:13:46 +00:00
purgeCloudRunnerCache=$4
2021-08-15 21:32:43 +00:00
cacheFolderWithBranch="$cacheFolderFull"
lfsCacheFolder="$cacheFolderFull/lfs"
libraryCacheFolder="$cacheFolderFull/lib"
2021-08-01 01:04:38 +00:00
mkdir -p "$lfsCacheFolder"
mkdir -p "$libraryCacheFolder"
2021-07-27 20:45:49 +00:00
2021-08-15 19:10:20 +00:00
echo 'Library Caching'
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
2021-07-12 22:36:40 +00:00
# Restore library cache
2021-08-15 20:30:53 +00:00
ls -lh "$libraryCacheFolder"
2021-08-01 15:49:21 +00:00
latestLibraryCacheFile=$(ls -t "$libraryCacheFolder" | grep .zip$ | head -1)
2021-08-21 05:36:52 +00:00
echo "Checking if Library cache $libraryCacheFolder/$latestLibraryCacheFile exists"
2021-09-21 22:06:24 +00:00
cd $libraryCacheFolder
if [ -f "$latestLibraryCacheFile" ]; then
2021-08-21 05:36:52 +00:00
echo "Library cache exists"
2021-08-21 17:12:58 +00:00
unzip -q "$libraryCacheFolder/$latestLibraryCacheFile" -d "$projectPathFull"
2021-08-21 05:01:15 +00:00
tree "$libraryFolderFull"
fi
2021-08-15 19:10:20 +00:00
echo ' '
echo 'Large File Caching'
2021-08-13 20:19:17 +00:00
echo "Checking large file cache exists ($lfsCacheFolder/$LFS_ASSETS_HASH.zip)"
2021-09-21 22:06:24 +00:00
cd $lfsCacheFolder
if [ -f "$LFS_ASSETS_HASH.zip" ]; then
2021-08-01 20:31:59 +00:00
echo "Match found: using large file hash match $LFS_ASSETS_HASH.zip"
2021-08-01 21:02:06 +00:00
latestLFSCacheFile="$LFS_ASSETS_HASH"
2021-08-01 20:31:59 +00:00
else
latestLFSCacheFile=$(ls -t "$lfsCacheFolder" | grep .zip$ | head -1)
echo "Match not found: using latest large file cache $latestLFSCacheFile"
2021-08-01 01:04:38 +00:00
fi
2021-07-31 21:41:55 +00:00
2021-09-21 22:06:24 +00:00
if [ ! -f "$latestLFSCacheFile" ]; then
2021-08-02 00:07:25 +00:00
echo "LFS cache exists from build $latestLFSCacheFile from $branch"
2021-08-01 01:04:38 +00:00
rm -r "$gitLFSDestinationFolder"
2021-08-21 17:04:11 +00:00
unzip -q "$lfsCacheFolder/$latestLFSCacheFile" -d "$repoPathFull/.git"
echo "git LFS folder, (should not contain $latestLFSCacheFile)"
2021-08-15 20:24:13 +00:00
ls -lh "$gitLFSDestinationFolder/"
2021-07-31 21:41:55 +00:00
fi
2021-07-12 22:36:40 +00:00
2021-08-02 00:07:25 +00:00
echo ' '
2021-08-13 20:34:39 +00:00
echo "LFS cache for $branch"
2021-08-15 20:24:13 +00:00
du -sch "$lfsCacheFolder/"
2021-08-15 19:10:20 +00:00
echo '**'
2021-08-13 20:34:39 +00:00
echo "Library cache for $branch"
2021-08-15 20:24:13 +00:00
du -sch "$libraryCacheFolder/"
2021-08-15 19:10:20 +00:00
echo '**'
2021-08-13 20:34:39 +00:00
echo "Branch: $branch"
2021-08-15 20:24:13 +00:00
du -sch "$cacheFolderWithBranch/"
2021-08-15 19:10:20 +00:00
echo '**'
2021-08-13 20:34:39 +00:00
echo 'Full cache'
2021-08-15 20:24:13 +00:00
du -sch "$cacheFolderFull/"
2021-08-01 01:14:42 +00:00
echo ' '
2021-08-13 20:34:39 +00:00
2021-08-15 15:09:53 +00:00
cd "$repoPathFull"
2021-08-02 00:00:37 +00:00
git lfs pull
echo 'pulled latest LFS files'
2021-08-21 05:01:15 +00:00
cd "$gitLFSDestinationFolder/.."
zip -q -r "$LFS_ASSETS_HASH.zip" "./lfs"
2021-08-02 00:00:37 +00:00
cp "$LFS_ASSETS_HASH.zip" "$lfsCacheFolder"
echo "copied $LFS_ASSETS_HASH to $lfsCacheFolder"
2021-07-31 22:27:59 +00:00
# purge cache
2021-09-21 22:06:24 +00:00
if [ -z "$purgeCloudRunnerCache" ]; then
2021-08-21 05:01:15 +00:00
echo ' '
2021-08-21 19:01:53 +00:00
echo "purging $purgeCloudRunnerCache"
rm -r "$purgeCloudRunnerCache"
2021-08-01 16:22:11 +00:00
echo ' '
fi
2021-08-01 01:04:38 +00:00