diff --git a/.gitignore b/.gitignore index f8fac8a21b..39d029fef0 100644 --- a/.gitignore +++ b/.gitignore @@ -101,3 +101,6 @@ StartupProfileData-NonInteractive # Ignore logfiles logfile/* + +# Ignore nuget.config because it is dynamically generated +nuget.config diff --git a/.pipelines/templates/insert-nuget-config-azfeed.yml b/.pipelines/templates/insert-nuget-config-azfeed.yml index e82102cbd7..1b1dc46afb 100644 --- a/.pipelines/templates/insert-nuget-config-azfeed.yml +++ b/.pipelines/templates/insert-nuget-config-azfeed.yml @@ -5,7 +5,10 @@ steps: - pwsh: | $configPath = "${env:NugetConfigDir}/nuget.config" Import-Module ${{ parameters.repoRoot }}/build.psm1 -Force - New-NugetConfigFile -NugetFeedUrl $(PowerShellCore_PublicPackages) -UserName $(AzDevopsFeedUserNameKVPAT) -ClearTextPAT $(mscodehubPackageReadPat) -FeedName AzDevOpsFeed -Destination "${env:NugetConfigDir}" + + $powerShellPublicPackages = [NugetPackageSource] @{Url = '$(PowerShellCore_PublicPackages)'; Name= 'AzDevOpsFeed'} + + New-NugetConfigFile -NugetPackageSource $powerShellPublicPackages -UserName $(AzDevopsFeedUserNameKVPAT) -ClearTextPAT $(mscodehubPackageReadPat) -Destination "${env:NugetConfigDir}" if(-not (Test-Path $configPath)) { throw "nuget.config is not created" @@ -20,8 +23,11 @@ steps: - pwsh: | $configPath = "${env:NugetConfigDir}/nuget.config" Import-Module ${{ parameters.repoRoot }}/build.psm1 -Force - New-NugetConfigFile -NugetFeedUrl $(PowerShellCore_PublicPackages) -UserName $(AzDevopsFeedUserNameKVPAT) -ClearTextPAT $(mscodehubPackageReadPat) -FeedName AzDevOpsFeed -Destination "${env:NugetConfigDir}" - if(-not (Test-Path $configPath)) + + $powerShellPublicPackages = [NugetPackageSource] @{Url = '$(PowerShellCore_PublicPackages)'; Name= 'AzDevOpsFeed'} + + New-NugetConfigFile -NugetPackageSource $powerShellPublicPackages -UserName $(AzDevopsFeedUserNameKVPAT) -ClearTextPAT $(mscodehubPackageReadPat) -Destination "${env:NugetConfigDir}" + if (-not (Test-Path $configPath)) { throw "nuget.config is not created" } diff --git a/.vsts-ci/windows/templates/windows-packaging.yml b/.vsts-ci/windows/templates/windows-packaging.yml index 3961214c86..84b02d14df 100644 --- a/.vsts-ci/windows/templates/windows-packaging.yml +++ b/.vsts-ci/windows/templates/windows-packaging.yml @@ -50,6 +50,13 @@ jobs: - template: /tools/releaseBuild/azureDevOps/templates/insert-nuget-config-azfeed.yml + - pwsh: | + Import-Module .\tools\ci.psm1 + Switch-PSNugetConfig -Source Public + displayName: Switch to public feeds + condition: succeeded() + workingDirectory: $(repoPath) + - pwsh: | Import-Module .\tools\ci.psm1 Invoke-CIInstall -SkipUser diff --git a/build.psm1 b/build.psm1 index 93e825f295..a3ed3fa669 100644 --- a/build.psm1 +++ b/build.psm1 @@ -307,6 +307,9 @@ function Start-PSBuild { # it's useful for development, to do a quick changes in the engine [switch]$SMAOnly, + # Use nuget.org instead of the PowerShell specific feed + [switch]$UseNuGetOrg, + # These runtimes must match those in project.json # We do not use ValidateScript since we want tab completion # If this parameter is not provided it will get determined automatically. @@ -362,6 +365,12 @@ function Start-PSBuild { } } + if ($UseNuGetOrg) { + Switch-PSNugetConfig -Source Public + } else { + Write-Verbose -Message "Using default feeds which are Microsoft, use `-UseNuGetOrg` to switch to Public feeds" -Verbose + } + function Stop-DevPowerShell { Get-Process pwsh* | Where-Object { @@ -718,6 +727,29 @@ Fix steps: } } +function Switch-PSNugetConfig { + param( + [ValidateSet('Public', 'Private')] + [string] $Source = 'Public' + ) + + if ( $Source -eq 'Public') { + $dotnetSdk = [NugetPackageSource] @{Url = 'https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet9/nuget/v2'; Name = 'dotnet' } + $gallery = [NugetPackageSource] @{Url = 'https://www.powershellgallery.com/api/v2/'; Name = 'psgallery' } + $nugetorg = [NugetPackageSource] @{Url = 'https://api.nuget.org/v3/index.json'; Name = 'nuget.org' } + + New-NugetConfigFile -NugetPackageSource $nugetorg, $dotnetSdk -Destination "$PSScriptRoot/" + New-NugetConfigFile -NugetPackageSource $gallery -Destination "$PSScriptRoot/src/Modules/" + } elseif ( $Source -eq 'Private') { + $powerShellPackages = [NugetPackageSource] @{Url = 'https://pkgs.dev.azure.com/powershell/PowerShell/_packaging/powershell/nuget/v3/index.json'; Name = 'powershell' } + + New-NugetConfigFile -NugetPackageSource $powerShellPackages -Destination "$PSScriptRoot/" + New-NugetConfigFile -NugetPackageSource $powerShellPackages -Destination "$PSScriptRoot/src/Modules/" + } else { + throw "Unknown source: $Source" + } +} + function Test-ShouldGenerateExperimentalFeatures { param( @@ -1284,9 +1316,14 @@ function Start-PSPester { [Parameter(ParameterSetName='Wait', Mandatory=$true, HelpMessage='Wait for the debugger to attach to PowerShell before Pester starts. Debug builds only!')] [switch]$Wait, - [switch]$SkipTestToolBuild + [switch]$SkipTestToolBuild, + [switch]$UseNuGetOrg ) + if ($UseNuGetOrg) { + Switch-PSNugetConfig -Source Public + } + if (-not (Get-Module -ListAvailable -Name $Pester -ErrorAction SilentlyContinue | Where-Object { $_.Version -ge "4.2" } )) { Restore-PSPester @@ -3394,36 +3431,67 @@ function New-TestPackage [System.IO.Compression.ZipFile]::CreateFromDirectory($packageRoot, $packagePath) } -function New-NugetConfigFile -{ +class NugetPackageSource { + [string] $Url + [string] $Name +} + +function New-NugetConfigFile { param( - [Parameter(Mandatory=$true)] [string] $NugetFeedUrl, - [Parameter(Mandatory=$true)] [string] $FeedName, - [Parameter(Mandatory=$true)] [string] $UserName, - [Parameter(Mandatory=$true)] [string] $ClearTextPAT, - [Parameter(Mandatory=$true)] [string] $Destination + [Parameter(Mandatory = $true, ParameterSetName ='user')] + [Parameter(Mandatory = $true, ParameterSetName ='nouser')] + [NugetPackageSource[]] $NugetPackageSource, + + [Parameter(Mandatory = $true)] [string] $Destination, + + [Parameter(Mandatory = $true, ParameterSetName = 'user')] + [string] $UserName, + + [Parameter(Mandatory = $true, ParameterSetName = 'user')] + [string] $ClearTextPAT ) - $nugetConfigTemplate = @' + $nugetConfigHeaderTemplate = @' +'@ + + $nugetPackageSourceTemplate = @' +'@ + $nugetPackageSourceFooterTemplate = @' +'@ + $nugetCredentialsTemplate = @' <[FEEDNAME]> +'@ + $nugetConfigFooterTemplate = @' '@ + $content = $nugetConfigHeaderTemplate - $content = $nugetConfigTemplate.Replace('[FEED]', $NugetFeedUrl).Replace('[FEEDNAME]', $FeedName).Replace('[USERNAME]', $UserName).Replace('[PASSWORD]', $ClearTextPAT) + [NugetPackageSource]$source = $null + foreach ($source in $NugetPackageSource) { + $content += $nugetPackageSourceTemplate.Replace('[FEED]', $source.Url).Replace('[FEEDNAME]', $source.Name) + } + + $content += $nugetPackageSourceFooterTemplate + + if ($UserName -or $ClearTextPAT) { + $content += $nugetCredentialsTemplate.Replace('[USERNAME]', $UserName).Replace('[PASSWORD]', $ClearTextPAT) + } + + $content += $nugetConfigFooterTemplate Set-Content -Path (Join-Path $Destination 'nuget.config') -Value $content -Force } diff --git a/docs/building/linux.md b/docs/building/linux.md index 87fce81843..d1ec01bd20 100644 --- a/docs/building/linux.md +++ b/docs/building/linux.md @@ -12,7 +12,7 @@ The build module works on a best-effort basis for other distributions. Using Git requires it to be set up correctly; refer to the [Working with the PowerShell Repository](../git/README.md), -[README](../../README.md), and [Contributing Guidelines](../../.github/CONTRIBUTING.md). +[Readme](../../README.md), and [Contributing Guidelines](../../.github/CONTRIBUTING.md). **This guide assumes that you have recursively cloned the PowerShell repository and `cd`ed into it.** @@ -63,7 +63,7 @@ If you have followed the toolchain setup section above, you should have PowerShe ```powershell Import-Module ./build.psm1 -Start-PSBuild +Start-PSBuild -UseNuGetOrg ``` Congratulations! If everything went right, PowerShell is now built. @@ -72,4 +72,4 @@ The `Start-PSBuild` script will output the location of the executable: `./src/powershell-unix/bin/Debug/net6.0/linux-x64/publish/pwsh`. You should now be running the PowerShell Core that you just built, if you run the above executable. -You can run our cross-platform Pester tests with `Start-PSPester`, and our xUnit tests with `Start-PSxUnit`. +You can run our cross-platform Pester tests with `Start-PSPester -UseNuGetOrg`, and our xUnit tests with `Start-PSxUnit`. diff --git a/docs/building/macos.md b/docs/building/macos.md index 63f1b4c9f8..4f15e3fb54 100644 --- a/docs/building/macos.md +++ b/docs/building/macos.md @@ -34,6 +34,6 @@ We cannot do this for you in the build module due to #[847][]. ## Build using our module -Start a PowerShell session by running `pwsh`, and then use `Start-PSBuild` from the module. +Start a PowerShell session by running `pwsh`, and then use `Start-PSBuild -UseNuGetOrg` from the module. After building, PowerShell will be at `./src/powershell-unix/bin/Debug/net6.0/osx-x64/publish/pwsh`. diff --git a/docs/building/windows-core.md b/docs/building/windows-core.md index 588ab0ed32..6dfd7e97bf 100644 --- a/docs/building/windows-core.md +++ b/docs/building/windows-core.md @@ -11,7 +11,7 @@ R2, though they should work anywhere the dependencies work. ### Git Setup Using Git requires it to be setup correctly; refer to the -[README](../../README.md) and +[Readme](../../README.md) and [Contributing Guidelines](../../.github/CONTRIBUTING.md). This guide assumes that you have recursively cloned the PowerShell repository and `cd`ed into it. @@ -56,7 +56,7 @@ We maintain a [PowerShell module](../../build.psm1) with the function `Start-PSB ```powershell Import-Module ./build.psm1 -Start-PSBuild -Clean -PSModuleRestore +Start-PSBuild -Clean -PSModuleRestore -UseNuGetOrg ``` Congratulations! If everything went right, PowerShell is now built and executable as `./src/powershell-win-core/bin/Debug/net6.0/win7-x64/publish/pwsh.exe`. @@ -77,7 +77,7 @@ You can run our cross-platform Pester tests with `Start-PSPester`. ```powershell Import-Module ./build.psm1 -Start-PSPester +Start-PSPester -UseNuGetOrg ``` ## Building in Visual Studio diff --git a/nuget.config b/nuget.config index 09cb25b421..fc6b5ff4e6 100644 --- a/nuget.config +++ b/nuget.config @@ -2,8 +2,7 @@ - - + diff --git a/src/Modules/nuget.config b/src/Modules/nuget.config index b0fc73009d..fc6b5ff4e6 100644 --- a/src/Modules/nuget.config +++ b/src/Modules/nuget.config @@ -2,7 +2,7 @@ - + diff --git a/test/hosting/NuGet.Config b/test/hosting/NuGet.Config deleted file mode 100644 index 765346e534..0000000000 --- a/test/hosting/NuGet.Config +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/test/perf/nuget.config b/test/perf/nuget.config deleted file mode 100644 index e8b7ac6770..0000000000 --- a/test/perf/nuget.config +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/test/tools/NamedPipeConnection/nuget.config b/test/tools/NamedPipeConnection/nuget.config deleted file mode 100644 index 6548586147..0000000000 --- a/test/tools/NamedPipeConnection/nuget.config +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - diff --git a/tools/ci.psm1 b/tools/ci.psm1 index 89c34362d1..73c6cb41e8 100644 --- a/tools/ci.psm1 +++ b/tools/ci.psm1 @@ -105,7 +105,7 @@ function Invoke-CIBuild Start-PSBuild -Configuration 'CodeCoverage' -PSModuleRestore -CI -ReleaseTag $releaseTag } - Start-PSBuild -PSModuleRestore -Configuration 'Release' -CI -ReleaseTag $releaseTag + Start-PSBuild -PSModuleRestore -Configuration 'Release' -CI -ReleaseTag $releaseTag -UseNuGetOrg Save-PSOptions $options = (Get-PSOptions) @@ -128,6 +128,10 @@ function Invoke-CIInstall [switch] $SkipUser ) + + # Switch to public sources in CI + Switch-PSNugetConfig -Source Public + # Make sure we have all the tags Sync-PSTags -AddRemoteIfMissing @@ -480,6 +484,9 @@ function Invoke-CIFinish [string[]] $Stage = ('Build','Package') ) + # Switch to public sources in CI + Switch-PSNugetConfig -Source Public + if ($PSEdition -eq 'Core' -and ($IsLinux -or $IsMacOS) -and $Stage -contains 'Build') { return New-LinuxPackage }