Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use compliant build environment for release build. #1776

Merged
merged 6 commits into from
Feb 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .ci/releaseBuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ stages:
displayName: Build
pool:
name: PowerShell1ES # was Package ES CodeHub Lab E
demands:
- ImageOverride -equals PSMMS2019-Secure
jobs:
- job: Build_Job
displayName: Build Microsoft.PowerShell.ScriptAnalyzer
Expand Down
40 changes: 27 additions & 13 deletions build.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ function Start-ScriptAnalyzerBuild
# install the proper version
Install-Dotnet
if ( -not (Test-SuitableDotnet) ) {
$requiredVersion = Get-GlobalJsonSdkVersion
$requiredVersion = $script:wantedVersion
$foundVersion = Get-InstalledCLIVersion
Write-Warning "No suitable dotnet CLI found, requires version '$requiredVersion' found only '$foundVersion'"
}
Expand All @@ -184,6 +184,7 @@ function Start-ScriptAnalyzerBuild
{
# Build all the versions of the analyzer
foreach ($psVersion in 3, 4, 5, 7) {
Write-Verbose -Verbose -Message "Configuration: $Configuration PSVersion: $psVersion"
Start-ScriptAnalyzerBuild -Configuration $Configuration -PSVersion $psVersion -Verbose:$verboseWanted
}
if ( $Catalog ) {
Expand Down Expand Up @@ -271,12 +272,17 @@ function Start-ScriptAnalyzerBuild
$dotnetArgs += "${PSScriptRoot}\bin\${buildConfiguration}\${framework}"
}
$buildOutput = & $script:DotnetExe $dotnetArgs 2>&1
if ( $LASTEXITCODE -ne 0 ) { throw "$buildOutput" }
if ( $LASTEXITCODE -ne 0 ) {
Write-Verbose -Verbose -Message "dotnet is $(${script:DotnetExe}.Source)"
$dotnetArgs | Foreach-Object {"dotnetArg: $_"} | Write-Verbose -Verbose
Get-PSCallStack | Write-Verbose -Verbose
throw $buildOutput
}
Write-Verbose -Verbose:$verboseWanted -message "$buildOutput"
}
catch {
Write-Warning $_
Write-Error "Failure to build for PSVersion '$PSVersion' using framework '$framework' and configuration '$config'"
$_.TargetObject | Write-Warning
Write-Error "Failure to build for PSVersion '$PSVersion' using framework '$framework' and configuration '$buildConfiguration'"
throw
}
finally {
Expand Down Expand Up @@ -545,7 +551,7 @@ function ConvertTo-PortableVersion {
function Test-SuitableDotnet {
param (
$availableVersions = $( Get-InstalledCliVersion),
$requiredVersion = $( Get-GlobalJsonSdkVersion )
$requiredVersion = $script:wantedVersion
)

if ( $requiredVersion -is [String] -or $requiredVersion -is [Version] ) {
Expand Down Expand Up @@ -610,7 +616,7 @@ function Get-InstalledCLIVersion {
function Test-DotnetInstallation
{
param (
$requestedVersion = $( Get-GlobalJsonSdkVersion ),
$requestedVersion = $script:wantedVersion,
$installedVersions = $( Get-InstalledCLIVersion )
)
return (Test-SuitableDotnet -availableVersions $installedVersions -requiredVersion $requestedVersion )
Expand Down Expand Up @@ -671,7 +677,8 @@ function Receive-DotnetInstallScript

function Get-DotnetExe
{
$discoveredDotnet = Get-Command -CommandType Application dotnet -ErrorAction SilentlyContinu
param ( $version = $script:wantedVersion )
$discoveredDotnet = Get-Command -CommandType Application dotnet -ErrorAction SilentlyContinue -All
if ( $discoveredDotnet ) {
# it's possible that there are multiples. Take the highest version we find
# the problem is that invoking dotnet on a version which is lower than the specified
Expand All @@ -682,13 +689,17 @@ function Get-DotnetExe
# file points to a version of the sdk which is *not* installed. However, the format of the new list
# with --version has a couple of spaces at the beginning of the line, so we need to be resilient
# against that.
$latestDotnet = $discoveredDotNet |
Where-Object { try { & $_ --version 2>$null } catch { } } |
Sort-Object { $pv = ConvertTo-PortableVersion (& $_ --version 2>$null| %{$_.Trim().Split()[0]}); "$pv" } |
$properDotnet = $discoveredDotNet |
Where-Object {
& $_ --list-sdks |
Where-Object {
$_ -match $version
}
} |
Select-Object -Last 1
if ( $latestDotnet ) {
$script:DotnetExe = $latestDotnet
return $latestDotnet
if ( $properDotnet ) {
$script:DotnetExe = $properDotnet
return $properDotnet
}
}
# it's not in the path, try harder to find it by checking some usual places
Expand All @@ -714,6 +725,9 @@ function Get-DotnetExe
}

try {
# The version we want based on the global.JSON file
# suck this before getting the dotnet exe
$script:wantedVersion = Get-GlobalJsonSdkVersion -Raw
$script:DotnetExe = Get-DotnetExe
}
catch {
Expand Down