diff options
author | dotnet-maestro[bot] <42748379+dotnet-maestro[bot]@users.noreply.github.com> | 2019-11-19 18:47:57 +0300 |
---|---|---|
committer | Alexander Köplinger <alex.koeplinger@outlook.com> | 2019-11-19 18:47:57 +0300 |
commit | a6db160596bb987af11fb2844d51c9a3a7c73133 (patch) | |
tree | a8e9a349963b64d74819a177bdf359e986fccd16 /eng/common/SetupNugetSources.ps1 | |
parent | 0c3ffb9cc9839a99b71e1c8dc2e85d462820a31c (diff) |
[master] Update dependencies from dotnet/arcade dotnet/core-setup dotnet/corefx (#17690)
* Update dependencies from https://github.com/dotnet/arcade build 20191102.1
- Microsoft.DotNet.Arcade.Sdk - 5.0.0-beta.19552.1
- Microsoft.DotNet.Helix.Sdk - 5.0.0-beta.19552.1
* Update dependencies from https://github.com/dotnet/core-setup build 20191104.1
- Microsoft.NETCore.App - 5.0.0-alpha.1.19554.1
* Update dependencies from https://github.com/dotnet/corefx build 20191103.8
- Microsoft.Private.CoreFx.NETCoreApp - 5.0.0-alpha.1.19553.8
* Update dependencies from https://github.com/dotnet/arcade build 20191108.11
- Microsoft.DotNet.Arcade.Sdk - 5.0.0-beta.19558.11
- Microsoft.DotNet.Helix.Sdk - 5.0.0-beta.19558.11
* Update dependencies from https://github.com/dotnet/core-setup build 20191109.5
- Microsoft.NETCore.App - 5.0.0-alpha.1.19559.5
* Update dependencies from https://github.com/dotnet/corefx build 20191109.6
- Microsoft.Private.CoreFx.NETCoreApp - 5.0.0-alpha.1.19559.6
* Update dependencies from https://github.com/dotnet/arcade build 20191117.2
- Microsoft.DotNet.Arcade.Sdk - 5.0.0-beta.19567.2
- Microsoft.DotNet.Helix.Sdk - 5.0.0-beta.19567.2
* Update dependencies from https://github.com/dotnet/core-setup build 20191114.1
- Microsoft.NETCore.App - 5.0.0-alpha.1.19564.1
* Update dependencies from https://github.com/dotnet/corefx build 20191113.6
- Microsoft.Private.CoreFx.NETCoreApp - 5.0.0-alpha.1.19563.6
* Use NETCoreApp version 5.0.0-alpha.1.19563.3
Later versions have an issue and the new dotnet/runtime assets aren't ready yet.
* Disable failing tests
* Fix merge error
Diffstat (limited to 'eng/common/SetupNugetSources.ps1')
-rw-r--r-- | eng/common/SetupNugetSources.ps1 | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/eng/common/SetupNugetSources.ps1 b/eng/common/SetupNugetSources.ps1 new file mode 100644 index 00000000000..2cb40c29474 --- /dev/null +++ b/eng/common/SetupNugetSources.ps1 @@ -0,0 +1,127 @@ +# This file is a temporary workaround for internal builds to be able to restore from private AzDO feeds. +# This file should be removed as part of this issue: https://github.com/dotnet/arcade/issues/4080 +# +# What the script does is iterate over all package sources in the pointed NuGet.config and add a credential entry +# under <packageSourceCredentials> for each Maestro managed private feed. Two additional credential +# entries are also added for the two private static internal feeds: dotnet3-internal and dotnet3-internal-transport. +# +# This script needs to be called in every job that will restore packages and which the base repo has +# private AzDO feeds in the NuGet.config. +# +# See example YAML call for this script below. Note the use of the variable `$(dn-bot-dnceng-artifact-feeds-rw)` +# from the AzureDevOps-Artifact-Feeds-Pats variable group. +# +# - task: PowerShell@2 +# displayName: Setup Private Feeds Credentials +# condition: eq(variables['Agent.OS'], 'Windows_NT') +# inputs: +# filePath: $(Build.SourcesDirectory)/eng/common/SetupNugetSources.ps1 +# arguments: -ConfigFile ${Env:BUILD_SOURCESDIRECTORY}/NuGet.config -Password $Env:Token +# env: +# Token: $(dn-bot-dnceng-artifact-feeds-rw) + +[CmdletBinding()] +param ( + [Parameter(Mandatory = $true)][string]$ConfigFile, + [Parameter(Mandatory = $true)][string]$Password +) + +$ErrorActionPreference = "Stop" +Set-StrictMode -Version 2.0 +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 + +. $PSScriptRoot\tools.ps1 + +# Add source entry to PackageSources +function AddPackageSource($sources, $SourceName, $SourceEndPoint, $creds, $Username, $Password) { + $packageSource = $sources.SelectSingleNode("add[@key='$SourceName']") + + if ($packageSource -eq $null) + { + $packageSource = $doc.CreateElement("add") + $packageSource.SetAttribute("key", $SourceName) + $packageSource.SetAttribute("value", $SourceEndPoint) + $sources.AppendChild($packageSource) | Out-Null + } + else { + Write-Host "Package source $SourceName already present." + } + + AddCredential -Creds $creds -Source $SourceName -Username $Username -Password $Password +} + +# Add a credential node for the specified source +function AddCredential($creds, $source, $username, $password) { + # Looks for credential configuration for the given SourceName. Create it if none is found. + $sourceElement = $creds.SelectSingleNode($Source) + if ($sourceElement -eq $null) + { + $sourceElement = $doc.CreateElement($Source) + $creds.AppendChild($sourceElement) | Out-Null + } + + # Add the <Username> node to the credential if none is found. + $usernameElement = $sourceElement.SelectSingleNode("add[@key='Username']") + if ($usernameElement -eq $null) + { + $usernameElement = $doc.CreateElement("add") + $usernameElement.SetAttribute("key", "Username") + $sourceElement.AppendChild($usernameElement) | Out-Null + } + $usernameElement.SetAttribute("value", $Username) + + # Add the <ClearTextPassword> to the credential if none is found. + # Add it as a clear text because there is no support for encrypted ones in non-windows .Net SDKs. + # -> https://github.com/NuGet/Home/issues/5526 + $passwordElement = $sourceElement.SelectSingleNode("add[@key='ClearTextPassword']") + if ($passwordElement -eq $null) + { + $passwordElement = $doc.CreateElement("add") + $passwordElement.SetAttribute("key", "ClearTextPassword") + $sourceElement.AppendChild($passwordElement) | Out-Null + } + $passwordElement.SetAttribute("value", $Password) +} + +function InsertMaestroPrivateFeedCredentials($Sources, $Creds, $Password) { + $maestroPrivateSources = $Sources.SelectNodes("add[contains(@key,'darc-int')]") + + Write-Host "Inserting credentials for $($maestroPrivateSources.Count) Maestro's private feeds." + + ForEach ($PackageSource in $maestroPrivateSources) { + Write-Host "`tInserting credential for Maestro's feed:" $PackageSource.Key + AddCredential -Creds $creds -Source $PackageSource.Key -Username $Username -Password $Password + } +} + +if (!(Test-Path $ConfigFile -PathType Leaf)) { + Write-Host "Couldn't find the file NuGet config file: $ConfigFile" + ExitWithExitCode 1 +} + +# Load NuGet.config +$doc = New-Object System.Xml.XmlDocument +$filename = (Get-Item $ConfigFile).FullName +$doc.Load($filename) + +# Get reference to <PackageSources> or create one if none exist already +$sources = $doc.DocumentElement.SelectSingleNode("packageSources") +if ($sources -eq $null) { + $sources = $doc.CreateElement("packageSources") + $doc.DocumentElement.AppendChild($sources) | Out-Null +} + +# Looks for a <PackageSourceCredentials> node. Create it if none is found. +$creds = $doc.DocumentElement.SelectSingleNode("packageSourceCredentials") +if ($creds -eq $null) { + $creds = $doc.CreateElement("packageSourceCredentials") + $doc.DocumentElement.AppendChild($creds) | Out-Null +} + +# Insert credential nodes for Maestro's private feeds +InsertMaestroPrivateFeedCredentials -Sources $sources -Creds $creds -Password $Password + +AddPackageSource -Sources $sources -SourceName "dotnet3-internal" -SourceEndPoint "https://pkgs.dev.azure.com/dnceng/_packaging/dotnet3-internal/nuget/v2" -Creds $creds -Username "dn-bot" -Password $Password +AddPackageSource -Sources $sources -SourceName "dotnet3-internal-transport" -SourceEndPoint "https://pkgs.dev.azure.com/dnceng/_packaging/dotnet3-internal-transport/nuget/v2" -Creds $creds -Username "dn-bot" -Password $Password + +$doc.Save($filename) |