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

65 lines
1.5 KiB
Bash
Raw Normal View History

#!/bin/sh
cacheFolderFull=$1
2021-07-12 22:46:21 +00:00
branchName=$2
libraryFolderFull=$3
2021-07-12 22:46:21 +00:00
purgeRemoteBuilderCache=$4
2021-07-31 20:52:37 +00:00
echo " "
echo "Caching starting, parameters:"
echo "$cacheFolderFull"
echo "$branchName"
echo "$libraryFolderFull"
echo "$purgeRemoteBuilderCache"
cacheFolderWithBranch="$cacheFolderFull/$branchName"
2021-07-31 20:52:37 +00:00
echo " "
2021-07-27 20:45:49 +00:00
# handle library cache
2021-07-27 22:40:48 +00:00
if [ ! -d "$cacheFolderFull" ]; then
2021-07-27 22:23:02 +00:00
echo "creating new cache folder $cacheFolderFull"
mkdir "$cacheFolderFull"
if [ ! -d "$cacheFolderWithBranch" ]; then
echo "creating new cache branch folder for: $cacheFolderWithBranch"
mkdir "$cacheFolderWithBranch"
2021-07-27 22:40:48 +00:00
else
echo "cache branch folder already exists for: $cacheFolderWithBranch"
2021-07-27 22:40:48 +00:00
fi
2021-07-27 22:23:02 +00:00
else
echo "cache folder already exists $cacheFolderFull"
2021-07-27 20:45:49 +00:00
fi
2021-07-27 22:23:02 +00:00
2021-07-27 20:45:49 +00:00
echo "Library cache for branch: $branchName"
ls -lh "$cacheFolderWithBranch"
2021-07-27 20:45:49 +00:00
echo ''
2021-07-27 22:40:48 +00:00
if [ -d "$libraryFolderFull" ]; then
rm -r "$libraryFolderFull"
2021-07-27 20:45:49 +00:00
echo "Git must ignore the Library folder"
fi
echo "Checking cache"
2021-07-12 22:36:40 +00:00
# Restore library cache
latest=$(ls -t "$cacheFolderWithBranch" | egrep -i -e '\\.zip$' | head -1)
if [ "$(ls -A $latest)" ]; then
echo 'Cache empty'
else if [ ! -z "$latest" ]; then
echo "Library cache exists from build $latest from $branchName"
echo 'Creating empty Library folder for cache'
mkdir "$libraryFolderFull"
unzip -q "$cacheFolderWithBranch/$latest" -d "$libraryFolderFull"
else
echo 'Cache does not exist'
fi
2021-07-12 22:36:40 +00:00
# Restore LFS cache
# purge cache
if [ "$purgeRemoteBuilderCache" == "true" ]; then
rm -r "$libraryFolderFull"
fi