From 08c24ea7ecb3cfd211534b83be4e0bd59c7d6298 Mon Sep 17 00:00:00 2001 From: Andy Jordan <2226434+andyleejordan@users.noreply.github.com> Date: Tue, 10 Sep 2024 16:46:39 -0700 Subject: [PATCH] Remove `dotnet` bootstrap/installation code We should not be doing this for the developer/user. --- Tests/Build/BuildModule.tests.ps1 | 54 -------- build.ps1 | 20 +-- build.psm1 | 203 +----------------------------- 3 files changed, 5 insertions(+), 272 deletions(-) diff --git a/Tests/Build/BuildModule.tests.ps1 b/Tests/Build/BuildModule.tests.ps1 index 542ac2a52..ebc4e2a6a 100644 --- a/Tests/Build/BuildModule.tests.ps1 +++ b/Tests/Build/BuildModule.tests.ps1 @@ -48,60 +48,6 @@ Describe "Build Module Tests" { } } - Context "Test-DotnetInstallation" { - BeforeAll { - $availableVersions = ConvertTo-PortableVersion -strVersion "2.2.400","2.2.401","2.2.405" - $foundVersion = ConvertTo-PortableVersion -strVersion 2.2.402 - $missingVersion = ConvertTo-PortableVersion -strVersion 2.2.410 - } - - It "Test-DotnetInstallation finds a good version" { - Mock Get-InstalledCLIVersion { return $availableVersions } - Mock Get-GlobalJSonSdkVersion { return $foundVersion } - $result = Test-DotnetInstallation -requestedVersion (Get-GlobalJsonSdkVersion) -installedVersions (Get-InstalledCLIVersion) - Assert-MockCalled "Get-InstalledCLIVersion" -Times 1 - Assert-MockCalled "Get-GlobalJsonSdkVersion" -Times 1 - $result | Should -Be $true - } - - It "Test-DotnetInstallation cannot find a good version should return false" { - Mock Get-InstalledCLIVersion { return $availableVersions } - Mock Get-GlobalJSonSdkVersion { return $missingVersion } - $result = Test-DotnetInstallation -requestedVersion (Get-GlobalJsonSdkVersion) -installedVersions (Get-InstalledCLIVersion) - Assert-MockCalled "Get-InstalledCLIVersion" -Times 1 - Assert-MockCalled "Get-GlobalJsonSdkVersion" -Times 1 - $result | Should -Be $false - } - } - - Context "Receive-DotnetInstallScript" { - - Mock -ModuleName Build Receive-File { new-item -type file TestDrive:/dotnet-install.sh } - It "Downloads the proper non-Windows file" { - try { - push-location TestDrive: - Receive-DotnetInstallScript -platform NonWindows - "TestDrive:/dotnet-install.sh" | Should -Exist - } - finally { - Pop-Location - } - } - - Mock -ModuleName Build Receive-File { new-item -type file TestDrive:/dotnet-install.ps1 } - It "Downloads the proper file Windows file" { - try { - push-location TestDrive: - Receive-DotnetInstallScript -platform "Windows" - "TestDrive:/dotnet-install.ps1" | Should -Exist - } - finally { - Pop-Location - } - } - - } - Context "Test result functions" { BeforeAll { $xmlFile = @' diff --git a/build.ps1 b/build.ps1 index a0e27e798..bbc6c505a 100644 --- a/build.ps1 +++ b/build.ps1 @@ -33,20 +33,11 @@ param( [Parameter(ParameterSetName='Test')] [switch] $InProcess, - [Parameter(ParameterSetName='Bootstrap')] - [switch] $Bootstrap, - [Parameter(ParameterSetName='BuildAll')] [switch] $Catalog, [Parameter(ParameterSetName='Package')] - [switch] $BuildNupkg, - - [Parameter(ParameterSetName='Package')] - [switch] $CopyManifest, - - [Parameter(ParameterSetName='Package')] - [switch] $Signed + [switch] $BuildNupkg ) @@ -90,15 +81,8 @@ END { } Start-ScriptAnalyzerBuild @buildArgs } - "Bootstrap" { - Install-DotNet - return - } "Package" { - if($CopyManifest) { - Copy-Manifest -signed:$Signed - } - Start-CreatePackage -signed:$Signed + Start-CreatePackage } "Test" { Test-ScriptAnalyzer -InProcess:$InProcess diff --git a/build.psm1 b/build.psm1 index 22dc9ee5e..6889f1b89 100644 --- a/build.psm1 +++ b/build.psm1 @@ -7,8 +7,7 @@ $analyzerName = "PSScriptAnalyzer" function Get-AnalyzerVersion { - $csprojPath = [io.path]::Combine($projectRoot,"Engine","Engine.csproj") - $xml = [xml](Get-Content "${csprojPath}") + [xml]$xml = Get-Content $([io.path]::Combine($projectRoot,"Engine","Engine.csproj")) $xml.SelectSingleNode(".//VersionPrefix")."#text" } @@ -29,61 +28,6 @@ function Publish-File } } -# attempt to get the users module directory -function Get-UserModulePath -{ - if ( $IsCoreCLR -and -not $IsWindows ) - { - $platformType = "System.Management.Automation.Platform" -as [Type] - if ( $platformType ) { - ${platformType}::SelectProductNameForDirectory("USER_MODULES") - } - else { - throw "Could not determine users module path" - } - } - else { - "${HOME}/Documents/WindowsPowerShell/Modules" - } -} - - -function Uninstall-ScriptAnalyzer -{ - [CmdletBinding(SupportsShouldProcess)] - param ( $ModulePath = $(Join-Path -Path (Get-UserModulePath) -ChildPath ${analyzerName}) ) - END { - if ( $PSCmdlet.ShouldProcess("$modulePath") ) { - Remove-Item -Recurse -Path "$ModulePath" -Force - } - } -} - -# install script analyzer, by default into the users module path -function Install-ScriptAnalyzer -{ - [CmdletBinding(SupportsShouldProcess)] - param ( $ModulePath = $(Join-Path -Path (Get-UserModulePath) -ChildPath ${analyzerName}) ) - END { - if ( $PSCmdlet.ShouldProcess("$modulePath") ) { - Copy-Item -Recurse -Path "$script:destinationDir" -Destination "$ModulePath\." -Force - } - } -} - -# if script analyzer is installed, remove it -function Uninstall-ScriptAnalyzer -{ - [CmdletBinding(SupportsShouldProcess)] - param ( $ModulePath = $(Join-Path -Path (Get-UserModulePath) -ChildPath ${analyzerName}) ) - END { - if ((Test-Path $ModulePath) -and (Get-Item $ModulePath).PSIsContainer ) - { - Remove-Item -Force -Recurse $ModulePath - } - } -} - # Clean up the build location function Remove-Build { @@ -157,9 +101,6 @@ function Start-ScriptAnalyzerBuild BEGIN { # don't allow the build to be started unless we have the proper Cli version - # this will not actually install dotnet if it's already present, but it will - # install the proper version - Install-Dotnet if ( -not (Test-SuitableDotnet) ) { $requiredVersion = $script:wantedVersion $foundVersion = Get-InstalledCLIVersion @@ -431,49 +372,6 @@ function Get-TestFailures $results.SelectNodes(".//test-case[@result='Failure']") } -# BOOTSTRAPPING CODE FOR INSTALLING DOTNET -# install dotnet cli tools based on the version mentioned in global.json -function Install-Dotnet -{ - [CmdletBinding(SupportsShouldProcess=$true)] - param ( - [Parameter()][Switch]$Force, - [Parameter()]$version = $( Get-GlobalJsonSdkVersion -Raw ) - ) - - if ( Test-DotnetInstallation -requestedversion $version ) { - if ( $Force ) { - Write-Verbose -Verbose "Installing again" - } - else { - return - } - } - - try { - Push-Location $PSScriptRoot - $installScriptPath = Receive-DotnetInstallScript - $installScriptName = [System.IO.Path]::GetFileName($installScriptPath) - If ( $PSCmdlet.ShouldProcess("$installScriptName for $version")) { - & "${installScriptPath}" -c release -version $version -SkipNonVersionedFiles - } - # this may be the first time that dotnet has been installed, - # set up the executable variable - if ( -not $script:DotnetExe ) { - $script:DotnetExe = Get-DotnetExe - } - } - catch { - throw $_ - } - finally { - if ( Test-Path $installScriptPath ) { - Remove-Item $installScriptPath - } - Pop-Location - } -} - function Get-GlobalJsonSdkVersion { param ( [switch]$Raw ) $json = Get-Content -raw (Join-Path $PSScriptRoot global.json) | ConvertFrom-Json @@ -612,68 +510,6 @@ function Get-InstalledCLIVersion { return (ConvertTo-PortableVersion $installedVersions) } -function Test-DotnetInstallation -{ - param ( - $requestedVersion = $script:wantedVersion, - $installedVersions = $( Get-InstalledCLIVersion ) - ) - return (Test-SuitableDotnet -availableVersions $installedVersions -requiredVersion $requestedVersion ) -} - -function Receive-File { - param ( [Parameter(Mandatory,Position=0)]$uri ) - - # enable Tls12 for the request - # -SslProtocol parameter for Invoke-WebRequest wasn't in PSv3 - $securityProtocol = [System.Net.ServicePointManager]::SecurityProtocol - $tls12 = [System.Net.SecurityProtocolType]::Tls12 - try { - if ( ([System.Net.ServicePointManager]::SecurityProtocol -band $tls12) -eq 0 ) { - [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor $tls12 - } - $null = Invoke-WebRequest -Uri ${uri} -OutFile "${installScriptName}" - } - finally { - [System.Net.ServicePointManager]::SecurityProtocol = $securityProtocol - } - if ( (Test-Path Variable:IsWindows) -and -not $IsWindows ) { - chmod +x $installScriptName - } - $installScript = Get-Item $installScriptName -ErrorAction Stop - if ( -not $installScript ) { - throw "Download failure of ${uri}" - } - return $installScript -} - -function Receive-DotnetInstallScript -{ - # param '$platform' is a hook to enable forcing download of a specific - # install script, generally it should not be used except in testing. - param ( $platform = "" ) - - # if $platform has been set, it has priority - # if it's not set to Windows or NonWindows, it will be ignored - if ( $platform -eq "Windows" ) { - $installScriptName = "dotnet-install.ps1" - } - elseif ( $platform -eq "NonWindows" ) { - $installScriptName = "dotnet-install.sh" - } - elseif ( ((Test-Path Variable:IsWindows) -and -not $IsWindows) ) { - # if the variable IsWindows exists and it is set to false - $installScriptName = "dotnet-install.sh" - } - else { # the default case - we're running on a Windows system - $installScriptName = "dotnet-install.ps1" - } - $uri = "https://dot.net/v1/${installScriptName}" - - $installScript = Receive-File -Uri $uri - return $installScript.FullName -} - function Get-DotnetExe { param ( $version = $script:wantedVersion ) @@ -730,7 +566,7 @@ try { $script:DotnetExe = Get-DotnetExe } catch { - Write-Warning "Could not find dotnet executable" + Write-Warning "The dotnet CLI was not found, please install it: https://aka.ms/dotnet-cli" } # Copies the built PSCompatibilityCollector module to the output destination for PSSA @@ -780,44 +616,11 @@ function Copy-CrossCompatibilityModule } } -# copy the manifest into the module if is present -function Copy-Manifest -{ - param ( [switch]$signed ) - if ( $signed ) { - $buildRoot = "signed" - } - else { - $buildRoot = "out" - } - $analyzerVersion = Get-AnalyzerVersion - # location where analyzer goes - # debugging - (Get-ChildItem -File -Recurse)|ForEach-Object {Write-Verbose -Verbose -Message $_} - $modBaseDir = [io.path]::Combine($projectRoot,${buildRoot},"${analyzerName}", $analyzerVersion) - # copy the manifest files - Push-Location $buildRoot - if ( Test-Path _manifest ) { - Copy-Item -Recurse -Path _manifest -Destination $modBaseDir -Verbose - } - else { - Write-Warning -Message "_manifest not found in $PWD" - } - Pop-Location -} - # creates the nuget package which can be used for publishing to the gallery function Start-CreatePackage { - [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseCompatibleCommands', '')] - param ( [switch]$signed ) try { - if ( $signed ) { - $buildRoot = "signed" - } - else { - $buildRoot = "out" - } + $buildRoot = "out" $repoName = [guid]::NewGuid().ToString() $nupkgDir = Join-Path $PSScriptRoot $buildRoot $null = Register-PSRepository -Name $repoName -InstallationPolicy Trusted -SourceLocation $nupkgDir