run-tests.ps1 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <#
  2. .SYNOPSIS
  3. This script runs the tests in this project on complete build of the .NET Core CLI
  4. .PARAMETER ci
  5. This is a CI build
  6. .PARAMETER AccessTokenSuffix
  7. The access token for Azure blobs
  8. .PARAMETER AssetRootUrl
  9. The blob feed for the .NET Core CLI. If not specified, it will determined automatically if possible.
  10. .PARAMETER RestoreSources
  11. A list of additional NuGet feeds. If not specified, it will determined automatically if possible.
  12. .PARAMETER TestRuntimeIdentifier
  13. Filter the tests by which RID they publish for. If empty (default), tests are run for
  14. * none (portable)
  15. * osx-x64
  16. * linux-x64
  17. * win-x64
  18. .PARAMETER HostRid
  19. The RID of the platform running the tests. (Determined automatically if possible)
  20. .PARAMETER ProdConManifestUrl
  21. The prodcon build.xml file
  22. .PARAMETER ProdConChannel
  23. The prodcon channel to use if a build.xml file isn't set.
  24. .PARAMETER AdditionalRestoreSources
  25. A pipe-separated list of extra NuGet feeds. Required for builds which need to restore from multiple feeds.
  26. #>
  27. param(
  28. [switch]$ci,
  29. $AssetRootUrl = $env:PB_ASSETROOTURL,
  30. $AccessTokenSuffix = $env:PB_ACCESSTOKENSUFFIX,
  31. $RestoreSources = $env:PB_RESTORESOURCE,
  32. [ValidateSet('none', 'osx-x64', 'linux-x64', 'win-x64')]
  33. $TestRuntimeIdentifier,
  34. $HostRid,
  35. $ProdConManifestUrl,
  36. $ProdConChannel = 'release/2.2',
  37. $AdditionalRestoreSources
  38. )
  39. $ErrorActionPreference = 'Stop'
  40. Set-StrictMode -Version 1
  41. $repoRoot = Resolve-Path "$PSScriptRoot/../../"
  42. Import-Module "$repoRoot/scripts/common.psm1" -Scope Local -Force
  43. # This ID corresponds to the ProdCon build number
  44. Write-Host "ProductBuildId: $env:PRODUCTBUILDID"
  45. if (-not $HostRid) {
  46. if (Test-Path Variable:/IsCoreCLR) {
  47. $HostRid = if ($IsWindows) { 'win-x64' } `
  48. elseif ($IsLinux) { 'linux-x64' } `
  49. elseif ($IsMacOS) { 'osx-x64' }
  50. }
  51. else {
  52. $HostRid = 'win-x64'
  53. }
  54. }
  55. if (-not $HostRid) {
  56. throw 'Could not determine which platform this script is running on. Add -HostRid $rid where $rid = the .NET Core SDK to install'
  57. }
  58. switch ($HostRid) {
  59. 'win-x64' {
  60. $dotnetFileName = 'dotnet.exe'
  61. $archiveExt = '.zip'
  62. }
  63. default {
  64. $dotnetFileName = 'dotnet'
  65. $archiveExt = '.tar.gz'
  66. }
  67. }
  68. Push-Location $PSScriptRoot
  69. try {
  70. New-Item -Type Directory "$PSScriptRoot/obj/" -ErrorAction Ignore | Out-Null
  71. $sdkVersion = ''
  72. if (-not $ci -or $ProdConManifestUrl) {
  73. # Workaround for pwsh 6 dumping progress info
  74. $ProgressPreference = 'SilentlyContinue'
  75. if (-not $ProdConManifestUrl) {
  76. Write-Host -ForegroundColor Magenta "Running tests for the latest ProdCon build"
  77. $ProdConManifestUrl = "https://raw.githubusercontent.com/dotnet/versions/master/build-info/dotnet/product/cli/$ProdConChannel/build.xml"
  78. }
  79. Write-Host "ProdConManifestUrl: $ProdConManifestUrl"
  80. [xml] $prodConManifest = Invoke-RestMethod $ProdConManifestUrl
  81. $RestoreSources = $prodConManifest.OrchestratedBuild.Endpoint `
  82. | ? { $_.Type -eq 'BlobFeed' } `
  83. | select -first 1 -ExpandProperty Url
  84. $AssetRootUrl = $RestoreSources -replace '/index.json', '/assets'
  85. $sdkVersion = $prodConManifest.OrchestratedBuild.Build `
  86. | ? { $_.Name -eq 'cli' } `
  87. | select -first 1 -ExpandProperty ProductVersion
  88. }
  89. else {
  90. if (-not $AssetRootUrl) {
  91. Write-Error "Missing required parameter: AssetRootUrl"
  92. }
  93. $AssetRootUrl = $AssetRootUrl.TrimEnd('/')
  94. $cliMetadataUrl = "$AssetRootUrl/orchestration-metadata/manifests/cli.xml${AccessTokenSuffix}"
  95. Write-Host "CliMetadataUrl: $cliMetadataUrl"
  96. [xml] $cli = Invoke-RestMethod $cliMetadataUrl
  97. $sdkVersion = $cli.Build.ProductVersion
  98. }
  99. if ($AdditionalRestoreSources) {
  100. $RestoreSources += "|$AdditionalRestoreSources"
  101. }
  102. Write-Host "sdkVersion: $sdkVersion"
  103. Write-Host "AssetRootUrl: $AssetRootUrl"
  104. Write-Host "RestoreSources: $RestoreSources"
  105. @{ sdk = @{ version = $sdkVersion } } | ConvertTo-Json | Set-Content "$PSScriptRoot/global.json"
  106. $dotnetRoot = "$repoRoot/.dotnet"
  107. $dotnet = "$dotnetRoot/$dotnetFileName"
  108. if (-not (Test-Path "$dotnetRoot/sdk/$sdkVersion/dotnet.dll")) {
  109. Remove-Item -Recurse -Force $dotnetRoot -ErrorAction Ignore | Out-Null
  110. $cliUrl = "$AssetRootUrl/Sdk/$sdkVersion/dotnet-sdk-$sdkVersion-$HostRid$archiveExt"
  111. $cliArchiveFile = "$PSScriptRoot/obj/dotnet$archiveExt"
  112. Write-Host "Downloading $cliUrl"
  113. Invoke-WebRequest -UseBasicParsing "${cliUrl}${AccessTokenSuffix}" -OutFile $cliArchiveFile
  114. if ($archiveExt -eq '.zip') {
  115. Expand-Archive $cliArchiveFile -DestinationPath $dotnetRoot
  116. }
  117. else {
  118. New-Item -Type Directory $dotnetRoot -ErrorAction Ignore | Out-Null
  119. Invoke-Block { & tar xzf $cliArchiveFile -C $dotnetRoot }
  120. }
  121. }
  122. # Set a clean test environment
  123. $env:DOTNET_ROOT = $dotnetRoot
  124. $env:DOTNET_MULTILEVEL_LOOKUP = 0
  125. $env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = 0
  126. $env:MSBUILDSDKSPATH = ''
  127. $env:PATH = "$dotnetRoot;$env:PATH"
  128. # Required by the tests. It is assumed packages on this feed will end up on nuget.org
  129. $env:NUGET_PACKAGE_SOURCE = $RestoreSources
  130. [string[]] $filterArgs = @()
  131. if ($TestRuntimeIdentifier) {
  132. $filterArgs += '--filter',"rid: $TestRuntimeIdentifier"
  133. }
  134. Invoke-Block { & $dotnet test `
  135. --logger "console;verbosity=detailed" `
  136. --logger "trx;LogFileName=$repoRoot/artifacts/logs/e2etests.trx" `
  137. "-bl:$repoRoot/artifacts/logs/e2etests.binlog" `
  138. @filterArgs }
  139. }
  140. finally {
  141. Pop-Location
  142. }