Merge pull request #1242 from eerhardt/NuGetCache
Cache NuGet packages on our CI server between builds.
This commit is contained in:
commit
afc0d45e2e
5 changed files with 58 additions and 9 deletions
|
@ -5,6 +5,27 @@
|
|||
|
||||
. $PSScriptRoot\..\common\_common.ps1
|
||||
|
||||
if ($env:CI_BUILD -eq "1") {
|
||||
# periodically clear out the package cache on the CI server
|
||||
$PackageCacheFile = "$env:NUGET_PACKAGES\packageCacheTime.txt"
|
||||
|
||||
if(!(Test-Path $PackageCacheFile)) {
|
||||
Get-Date | Out-File -FilePath $PackageCacheFile
|
||||
}
|
||||
else {
|
||||
$PackageCacheTimeProperty = Get-ItemProperty -Path $PackageCacheFile -Name CreationTimeUtc
|
||||
$PackageCacheTime = [datetime]($PackageCacheTimeProperty).CreationTimeUtc
|
||||
|
||||
if ($PackageCacheTime -lt ([datetime]::UtcNow).AddHours(-$env:NUGET_PACKAGES_CACHE_TIME_LIMIT)) {
|
||||
header "Clearing package cache"
|
||||
|
||||
Remove-Item -Recurse -Force "$env:NUGET_PACKAGES"
|
||||
mkdir $env:NUGET_PACKAGES | Out-Null
|
||||
Get-Date | Out-File -FilePath $PackageCacheFile
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Restore packages
|
||||
# NOTE(anurse): I had to remove --quiet, because NuGet3 is too quiet when that's provided :(
|
||||
header "Restoring packages"
|
||||
|
|
|
@ -16,6 +16,26 @@ DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
|||
|
||||
source "$DIR/../common/_common.sh"
|
||||
|
||||
if [ ! -z "$CI_BUILD" ]; then
|
||||
# periodically clear out the package cache on the CI server
|
||||
PackageCacheFile="$NUGET_PACKAGES/packageCacheTime.txt"
|
||||
if [ ! -f $PackageCacheFile ]; then
|
||||
date > $PackageCacheFile
|
||||
else
|
||||
#$NUGET_PACKAGES_CACHE_TIME_LIMIT is in hours
|
||||
CacheTimeLimitInSeconds=$(($NUGET_PACKAGES_CACHE_TIME_LIMIT * 3600))
|
||||
CacheExpireTime=$(($(date +%s) - $CacheTimeLimitInSeconds))
|
||||
|
||||
if [ $(date +%s -r $PackageCacheFile) -lt $CacheExpireTime ]; then
|
||||
header "Clearing package cache"
|
||||
|
||||
rm -Rf $NUGET_PACKAGES
|
||||
mkdir -p $NUGET_PACKAGES
|
||||
date > $PackageCacheFile
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
header "Restoring packages"
|
||||
|
||||
dotnet restore "$REPOROOT/src" --runtime "$RID" $DISABLE_PARALLEL
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
set -e
|
||||
|
||||
export CI_BUILD=1
|
||||
|
||||
SOURCE="${BASH_SOURCE[0]}"
|
||||
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
|
||||
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
||||
|
|
|
@ -3,14 +3,12 @@
|
|||
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
#
|
||||
|
||||
if ($env:CI_BUILD -eq "1") {
|
||||
$env:NUGET_PACKAGES = (Join-Path $RepoRoot "artifacts\home\.nuget\packages")
|
||||
} else {
|
||||
$env:NUGET_PACKAGES = (Join-Path $env:USERPROFILE ".nuget\packages")
|
||||
}
|
||||
|
||||
$env:NUGET_PACKAGES = (Join-Path $env:USERPROFILE ".nuget\packages")
|
||||
$env:DOTNET_PACKAGES = $env:NUGET_PACKAGES
|
||||
$env:DNX_PACKAGES = $env:NUGET_PACKAGES
|
||||
if(!(Test-Path $env:NUGET_PACKAGES)) {
|
||||
mkdir $env:NUGET_PACKAGES | Out-Null
|
||||
}
|
||||
}
|
||||
|
||||
# default the package cache expiration to 1 week, in hours
|
||||
setEnvIfDefault "NUGET_PACKAGES_CACHE_TIME_LIMIT" (7 * 24)
|
||||
|
|
|
@ -4,7 +4,15 @@
|
|||
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
#
|
||||
|
||||
## Temporarily redirect to the NuGet package installation location
|
||||
export NUGET_PACKAGES=~/.nuget/packages
|
||||
export DOTNET_PACKAGES=$NUGET_PACKAGES
|
||||
export DNX_PACKAGES=$NUGET_PACKAGES
|
||||
export DNX_PACKAGES=$NUGET_PACKAGES
|
||||
|
||||
if [ ! -d $NUGET_PACKAGES ]; then
|
||||
mkdir -p $NUGET_PACKAGES
|
||||
fi
|
||||
|
||||
if [ -z "$NUGET_PACKAGES_CACHE_TIME_LIMIT" ]; then
|
||||
# default the package cache expiration to 1 week, in hours
|
||||
export NUGET_PACKAGES_CACHE_TIME_LIMIT=$(( 7 * 24 ))
|
||||
fi
|
||||
|
|
Loading…
Reference in a new issue