diff --git a/packages/http-client-csharp/eng/pipeline/templates/ci-stages.yml b/packages/http-client-csharp/eng/pipeline/templates/ci-stages.yml index 5755b96656b..874eef4f27b 100644 --- a/packages/http-client-csharp/eng/pipeline/templates/ci-stages.yml +++ b/packages/http-client-csharp/eng/pipeline/templates/ci-stages.yml @@ -5,6 +5,10 @@ parameters: - name: DependsOn type: object default: [] + # Spector coverage only runs in the Linux test job for this Node version, which is also the job that uploads coverage. + - name: PrimaryNodeVersion + type: string + default: "24.x" stages: - template: /eng/emitters/pipelines/templates/stages/emitter-stages.yml @@ -37,25 +41,28 @@ stages: TestArguments: -GenerationChecks Condition: ${{ parameters.Condition }} DependsOn: ${{ parameters.DependsOn }} + PrimaryNodeVersion: ${{ parameters.PrimaryNodeVersion }} LanguageShortName: "csharp" AdditionalInitializeSteps: - - task: UseDotNet@2 - inputs: - displayName: "Install .NET 8" - performMultiLevelLookup: true - useGlobalJson: false - version: 8.x - workingDirectory: $(Build.SourcesDirectory)/packages/http-client-csharp - - task: UseDotNet@2 + - pwsh: | + Write-Host "##vso[task.setvariable variable=NUGET_PACKAGES]$(Pipeline.Workspace)/.nuget/packages" + Write-Host "##vso[task.setvariable variable=DOTNET_NOLOGO]true" + Write-Host "##vso[task.setvariable variable=DOTNET_CLI_TELEMETRY_OPTOUT]true" + Write-Host "##vso[task.setvariable variable=DOTNET_SKIP_FIRST_TIME_EXPERIENCE]true" + $coverageJob = "Test_linux_${{ split(parameters.PrimaryNodeVersion, '.')[0] }}" + if ("$(System.PhaseName)" -eq $coverageJob -or "$(Agent.JobName)" -eq $coverageJob) { + Write-Host "##vso[task.setvariable variable=CSHARP_RUN_SPECTOR_COVERAGE]true" + } + displayName: "Configure NuGet cache and .NET CLI" + - task: Cache@2 + displayName: "Cache NuGet packages" inputs: - displayName: "Install .NET 9" - performMultiLevelLookup: true - useGlobalJson: false - version: 9.x - workingDirectory: $(Build.SourcesDirectory)/packages/http-client-csharp + key: '"nuget" | "$(Agent.OS)" | eng/nuget.config | packages/http-client-csharp/generator/Packages.Data.props | packages/http-client-csharp/generator/Directory.Build.targets | packages/http-client-csharp/**/*.csproj, !packages/http-client-csharp/node_modules/**' + restoreKeys: | + "nuget" | "$(Agent.OS)" + path: $(NUGET_PACKAGES) - task: UseDotNet@2 + displayName: "Install .NET 10" inputs: - displayName: "Install .NET 10" - performMultiLevelLookup: true useGlobalJson: true workingDirectory: $(Build.SourcesDirectory)/packages/http-client-csharp diff --git a/packages/http-client-csharp/eng/scripts/Generate.ps1 b/packages/http-client-csharp/eng/scripts/Generate.ps1 index 895bc96690f..c96dddfc70c 100644 --- a/packages/http-client-csharp/eng/scripts/Generate.ps1 +++ b/packages/http-client-csharp/eng/scripts/Generate.ps1 @@ -2,7 +2,9 @@ param( $filter, [bool]$Stubbed = $true, - [bool]$LaunchOnly = $false + [bool]$LaunchOnly = $false, + # Maximum number of concurrent generation jobs; 0 uses the default of Invoke-ParallelGeneration. + [int]$GenerationParallelism = 0 ) Import-Module "$PSScriptRoot\Generation.psm1" -DisableNameChecking -Force; @@ -14,30 +16,18 @@ $totalStopwatch = [System.Diagnostics.Stopwatch]::StartNew() $packageRoot = Resolve-Path (Join-Path $PSScriptRoot '..' '..') $solutionDir = Join-Path $packageRoot 'generator' +$generationJobs = @() +$generateSampleTypeSpec = (-not $LaunchOnly) -and ($null -eq $filter -or $filter -eq "Sample-TypeSpec") +$SampleTypeSpecTestProject = Join-Path $packageRoot 'generator' 'TestProjects' 'Local' "Sample-TypeSpec" + if (-not $LaunchOnly) { Refresh-Build - if ($null -eq $filter -or $filter -eq "Sample-TypeSpec") { - - Write-Host "Generating SampleTypeSpec" -ForegroundColor Cyan - $testProjectsLocalDir = Join-Path $packageRoot 'generator' 'TestProjects' 'Local' - - $SampleTypeSpecTestProject = Join-Path $testProjectsLocalDir "Sample-TypeSpec" - $SampleTypeSpecTestProject = $SampleTypeSpecTestProject - - Invoke (Get-TspCommand "$SampleTypeSpecTestProject/Sample-TypeSpec.tsp" $SampleTypeSpecTestProject) - - # exit if the generation failed - if ($LASTEXITCODE -ne 0) { - exit $LASTEXITCODE - } - - Write-Host "Building SampleTypeSpec" -ForegroundColor Cyan - Invoke "dotnet build $packageRoot/generator/TestProjects/Local/Sample-TypeSpec/src/SampleTypeSpec.csproj" - - # exit if the generation failed - if ($LASTEXITCODE -ne 0) { - exit $LASTEXITCODE + if ($generateSampleTypeSpec) { + $generationJobs += @{ + Name = "Sample-TypeSpec" + OutputDir = $SampleTypeSpecTestProject + Commands = @(Get-TspCommand "$SampleTypeSpecTestProject/Sample-TypeSpec.tsp" $SampleTypeSpecTestProject) } } } @@ -62,38 +52,41 @@ foreach ($specFile in Get-Sorted-Specs) { New-Item -ItemType Directory -Path $generationDir | Out-Null } - Write-Host "Generating $subPath" -ForegroundColor Cyan - - if ($folders.Contains("versioning")) { - Generate-Versioning (Split-Path $specFile) $generationDir -generateStub $stubbed + if ($folders.Contains("versioning") -or $folders.Contains("srv-driven")) { $spectorLaunchProjects.Add($($folders -join "-") + "-v1", $("TestProjects/Spector/$($subPath.Replace([System.IO.Path]::DirectorySeparatorChar, '/'))") + "/v1") $spectorLaunchProjects.Add($($folders -join "-") + "-v2", $("TestProjects/Spector/$($subPath.Replace([System.IO.Path]::DirectorySeparatorChar, '/'))") + "/v2") - continue } - - # srv-driven contains two separate specs, for two separate clients. We need to generate both. - if ($folders.Contains("srv-driven")) { - Generate-Srv-Driven (Split-Path $specFile) $generationDir -generateStub $stubbed - $spectorLaunchProjects.Add($($folders -join "-") + "-v1", $("TestProjects/Spector/$($subPath.Replace([System.IO.Path]::DirectorySeparatorChar, '/'))") + "/v1") - $spectorLaunchProjects.Add($($folders -join "-") + "-v2", $("TestProjects/Spector/$($subPath.Replace([System.IO.Path]::DirectorySeparatorChar, '/'))") + "/v2") - continue + else { + $spectorLaunchProjects.Add(($folders -join "-"), ("TestProjects/Spector/$($subPath.Replace([System.IO.Path]::DirectorySeparatorChar, '/'))")) } - $spectorLaunchProjects.Add(($folders -join "-"), ("TestProjects/Spector/$($subPath.Replace([System.IO.Path]::DirectorySeparatorChar, '/'))")) if ($LaunchOnly) { continue } - - Invoke (Get-TspCommand $specFile $generationDir $stubbed) - # exit if the generation failed - if ($LASTEXITCODE -ne 0) { - exit $LASTEXITCODE + $generationJobs += @{ + Name = $subPath + OutputDir = $generationDir + Commands = @(Get-SpecGenerationCommands $specFile $subPath $generationDir -generateStub $stubbed) } # TODO need to build but depends on https://github.com/Azure/autorest.csharp/issues/4463 } +if ($generationJobs.Count -gt 0) { + Invoke-ParallelGeneration $generationJobs -ThrottleLimit $GenerationParallelism +} + +if ($generateSampleTypeSpec) { + Write-Host "Building SampleTypeSpec" -ForegroundColor Cyan + Invoke "dotnet build $packageRoot/generator/TestProjects/Local/Sample-TypeSpec/src/SampleTypeSpec.csproj" + + # exit if the build failed + if ($LASTEXITCODE -ne 0) { + exit $LASTEXITCODE + } +} + # only write new launch settings if no filter was passed in if ($null -eq $filter) { Write-Host "Writing new launch settings" -ForegroundColor Cyan diff --git a/packages/http-client-csharp/eng/scripts/Generation.psm1 b/packages/http-client-csharp/eng/scripts/Generation.psm1 index c259a5ffa26..63f702ff987 100644 --- a/packages/http-client-csharp/eng/scripts/Generation.psm1 +++ b/packages/http-client-csharp/eng/scripts/Generation.psm1 @@ -107,7 +107,7 @@ function Compare-Paths { return $normalizedPath1.Contains($normalizedPath2) } -function Generate-Srv-Driven { +function Get-SrvDrivenCommands { param ( [string]$specFilePath, [string]$outputDir, @@ -134,8 +134,23 @@ function Generate-Srv-Driven { $v1SpecFilePath = $(Join-Path $specFilePath "old.tsp") $v2SpecFilePath = $(Join-Path $specFilePath "main.tsp") - Invoke (Get-TspCommand $v1SpecFilePath $v1Dir -generateStub $generateStub -libraryNameOverride $v1LibraryNameOverride) - Invoke (Get-TspCommand $v2SpecFilePath $v2Dir -generateStub $generateStub -libraryNameOverride $v2LibraryNameOverride) + return @( + (Get-TspCommand $v1SpecFilePath $v1Dir -generateStub $generateStub -libraryNameOverride $v1LibraryNameOverride) + (Get-TspCommand $v2SpecFilePath $v2Dir -generateStub $generateStub -libraryNameOverride $v2LibraryNameOverride) + ) +} + +function Generate-Srv-Driven { + param ( + [string]$specFilePath, + [string]$outputDir, + [bool]$generateStub = $false, + [bool]$createOutputDirIfNotExist = $true + ) + + foreach ($command in Get-SrvDrivenCommands $specFilePath $outputDir -generateStub $generateStub -createOutputDirIfNotExist $createOutputDirIfNotExist) { + Invoke $command + } # exit if the generation failed if ($LASTEXITCODE -ne 0) { @@ -143,7 +158,7 @@ function Generate-Srv-Driven { } } -function Generate-Versioning { +function Get-VersioningCommands { param ( [string]$specFilePath, [string]$outputDir, @@ -167,8 +182,10 @@ function Generate-Versioning { $v1LibraryNameOverride = $namespaceRoot + ".V1" $v2LibraryNameOverride = $namespaceRoot + ".V2" - Invoke (Get-TspCommand $specFilePath $v1Dir -generateStub $generateStub -apiVersion "v1" -libraryNameOverride $v1LibraryNameOverride) - Invoke (Get-TspCommand $specFilePath $v2Dir -generateStub $generateStub -apiVersion "v2" -libraryNameOverride $v2LibraryNameOverride) + $commands = @( + (Get-TspCommand $specFilePath $v1Dir -generateStub $generateStub -apiVersion "v1" -libraryNameOverride $v1LibraryNameOverride) + (Get-TspCommand $specFilePath $v2Dir -generateStub $generateStub -apiVersion "v2" -libraryNameOverride $v2LibraryNameOverride) + ) if ($outputFolders.Contains("removed")) { $v2PreviewDir = $(Join-Path $outputDir "v2Preview") @@ -176,7 +193,22 @@ function Generate-Versioning { New-Item -ItemType Directory -Path $v2PreviewDir | Out-Null } $v2PreviewLibraryNameOverride = $namespaceRoot + ".V2Preview" - Invoke (Get-TspCommand $specFilePath $v2PreviewDir -generateStub $generateStub -apiVersion "v2preview" -libraryNameOverride $v2PreviewLibraryNameOverride) + $commands += Get-TspCommand $specFilePath $v2PreviewDir -generateStub $generateStub -apiVersion "v2preview" -libraryNameOverride $v2PreviewLibraryNameOverride + } + + return $commands +} + +function Generate-Versioning { + param ( + [string]$specFilePath, + [string]$outputDir, + [bool]$generateStub = $false, + [bool]$createOutputDirIfNotExist = $true + ) + + foreach ($command in Get-VersioningCommands $specFilePath $outputDir -generateStub $generateStub -createOutputDirIfNotExist $createOutputDirIfNotExist) { + Invoke $command } # exit if the generation failed @@ -185,6 +217,113 @@ function Generate-Versioning { } } +function Get-SpecGenerationCommands { + param ( + [string]$specFile, + [string]$subPath, + [string]$outputDir, + [bool]$generateStub = $false, + [bool]$createOutputDirIfNotExist = $true + ) + + $folders = $subPath.Split([System.IO.Path]::DirectorySeparatorChar) + + if ($folders.Contains("versioning")) { + return Get-VersioningCommands (Split-Path $specFile) $outputDir -generateStub $generateStub -createOutputDirIfNotExist $createOutputDirIfNotExist + } + + # srv-driven contains two separate specs, for two separate clients. We need to generate both. + if ($folders.Contains("srv-driven")) { + return Get-SrvDrivenCommands (Split-Path $specFile) $outputDir -generateStub $generateStub -createOutputDirIfNotExist $createOutputDirIfNotExist + } + + return @(Get-TspCommand $specFile $outputDir $generateStub) +} + +# Runs generation jobs concurrently. Each job is a hashtable with a Name, an OutputDir and an ordered list of Commands; +# commands within a job run sequentially, jobs run in parallel. Output is only printed for failed jobs. +function Invoke-ParallelGeneration { + param ( + [Parameter(Mandatory = $true)] + [object[]]$Jobs, + [int]$ThrottleLimit = 0 + ) + + if ($ThrottleLimit -le 0) { + $ThrottleLimit = $env:CSHARP_GENERATION_PARALLELISM ? [int]$env:CSHARP_GENERATION_PARALLELISM : [Environment]::ProcessorCount + } + $ThrottleLimit = [Math]::Max(1, $ThrottleLimit) + + # Generation deletes every project file under its output directory, so a job whose output directory is + # nested inside another job's output directory is merged into that job and runs after it. + $mergedJobs = [System.Collections.Generic.List[hashtable]]::new() + foreach ($job in $Jobs | Sort-Object { $_.OutputDir ? ([System.IO.Path]::GetFullPath($_.OutputDir)).Length : 0 }) { + $root = $job.OutputDir ? [System.IO.Path]::GetFullPath($job.OutputDir).TrimEnd('\', '/') + [System.IO.Path]::DirectorySeparatorChar : $null + $parent = $root ? ($mergedJobs | Where-Object { $_.Root -and $root.StartsWith($_.Root, [System.StringComparison]::OrdinalIgnoreCase) } | Select-Object -First 1) : $null + if ($parent) { + $parent.Name = "$($parent.Name), $($job.Name)" + $parent.Commands = @($parent.Commands) + @($job.Commands) + } + else { + $mergedJobs.Add(@{ Name = $job.Name; Root = $root; Commands = @($job.Commands) }) + } + } + $Jobs = $mergedJobs.ToArray() + + Write-Host "Running $($Jobs.Count) generation job(s) with parallelism $ThrottleLimit" -ForegroundColor Cyan + $stopwatch = [System.Diagnostics.Stopwatch]::StartNew() + $workingDirectory = $packageRoot + $useShell = $IsLinux -or $IsMacOS + + $results = $Jobs | ForEach-Object -ThrottleLimit $ThrottleLimit -Parallel { + $job = $_ + $jobStopwatch = [System.Diagnostics.Stopwatch]::StartNew() + $output = [System.Text.StringBuilder]::new() + $exitCode = 0 + + Set-Location $using:workingDirectory + foreach ($command in $job.Commands) { + [void]$output.AppendLine("> $command") + $lines = if ($using:useShell) { sh -c "$command 2>&1" } else { cmd /c "$command 2>&1" } + foreach ($line in $lines) { + [void]$output.AppendLine("$line") + } + if ($LASTEXITCODE -ne 0) { + $exitCode = $LASTEXITCODE + break + } + } + + @{ + Name = $job.Name + ExitCode = $exitCode + Output = $output.ToString() + Elapsed = $jobStopwatch.Elapsed + } + } + + $failed = @() + foreach ($result in $results | Sort-Object { $_.Name }) { + if ($result.ExitCode -ne 0) { + Write-Host "Failed to generate $($result.Name) (exit code $($result.ExitCode))" -ForegroundColor Red + Write-Host $result.Output + $failed += $result + } + else { + Write-Host "Generated $($result.Name) in $($result.Elapsed.ToString('mm\:ss\.ff'))" + } + } + + Write-Host "Generation completed in $($stopwatch.Elapsed.ToString('hh\:mm\:ss\.ff'))" -ForegroundColor Cyan + + if ($failed.Count -gt 0) { + $global:LASTEXITCODE = 1 + throw "Generation failed for: $(($failed | ForEach-Object { $_.Name }) -join ', ')" + } + + $global:LASTEXITCODE = 0 +} + function Set-LaunchSettings { param([object]$LaunchSettings) @@ -200,4 +339,8 @@ Export-ModuleMember -Function "Refresh-Build" Export-ModuleMember -Function "Compare-Paths" Export-ModuleMember -Function "Generate-Srv-Driven" Export-ModuleMember -Function "Generate-Versioning" +Export-ModuleMember -Function "Get-SrvDrivenCommands" +Export-ModuleMember -Function "Get-VersioningCommands" +Export-ModuleMember -Function "Get-SpecGenerationCommands" +Export-ModuleMember -Function "Invoke-ParallelGeneration" Export-ModuleMember -Function "Set-LaunchSettings" diff --git a/packages/http-client-csharp/eng/scripts/Get-Spector-Coverage.ps1 b/packages/http-client-csharp/eng/scripts/Get-Spector-Coverage.ps1 index 8cd8dbc92e2..ba500acdaea 100644 --- a/packages/http-client-csharp/eng/scripts/Get-Spector-Coverage.ps1 +++ b/packages/http-client-csharp/eng/scripts/Get-Spector-Coverage.ps1 @@ -1,14 +1,24 @@ #Requires -Version 7.0 +param( + # Skip rebuilding the emitter and generator, e.g. when the caller has already built them. + [switch] $SkipBuild, + # Maximum number of concurrent generation jobs; 0 uses the default of Invoke-ParallelGeneration. + [int] $GenerationParallelism = 0 +) + Import-Module "$PSScriptRoot\Generation.psm1" -DisableNameChecking -Force; Import-Module "$PSScriptRoot\Spector-Helper.psm1" -DisableNameChecking -Force; -Refresh-Build +if (-not $SkipBuild) { + Refresh-Build +} $packageRoot = Resolve-Path (Join-Path $PSScriptRoot '..' '..') $spectorCsproj = Join-Path $packageRoot 'generator' 'TestProjects' 'Spector.Tests' 'TestProjects.Spector.Tests.csproj' $spectorRoot = Join-Path $packageRoot 'generator' 'TestProjects' 'Spector' -$coverageDir = Join-Path $packageRoot 'generator' 'artifacts' 'coverage' +$artifactsDir = Join-Path $packageRoot 'generator' 'artifacts' +$coverageDir = Join-Path $artifactsDir 'coverage' if (-not (Test-Path $coverageDir)) { New-Item -ItemType Directory -Path $coverageDir | Out-Null @@ -17,52 +27,54 @@ if (-not (Test-Path $coverageDir)) { $specs = Get-Sorted-Specs # generate all - foreach ($specFile in $specs) { - $subPath = Get-SubPath $specFile +$generationJobs = @() +$projectDirs = @() +foreach ($specFile in $specs) { + $subPath = Get-SubPath $specFile + $folders = $subPath.Split([System.IO.Path]::DirectorySeparatorChar) + $outputDir = Join-Path $spectorRoot $subPath - Write-Host "Regenerating $subPath" -ForegroundColor Cyan - $outputDir = Join-Path $spectorRoot $subPath - - if ($subPath.Contains("versioning")) { - # this will generate v1 and v2 so we only need to call it once for one of the versions - Generate-Versioning ($specFile | Split-Path) $outputDir -createOutputDirIfNotExist $false - continue - } + $generationJobs += @{ + Name = $subPath + OutputDir = $outputDir + Commands = @(Get-SpecGenerationCommands $specFile $subPath $outputDir -createOutputDirIfNotExist $false) + } - if ($subPath.Contains("srv-driven")) { - # this will generate v1 and v2 so we only need to call it once for one of the versions - Generate-Srv-Driven ($specFile| Split-Path) $outputDir -createOutputDirIfNotExist $false - continue - } + # versioning and srv-driven projects are built through their references from the Spector test project + if (-not ($folders.Contains("versioning") -or $folders.Contains("srv-driven"))) { + $projectDirs += $outputDir + } +} - $command = Get-TspCommand $specFile $outputDir - Invoke $command - # exit if the generation failed - if ($LASTEXITCODE -ne 0) { - exit $LASTEXITCODE - } +Invoke-ParallelGeneration $generationJobs -ThrottleLimit $GenerationParallelism - # build the generated project - Write-Host "Building $subPath" -ForegroundColor Cyan - Get-ChildItem -Path $outputDir -Recurse -Filter '*.csproj' | ForEach-Object { - $command = "dotnet build $_" - Invoke $command - # exit if the build failed - if ($LASTEXITCODE -ne 0) { - exit $LASTEXITCODE - } - } - } +# collect projects after generation since generation deletes and recreates the project files +$projectsToBuild = @($spectorCsproj) +foreach ($projectDir in $projectDirs) { + $projectsToBuild += Get-ChildItem -Path $projectDir -Recurse -Filter '*.csproj' | ForEach-Object FullName +} - # test all - Write-Host "Generating Spector coverage" -ForegroundColor Cyan - $command = "dotnet test $spectorCsproj" - Invoke $command - # exit if the testing failed - if ($LASTEXITCODE -ne 0) { - exit $LASTEXITCODE - } +# build all generated projects and the test project in a single parallel build +Write-Host "Building generated Spector projects" -ForegroundColor Cyan +$solutionPath = Join-Path $artifactsDir 'spector-coverage.slnx' +$solutionProjects = $projectsToBuild | Sort-Object -Unique | ForEach-Object { + " " +} +Set-Content -Path $solutionPath -Value (@('') + $solutionProjects + @('')) +Invoke "dotnet build $solutionPath" +# exit if the build failed +if ($LASTEXITCODE -ne 0) { + exit $LASTEXITCODE +} +# test all +Write-Host "Generating Spector coverage" -ForegroundColor Cyan +$command = "dotnet test $spectorCsproj --no-build" +Invoke $command +# exit if the testing failed +if ($LASTEXITCODE -ne 0) { + exit $LASTEXITCODE +} # restore all foreach ($specFile in $specs) { $subPath = Get-SubPath $specFile diff --git a/packages/http-client-csharp/eng/scripts/Test-Packages.ps1 b/packages/http-client-csharp/eng/scripts/Test-Packages.ps1 index f8cc38fcb4d..c2ece0f90d7 100644 --- a/packages/http-client-csharp/eng/scripts/Test-Packages.ps1 +++ b/packages/http-client-csharp/eng/scripts/Test-Packages.ps1 @@ -18,6 +18,10 @@ $nugetConfigPath = (Join-Path $repoRoot "eng/nuget.config") $ciNugetAuditArg = $env:TF_BUILD ? "-p:NuGetAudit=false" : "" $previousRestoreConfigFile = $env:RestoreConfigFile $previousNuGetAudit = $env:NuGetAudit +# On CI, oversubscribe generation since each job spends much of its time on process startup and I/O. +$generationParallelism = $env:TF_BUILD ? [Environment]::ProcessorCount * 2 : 0 +# On CI, Spector coverage only runs in the job that sets CSHARP_RUN_SPECTOR_COVERAGE (see eng/pipeline/templates/ci-stages.yml). +$runSpectorCoverage = (-not $env:TF_BUILD) -or ($env:CSHARP_RUN_SPECTOR_COVERAGE -eq 'true') try { # Ensure all dotnet processes, including those spawned by npm scripts and generation, # restore through the repository's Azure DevOps feed instead of nuget.org. @@ -38,14 +42,19 @@ try { # enforce cop static-analysis rules on the generator sources Invoke-LoggedCommand "./eng/scripts/Invoke-Cop.ps1" -GroupOutput - # test the generator - Invoke-LoggedCommand "dotnet test ./generator -p:RestoreConfigFile=`"$nugetConfigPath`" $ciNugetAuditArg" -GroupOutput + # test the generator; it was already built by `npm run build` above + Invoke-LoggedCommand "dotnet test ./generator --no-build -p:RestoreConfigFile=`"$nugetConfigPath`" $ciNugetAuditArg" -GroupOutput Invoke-LoggedCommand "dotnet test ./playground-server.Tests -p:RestoreConfigFile=`"$nugetConfigPath`" $ciNugetAuditArg" -GroupOutput Invoke-LoggedCommand "node --test ./playground-server.Tests/install-azure-generators.node-test.mjs ./playground-server.Tests/deploy.node-test.mjs" -GroupOutput - Invoke-LoggedCommand "./eng/scripts/Get-Spector-Coverage.ps1" -GroupOutput + if ($runSpectorCoverage) { + Invoke-LoggedCommand "./eng/scripts/Get-Spector-Coverage.ps1 -SkipBuild -GenerationParallelism $generationParallelism" -GroupOutput + } + else { + Write-Host "Skipping Spector coverage; it runs in a single CI job." -ForegroundColor Yellow + } } finally { Pop-Location @@ -62,10 +71,11 @@ try { Write-Host "Setting up workspace" -ForegroundColor Cyan Invoke-LoggedCommand "pnpm setup:min" $packageRoot/../.. - Invoke-LoggedCommand "npm run build && npm run regen-docs" -GroupOutput + # Generate.ps1 builds the emitter and the generator projects needed for generation, so a full build is not needed here + Invoke-LoggedCommand "npm run regen-docs" -GroupOutput # run E2E Test for TypeSpec emitter Write-Host "Generating test projects ..." - & "$packageRoot/eng/scripts/Generate.ps1" + & "$packageRoot/eng/scripts/Generate.ps1" -GenerationParallelism $generationParallelism Write-Host 'Code generation is completed.' try {