Cache NuGet packages on our CI server between builds.
Currently on our CI builds, we point our NuGet cache under the repo. In between builds the repo gets deleted, thus the cache is lost. This change moves the cache to %userprofile%\.nuget\packages on CI and dev boxes. On CI, we expire the cache after a day by default.
This commit is contained in:
parent
be4629a6a6
commit
617af759ae
5 changed files with 58 additions and 9 deletions
|
@ -5,6 +5,27 @@
|
||||||
|
|
||||||
. $PSScriptRoot\..\common\_common.ps1
|
. $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
|
# Restore packages
|
||||||
# NOTE(anurse): I had to remove --quiet, because NuGet3 is too quiet when that's provided :(
|
# NOTE(anurse): I had to remove --quiet, because NuGet3 is too quiet when that's provided :(
|
||||||
header "Restoring packages"
|
header "Restoring packages"
|
||||||
|
|
|
@ -16,6 +16,26 @@ DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
||||||
|
|
||||||
source "$DIR/../common/_common.sh"
|
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"
|
header "Restoring packages"
|
||||||
|
|
||||||
dotnet restore "$REPOROOT/src" --runtime "$RID" $DISABLE_PARALLEL
|
dotnet restore "$REPOROOT/src" --runtime "$RID" $DISABLE_PARALLEL
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
export CI_BUILD=1
|
||||||
|
|
||||||
SOURCE="${BASH_SOURCE[0]}"
|
SOURCE="${BASH_SOURCE[0]}"
|
||||||
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
|
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
|
||||||
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
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.
|
# 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 $env:USERPROFILE ".nuget\packages")
|
||||||
$env:NUGET_PACKAGES = (Join-Path $RepoRoot "artifacts\home\.nuget\packages")
|
|
||||||
} else {
|
|
||||||
$env:NUGET_PACKAGES = (Join-Path $env:USERPROFILE ".nuget\packages")
|
|
||||||
}
|
|
||||||
|
|
||||||
$env:DOTNET_PACKAGES = $env:NUGET_PACKAGES
|
$env:DOTNET_PACKAGES = $env:NUGET_PACKAGES
|
||||||
$env:DNX_PACKAGES = $env:NUGET_PACKAGES
|
$env:DNX_PACKAGES = $env:NUGET_PACKAGES
|
||||||
if(!(Test-Path $env:NUGET_PACKAGES)) {
|
if(!(Test-Path $env:NUGET_PACKAGES)) {
|
||||||
mkdir $env:NUGET_PACKAGES | Out-Null
|
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.
|
# 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 NUGET_PACKAGES=~/.nuget/packages
|
||||||
export DOTNET_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…
Add table
Add a link
Reference in a new issue