add a script to check nuget config for PRs (#2042)

This commit is contained in:
Tian L 2023-08-15 15:23:02 +08:00 committed by GitHub
commit 0b9b2077eb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 0 deletions

View file

@ -37,6 +37,12 @@ jobs:
- checkout: self
fetchDepth: 1
- ${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
- powershell: |
$(Build.SourcesDirectory)\build\scripts\VerifyNugetConfig.ps1 -FilePath "$(Build.SourcesDirectory)\nuget.config"
displayName: Verify nuget config
failOnStderr: true
- ${{ if eq(parameters.isReleaseBuild, true) }}:
- task: UniversalPackages@0
displayName: Download internals package

View file

@ -0,0 +1,28 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
<#
.SYNOPSIS
Verify the specified nuget.config. Throw to fail the pipeline if the config is ill-formed.
.PARAMETER FilePath
The path pointing to the nuget.config file to be verified by this script.
.EXAMPLE
VerifyNugetConfig -FilePath .\nuget.config
#>
param([Parameter(Mandatory)][string]$FilePath)
$doc = [XML](Get-Content $FilePath)
$sources = (Select-Xml $doc -XPath "//configuration/packageSources").Node
$count = 0
foreach($src in $sources.ChildNodes){
if ($src.Name -eq "add"){
++$count
}
elseif ($src.Name -eq "clear"){
$count = 0
}
}
if ($count -gt 1){
throw "Adding multiple package sources is not allowed in nuget.config."
}