Skip to content

Commit b6286af

Browse files
authored
Use parameter sets to determine filter expression, exit on failure of dotnet build (#54031)
* Use parameter sets to determine filter expression, exit on failure of dotnet build * Re-add -ErrorAction SilentlyContinue * Use runwithdevopslogging.ps1 * Parameter attribute * Remove exit logic * Use Invoke-LoggedMsbuildCommand directly
1 parent 5759809 commit b6286af

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

eng/scripts/Export-API.ps1

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
[CmdletBinding()]
22
param (
3-
[Parameter(Position=0)]
3+
[Parameter(Position=0, Mandatory=$true, ParameterSetName='ServiceDirectory')]
44
[string] $ServiceDirectory,
5+
56
[string] $SDKType = "all",
67
[switch] $SpellCheckPublicApiSurface,
8+
9+
[Parameter(Mandatory=$true, ParameterSetName='PackagePath')]
710
[string] $PackagePath,
11+
[Parameter(Mandatory=$true, ParameterSetName='PackagePath')]
812
[string] $SdkRepoPath
913
)
1014

@@ -13,10 +17,14 @@ if ($SpellCheckPublicApiSurface -and -not (Get-Command 'npx')) {
1317
exit 1
1418
}
1519

16-
$relativePackagePath = if ($PackagePath) {
17-
Resolve-Path -Relative -RelativeBasePath (Join-Path $SdkRepoPath "sdk") -Path $PackagePath
18-
} else {
19-
$ServiceDirectory
20+
. $PSScriptRoot/../common/scripts/Helpers/CommandInvocation-Helpers.ps1
21+
22+
$relativePackagePath = $ServiceDirectory
23+
$apiListingFilesFilter = "$PSScriptRoot/../../sdk/$ServiceDirectory/*/api/*.cs"
24+
25+
if ($PSCmdlet.ParameterSetName -eq 'PackagePath') {
26+
$relativePackagePath = Resolve-Path -Relative -RelativeBasePath (Join-Path $SdkRepoPath "sdk") -Path $PackagePath
27+
$apiListingFilesFilter = "$PSScriptRoot/../../sdk/$relativePackagePath/api/*.cs"
2028
}
2129

2230
$servicesProj = Resolve-Path "$PSScriptRoot/../service.proj"
@@ -25,11 +33,11 @@ $debugLogging = $env:SYSTEM_DEBUG -eq "true"
2533
$logsFolder = $env:BUILD_ARTIFACTSTAGINGDIRECTORY
2634
$diagnosticArguments = ($debugLogging -and $logsFolder) ? "/binarylogger:$logsFolder/exportapi.binlog" : ""
2735

28-
dotnet build /t:ExportApi /p:RunApiCompat=false /p:InheritDocEnabled=false /p:GeneratePackageOnBuild=false /p:Configuration=Release /p:IncludeSamples=false /p:IncludePerf=false /p:IncludeStress=false /p:IncludeTests=false /p:Scope="$relativePackagePath" /p:SDKType=$SDKType /restore $servicesProj $diagnosticArguments
36+
Invoke-LoggedMsbuildCommand "dotnet build /t:ExportApi /p:RunApiCompat=false /p:InheritDocEnabled=false /p:GeneratePackageOnBuild=false /p:Configuration=Release /p:IncludeSamples=false /p:IncludePerf=false /p:IncludeStress=false /p:IncludeTests=false /p:Scope=`"$relativePackagePath`" /p:SDKType=$SDKType /restore $servicesProj $diagnosticArguments"
2937

3038
# Normalize line endings to LF in generated API listing files
3139
Write-Host "Normalizing line endings in API listing files"
32-
$apiListingFiles = Get-ChildItem -Path "$PSScriptRoot/../../sdk/$relativePackagePath/*/api/*.cs" -ErrorAction SilentlyContinue
40+
$apiListingFiles = Get-ChildItem -Path $apiListingFilesFilter -ErrorAction SilentlyContinue
3341
foreach ($file in $apiListingFiles) {
3442
$content = Get-Content -Path $file.FullName -Raw
3543
if ($content) {

0 commit comments

Comments
 (0)