build.ps1 1.7 KB

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