Update infrastructure to consume private builds from .NET (#13427)

This commit is contained in:
Aditya Patwardhan 2020-08-13 14:52:00 -07:00 committed by GitHub
parent 112f1b97a3
commit c20433a4a9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 96 additions and 25 deletions

View file

@ -303,7 +303,8 @@ function Start-PSBuild {
[ValidatePattern("^v\d+\.\d+\.\d+(-\w+(\.\d+)?)?$")]
[ValidateNotNullOrEmpty()]
[string]$ReleaseTag,
[switch]$Detailed
[switch]$Detailed,
[switch]$InteractiveAuth
)
if ($PSCmdlet.ParameterSetName -eq "Default" -and !$NoPSModuleRestore)
@ -426,7 +427,7 @@ Fix steps:
}
# handle Restore
Restore-PSPackage -Options $Options -Force:$Restore
Restore-PSPackage -Options $Options -Force:$Restore -InteractiveAuth:$InteractiveAuth
# handle ResGen
# Heuristic to run ResGen on the fresh machine
@ -618,7 +619,9 @@ function Restore-PSPackage
[Parameter()]
$Options = (Get-PSOptions -DefaultToNew),
[switch] $Force
[switch] $Force,
[switch] $InteractiveAuth
)
if (-not $ProjectDirs)
@ -654,6 +657,10 @@ function Restore-PSPackage
$RestoreArguments += "quiet"
}
if ($InteractiveAuth) {
$RestoreArguments += "--interactive"
}
$ProjectDirs | ForEach-Object {
$project = $_
Write-Log -message "Run dotnet restore $project $RestoreArguments"
@ -1639,7 +1646,9 @@ function Install-Dotnet {
[string]$Channel = $dotnetCLIChannel,
[string]$Version = $dotnetCLIRequiredVersion,
[switch]$NoSudo,
[string]$InstallDir
[string]$InstallDir,
[string]$AzureFeed,
[string]$FeedCredential
)
# This allows sudo install to be optional; needed when running in containers / as root
@ -1674,33 +1683,57 @@ function Install-Dotnet {
Start-NativeExecution {
& $curl -sO $installObtainUrl/$installScript
if (-not $InstallDir) {
bash ./$installScript -c $Channel -v $Version
} else {
bash ./$installScript -c $Channel -v $Version -i $InstallDir
$bashArgs = @("./$installScript", '-c', $Channel, '-v', $Version)
if ($InstallDir) {
$bashArgs += @('-i', $InstallDir)
}
if ($AzureFeed) {
$bashArgs += @('-AzureFeed', $AzureFeed, '-FeedCredential', $FeedCredential)
}
bash @bashArgs
}
} elseif ($environment.IsWindows) {
Remove-Item -ErrorAction SilentlyContinue -Recurse -Force ~\AppData\Local\Microsoft\dotnet
$installScript = "dotnet-install.ps1"
Invoke-WebRequest -Uri $installObtainUrl/$installScript -OutFile $installScript
if (-not $environment.IsCoreCLR) {
if (-not $InstallDir) {
& ./$installScript -Channel $Channel -Version $Version
} else {
& ./$installScript -Channel $Channel -Version $Version -InstallDir $InstallDir
$installArgs = @{
Channel = $Channel
Version = $Version
}
} else {
if ($InstallDir) {
$installArgs += @{ InstallDir = $InstallDir }
}
if ($AzureFeed) {
$installArgs += @{
AzureFeed = $AzureFeed
$FeedCredential = $FeedCredential
}
}
& ./$installScript @installArgs
}
else {
# dotnet-install.ps1 uses APIs that are not supported in .NET Core, so we run it with Windows PowerShell
$fullPSPath = Join-Path -Path $env:windir -ChildPath "System32\WindowsPowerShell\v1.0\powershell.exe"
$fullDotnetInstallPath = Join-Path -Path $PWD.Path -ChildPath $installScript
Start-NativeExecution {
if (-not $InstallDir) {
& $fullPSPath -NoLogo -NoProfile -File $fullDotnetInstallPath -Channel $Channel -Version $Version
} else {
& $fullPSPath -NoLogo -NoProfile -File $fullDotnetInstallPath -Channel $Channel -Version $Version -InstallDir $InstallDir
$psArgs = @('-NoLogo', '-NoProfile', '-File', $fullDotnetInstallPath, '-Channel', $Channel, '-Version', $Version)
if ($InstallDir) {
$psArgs += @('-InstallDir', $InstallDir)
}
if ($AzureFeed) {
$psArgs += @('-AzureFeed', $AzureFeed, '-FeedCredential', $FeedCredential)
}
& $fullPSPath @psArgs
}
}
}

View file

@ -7,7 +7,16 @@ param (
[string]$SDKVersionOverride,
[Parameter()]
[switch]$UpdateMSIPackaging
[switch]$UpdateMSIPackaging,
[Parameter()]
[string]$RuntimeSourceFeed,
[Parameter()]
[string]$RuntimeSourceFeedKey,
[Parameter()]
[switch]$InteractiveAuth
)
<#
@ -130,6 +139,14 @@ function Update-CsprojFile([string] $path, $values) {
}
function Get-DotnetUpdate {
if ($SDKVersionOverride) {
return @{
ShouldUpdate = $true
NewVersion = $SDKVersionOverride
Message = $null
}
}
try {
$dotnetMetadataPath = "$PSScriptRoot/../DotnetRuntimeMetadata.json"
$nextChannel = (Get-Content $dotnetMetadataPath -Raw | ConvertFrom-Json).sdk.nextChannel
@ -180,17 +197,38 @@ if ($dotnetUpdate.ShouldUpdate) {
Find-Dotnet
if (-not (Get-PackageSource -Name 'dotnet5' -ErrorAction SilentlyContinue)) {
$nugetFeed = ([xml](Get-Content .\nuget.config -Raw)).Configuration.packagesources.add | Where-Object { $_.Key -eq 'dotnet5' } | Select-Object -ExpandProperty Value
Register-PackageSource -Name 'dotnet5' -Location $nugetFeed -ProviderName NuGet
Write-Verbose -Message "Register new package source 'dotnet5'" -verbose
$addDotnet5Source = (-not (Get-PackageSource -Name 'dotnet5' -ErrorAction SilentlyContinue))
$addDotnet5InternalSource = (-not (Get-PackageSource -Name 'dotnet5-internal' -ErrorAction SilentlyContinue))
if ($addDotnet5Source -or $addDotnet5InternalSource) {
$nugetFileSources = ([xml](Get-Content .\nuget.config -Raw)).Configuration.packagesources.add
if ($addDotnet5Source) {
$dotnet5Feed = $nugetFileSources | Where-Object { $_.Key -eq 'dotnet5' } | Select-Object -ExpandProperty Value
Register-PackageSource -Name 'dotnet5' -Location $dotnet5Feed -ProviderName NuGet
Write-Verbose -Message "Register new package source 'dotnet5'" -verbose
}
if ($addDotnet5InternalSource -and $InteractiveAuth) {
# This NuGet feed is for internal to Microsoft use only.
$dotnet5InternalFeed = 'https://pkgs.dev.azure.com/dnceng/internal/_packaging/dotnet5-internal/nuget/v3/index.json'
$updatedNugetFile = (Get-Content .\nuget.config -Raw) -replace "</packageSources>", " <add key=`"dotnet5-internal`" value=`"$dotnet5InternalFeed`" />`r`n </packageSources>"
$updatedNugetFile | Out-File .\nuget.config -Force
Register-PackageSource -Name 'dotnet5-internal' -Location $dotnet5InternalFeed -ProviderName NuGet
Write-Verbose -Message "Register new package source 'dotnet5-internal'" -verbose
}
}
## Install latest version from the channel
$sdkVersion = if ($SDKVersionOverride) { $SDKVersionOverride } else { $dotnetUpdate.NewVersion }
Install-Dotnet -Channel "$Channel" -Version $sdkVersion
if (-not $RuntimeSourceFeed) {
Install-Dotnet -Channel "$Channel" -Version $sdkVersion
}
else {
Install-Dotnet -Channel "$Channel" -Version $sdkVersion -AzureFeed $RuntimeSourceFeed -FeedCredential $RuntimeSourceFeedKey
}
Write-Verbose -Message "Installing .NET SDK completed." -Verbose
@ -224,7 +262,7 @@ if ($dotnetUpdate.ShouldUpdate) {
Import-Module "$PSScriptRoot/../build.psm1" -Force
Import-Module "$PSScriptRoot/packaging" -Force
Start-PSBootstrap -Package
Start-PSBuild -Clean -Configuration Release -CrossGen
Start-PSBuild -Clean -Configuration Release -CrossGen -InteractiveAuth:$InteractiveAuth
try {
Start-PSPackage -Type msi -SkipReleaseChecks -InformationVariable wxsData