From 6b4077e868458bbe0f33d40d1c7e14804c2e7e95 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Wed, 1 Jul 2020 08:54:45 -0700 Subject: [PATCH 1/4] Fix and parallelize .NET installation --- PowerShellEditorServices.build.ps1 | 65 +++++++++++++++++++++++------- 1 file changed, 50 insertions(+), 15 deletions(-) diff --git a/PowerShellEditorServices.build.ps1 b/PowerShellEditorServices.build.ps1 index 34583f1be..acf809e0c 100644 --- a/PowerShellEditorServices.build.ps1 +++ b/PowerShellEditorServices.build.ps1 @@ -55,28 +55,65 @@ function Invoke-WithCreateDefaultHook { function Install-Dotnet { param ( - $Channel + [string[]]$Channel ) - Write-Host "`n### Installing .NET CLI $Version...`n" -ForegroundColor Green + $env:DOTNET_INSTALL_DIR = "$PSScriptRoot/.dotnet" + + $installSb = { + param( + $InstallScriptPath, + $Version, + $Channel, + $DotnetInstallDir, + $IsUnix + ) + + Write-Information "`n### Installing .NET CLI $Version...`n" + + if ($IsUnix) { + chmod +x $InstallScriptPath + } + + $params = if ($script:IsUnix) + { + @('-Channel', $Channel, '-InstallDir', $DotnetInstallDir, '-NoPath', '-Verbose') + } + else + { + @{ + Channel = $Channel + InstallDir = $DotnetInstallDir + NoPath = $true + Verbose = $true + } + } + + & $InstallScriptPath @params + + Write-Information "`n### Installation complete for version $Version." + } + + Write-Information "Installing .NET channels $Channel" # The install script is platform-specific - $installScriptExt = if ($script:IsUnix) { "sh" } else { "ps1" } + $installScriptExt = if ($IsUnix) { "sh" } else { "ps1" } + $installScript = "dotnet-install.$installScriptExt" # Download the official installation script and run it - $installScriptPath = "$([System.IO.Path]::GetTempPath())dotnet-install.$installScriptExt" - Invoke-WebRequest "https://dot.net/v1/dotnet-install.$installScriptExt" -OutFile $installScriptPath - $env:DOTNET_INSTALL_DIR = "$PSScriptRoot/.dotnet" + $installScriptPath = Join-Path ([System.IO.Path]::GetTempPath()) $installScript + Invoke-WebRequest "https://dot.net/v1/$installScript" -OutFile $installScriptPath - if ($script:IsUnix) { - chmod +x $installScriptPath - } + # Download and install the different .NET channels in parallel + $Channel | + ForEach-Object { + Start-Job -ScriptBlock $installSb -ArgumentList $installScriptPath,$Version,$_,$env:DOTNET_INSTALL_DIR,$script:IsUnix + } | + Receive-Job -Wait - $paramArr = @('-Channel', $Channel, '-InstallDir', "'$env:DOTNET_INSTALL_DIR'", '-NoPath') - Invoke-Expression "$installScriptPath $paramArr" $env:PATH = $env:DOTNET_INSTALL_DIR + [System.IO.Path]::PathSeparator + $env:PATH - Write-Host "`n### Installation complete." -ForegroundColor Green + Write-Information '.NET installation complete' } task SetupDotNet -Before Clean, Build, TestHost, TestServerWinPS, TestServerPS7, TestServerPS71, TestE2E { @@ -85,9 +122,7 @@ task SetupDotNet -Before Clean, Build, TestHost, TestServerWinPS, TestServerPS7, $dotnetExePath = if ($script:IsUnix) { "$dotnetPath/dotnet" } else { "$dotnetPath/dotnet.exe" } if (!(Test-Path $dotnetExePath)) { - Install-Dotnet -Channel '2.1' - Install-Dotnet -Channel '3.1' - Install-Dotnet -Channel 'release/5.0.1xx-preview6' + Install-Dotnet -Channel '2.1','3.1','release/5.0.1xx-preview6' } # This variable is used internally by 'dotnet' to know where it's installed From 7a91c6851e692a40353ac9cf7779f5982b96abfc Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Wed, 1 Jul 2020 09:52:16 -0700 Subject: [PATCH 2/4] Serialize downloads --- PowerShellEditorServices.build.ps1 | 49 +++++++++++------------------- 1 file changed, 18 insertions(+), 31 deletions(-) diff --git a/PowerShellEditorServices.build.ps1 b/PowerShellEditorServices.build.ps1 index acf809e0c..b02709cbf 100644 --- a/PowerShellEditorServices.build.ps1 +++ b/PowerShellEditorServices.build.ps1 @@ -60,57 +60,44 @@ function Install-Dotnet { $env:DOTNET_INSTALL_DIR = "$PSScriptRoot/.dotnet" - $installSb = { - param( - $InstallScriptPath, - $Version, - $Channel, - $DotnetInstallDir, - $IsUnix - ) + Write-Information "Installing .NET channels $Channel" + + # The install script is platform-specific + $installScriptExt = if ($script:IsUnix) { "sh" } else { "ps1" } + $installScript = "dotnet-install.$installScriptExt" + # Download the official installation script and run it + $installScriptPath = Join-Path ([System.IO.Path]::GetTempPath()) $installScript + Invoke-WebRequest "https://dot.net/v1/$installScript" -OutFile $installScriptPath + + # Download and install the different .NET channels in parallel + foreach ($dotnetChannel in $Channel) + { Write-Information "`n### Installing .NET CLI $Version...`n" - if ($IsUnix) { - chmod +x $InstallScriptPath + if ($script:IsUnix) { + chmod +x $installScriptPath } $params = if ($script:IsUnix) { - @('-Channel', $Channel, '-InstallDir', $DotnetInstallDir, '-NoPath', '-Verbose') + @('-Channel', $dotnetChannel, '-InstallDir', $env:DOTNET_INSTALL_DIR, '-NoPath', '-Verbose') } else { @{ - Channel = $Channel - InstallDir = $DotnetInstallDir + Channel = $dotnetChannel + InstallDir = $env:DOTNET_INSTALL_DIR NoPath = $true Verbose = $true } } - & $InstallScriptPath @params + & $installScriptPath @params Write-Information "`n### Installation complete for version $Version." } - Write-Information "Installing .NET channels $Channel" - - # The install script is platform-specific - $installScriptExt = if ($IsUnix) { "sh" } else { "ps1" } - $installScript = "dotnet-install.$installScriptExt" - - # Download the official installation script and run it - $installScriptPath = Join-Path ([System.IO.Path]::GetTempPath()) $installScript - Invoke-WebRequest "https://dot.net/v1/$installScript" -OutFile $installScriptPath - - # Download and install the different .NET channels in parallel - $Channel | - ForEach-Object { - Start-Job -ScriptBlock $installSb -ArgumentList $installScriptPath,$Version,$_,$env:DOTNET_INSTALL_DIR,$script:IsUnix - } | - Receive-Job -Wait - $env:PATH = $env:DOTNET_INSTALL_DIR + [System.IO.Path]::PathSeparator + $env:PATH Write-Information '.NET installation complete' From 20efc5302f71fa6f16660d6558e61c1a81acd2a5 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Wed, 1 Jul 2020 10:26:38 -0700 Subject: [PATCH 3/4] Move back to write-host --- PowerShellEditorServices.build.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/PowerShellEditorServices.build.ps1 b/PowerShellEditorServices.build.ps1 index b02709cbf..26eebfb37 100644 --- a/PowerShellEditorServices.build.ps1 +++ b/PowerShellEditorServices.build.ps1 @@ -60,7 +60,7 @@ function Install-Dotnet { $env:DOTNET_INSTALL_DIR = "$PSScriptRoot/.dotnet" - Write-Information "Installing .NET channels $Channel" + Write-Host "Installing .NET channels $Channel" -ForegroundColor Green # The install script is platform-specific $installScriptExt = if ($script:IsUnix) { "sh" } else { "ps1" } @@ -73,7 +73,7 @@ function Install-Dotnet { # Download and install the different .NET channels in parallel foreach ($dotnetChannel in $Channel) { - Write-Information "`n### Installing .NET CLI $Version...`n" + Write-Host "`n### Installing .NET CLI $Version...`n" if ($script:IsUnix) { chmod +x $installScriptPath @@ -95,12 +95,12 @@ function Install-Dotnet { & $installScriptPath @params - Write-Information "`n### Installation complete for version $Version." + Write-Host "`n### Installation complete for version $Version." } $env:PATH = $env:DOTNET_INSTALL_DIR + [System.IO.Path]::PathSeparator + $env:PATH - Write-Information '.NET installation complete' + Write-Host '.NET installation complete' -ForegroundColor Green } task SetupDotNet -Before Clean, Build, TestHost, TestServerWinPS, TestServerPS7, TestServerPS71, TestE2E { From 98e6b27f34286e377bb8aa01759a7072d470331c Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Wed, 1 Jul 2020 12:38:00 -0700 Subject: [PATCH 4/4] Remove defunct parallel comment --- PowerShellEditorServices.build.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PowerShellEditorServices.build.ps1 b/PowerShellEditorServices.build.ps1 index 26eebfb37..9934646ae 100644 --- a/PowerShellEditorServices.build.ps1 +++ b/PowerShellEditorServices.build.ps1 @@ -70,7 +70,7 @@ function Install-Dotnet { $installScriptPath = Join-Path ([System.IO.Path]::GetTempPath()) $installScript Invoke-WebRequest "https://dot.net/v1/$installScript" -OutFile $installScriptPath - # Download and install the different .NET channels in parallel + # Download and install the different .NET channels foreach ($dotnetChannel in $Channel) { Write-Host "`n### Installing .NET CLI $Version...`n"