1+ $ErrorActionPreference = " Stop"
2+
3+ function DownloadWithRetry ([string ] $url , [string ] $downloadLocation , [int ] $retries )
4+ {
5+ while ($true )
6+ {
7+ try
8+ {
9+ Invoke-WebRequest $url - OutFile $downloadLocation
10+ break
11+ }
12+ catch
13+ {
14+ $exceptionMessage = $_.Exception.Message
15+ Write-Host " Failed to download '$url ': $exceptionMessage "
16+ if ($retries -gt 0 ) {
17+ $retries --
18+ Write-Host " Waiting 10 seconds before retrying. Retries left: $retries "
19+ Start-Sleep - Seconds 10
20+
21+ }
22+ else
23+ {
24+ $exception = $_.Exception
25+ throw $exception
26+ }
27+ }
28+ }
29+ }
30+
31+ cd $PSScriptRoot
32+
33+ $repoFolder = $PSScriptRoot
34+ $env: REPO_FOLDER = $repoFolder
35+
36+ $koreBuildZip = " https://github.com/aspnet/KoreBuild/archive/rel/1.1.0.zip"
37+ if ($env: KOREBUILD_ZIP )
38+ {
39+ $koreBuildZip = $env: KOREBUILD_ZIP
40+ }
41+
42+ $buildFolder = " .build"
43+ $buildFile = " $buildFolder \KoreBuild.ps1"
44+
45+ if (! (Test-Path $buildFolder )) {
46+ Write-Host " Downloading KoreBuild from $koreBuildZip "
47+
48+ $tempFolder = $env: TEMP + " \KoreBuild-" + [guid ]::NewGuid()
49+ New-Item - Path " $tempFolder " - Type directory | Out-Null
50+
51+ $localZipFile = " $tempFolder \korebuild.zip"
52+
53+ DownloadWithRetry - url $koreBuildZip - downloadLocation $localZipFile - retries 6
54+
55+ Add-Type - AssemblyName System.IO.Compression.FileSystem
56+ [System.IO.Compression.ZipFile ]::ExtractToDirectory($localZipFile , $tempFolder )
57+
58+ New-Item - Path " $buildFolder " - Type directory | Out-Null
59+ copy-item " $tempFolder \**\build\*" $buildFolder - Recurse
60+
61+ # Cleanup
62+ if (Test-Path $tempFolder ) {
63+ Remove-Item - Recurse - Force $tempFolder
64+ }
65+ }
66+
67+ & " $buildFile " $args
0 commit comments