Skip to content

Commit

Permalink
Update ADO build scripts/files for net8 test run
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirwin committed Mar 13, 2024
1 parent 813ecd0 commit f511c09
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 36 deletions.
46 changes: 27 additions & 19 deletions .build/azure-templates/run-tests-on-os.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
Expand All @@ -34,7 +34,7 @@ parameters:
maximumAllowedFailures: 0
where: '' # A test filter expression, as defined by dotnet test
dotNetSdkVersion: '' # The .NET SDK version to install

steps:
- checkout: none # self represents the repo where the initial Pipelines YAML file was found

Expand Down Expand Up @@ -108,10 +108,18 @@ steps:
displayName: 'Use .NET sdk 6.0.403'
inputs:
packageType: 'sdk'
version: '5.0.403'
version: '6.0.403'
performMultiLevelLookup: '${{ variables.PerformMultiLevelLookup }}'
condition: and(succeeded(), contains('${{ parameters.framework }}', 'net6.'))

- task: UseDotNet@2
displayName: 'Use .NET sdk 8.0.202'
inputs:
packageType: 'sdk'
version: '8.0.202'
performMultiLevelLookup: '${{ variables.PerformMultiLevelLookup }}'
condition: and(succeeded(), contains('${{ parameters.framework }}', 'net8.'))

#- template: 'show-all-files.yml' # Uncomment for debugging
- pwsh: |
$framework = '${{ parameters.framework }}'
Expand All @@ -126,7 +134,7 @@ steps:
$tempDirectory = "$(Agent.TempDirectory)"
$isNightly = if ($env:ISNIGHTLY -eq 'true') { 'true' } else { 'false' }
$isWeekly = if ($env:ISWEEKLY -eq 'true') { 'true' } else { 'false' }
function IsSupportedFramework([string]$framework) {
if ($IsWindows -eq $null) {
$IsWindows = $env:OS.StartsWith('Win')
Expand All @@ -136,15 +144,15 @@ steps:
}
return $true
}
function RunTests([string]$framework, [string]$fileRegexPattern) {
if (!(IsSupportedFramework($framework))) { continue }
$testBinaries = Get-ChildItem -Path "$testBinaryRootDirectory" -File -Recurse | Where-Object {$_.FullName -match "$framework" -and $_.FullName -match "$fileRegexPattern" -and !$_.Name.EndsWith('.resources.dll') } | Sort-Object -Property FullName
Write-Host $testBinaries
foreach ($testBinary in $testBinaries) {
$testName = [System.IO.Path]::GetFileNameWithoutExtension($testBinary.FullName)
if ($maximumParalellJobs -gt 1) {
# Pause if we have queued too many parallel jobs
$running = @(Get-Job | Where-Object { $_.State -eq 'Running' })
Expand All @@ -155,7 +163,7 @@ steps:
$running | Wait-Job -Any | Out-Null
}
}
$testResultDirectory = "$testResultsArtifactDirectory/$testOSName/$framework/$testPlatform/$testName"
if (!(Test-Path "$testResultDirectory")) {
New-Item "$testResultDirectory" -ItemType Directory -Force
Expand Down Expand Up @@ -186,32 +194,32 @@ steps:
if (![string]::IsNullOrEmpty($where)) {
$testExpression = "$testExpression --filter ""$where"""
}
$testExpression = "$testExpression -- RunConfiguration.TargetPlatform=$testPlatform"
Write-Host "Testing '$($testBinary.FullName)' on framework '$framework' and outputting test results to '$testResultDirectory/$testResultsFileName'..."
Write-Host $testExpression -ForegroundColor Magenta
if ($maximumParalellJobs -le 1) {
Invoke-Expression $testExpression # For running in the foreground
} else {
$testExpression += " > ""$testResultDirectory/dotnet-test.log"" 2> ""$testResultDirectory/dotnet-test-error.log"""
$scriptBlock = {
param([string]$testExpression)
Invoke-Expression $testExpression
}
# Avoid dotnet test collisions by delaying for 500ms
Start-Sleep -Milliseconds 500
# Execute the jobs in parallel
Start-Job -Name "$testName,$framework,$testPlatform" -ScriptBlock $scriptBlock -ArgumentList $testExpression
}
}
}
RunTests -Framework "$framework" -FileRegexPattern "$testBinaryFilesPattern"
if ($maximumParalellJobs -gt 1) {
# Wait for it all to complete
do {
Expand All @@ -229,7 +237,7 @@ steps:
}
} until ($running.Count -eq 0)
}
$global:LASTEXITCODE = 0 # Force the script to continue on error
displayName: 'dotnet test ${{ parameters.framework }},${{ parameters.vsTestPlatform }}'
ignoreLASTEXITCODE: true
Expand All @@ -247,7 +255,7 @@ steps:
# it would be a ton of work to make a replacement for the
# Publish Test Results task or the (deprecated) TfsPublisher
# our only other option is to make a task for every supported
# platform and project and update it whenever a new platform
# platform and project and update it whenever a new platform
# is targeted or test project is created in Lucene.Net.

- template: 'publish-test-results-for-test-projects.yml'
Expand All @@ -270,4 +278,4 @@ steps:
}
if ($failed) {
Write-Host "##vso[task.complete result=Failed;]"
}
}
32 changes: 16 additions & 16 deletions .build/runbuild.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the ""License""); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an ""AS IS"" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -27,7 +27,7 @@ properties {
[string]$testResultsDirectory = "$artifactsDirectory/TestResults"
[string]$publishDirectory = "$artifactsDirectory/Publish"
[string]$solutionFile = "$baseDirectory/Lucene.Net.sln"
[string]$minimumSdkVersion = "7.0.100"
[string]$minimumSdkVersion = "8.0.202"
[string]$globalJsonFile = "$baseDirectory/global.json"
[string]$versionPropsFile = "$baseDirectory/version.props"
[string]$luceneReadmeFile = "$baseDirectory/src/Lucene.Net/readme-nuget.md"
Expand All @@ -48,7 +48,7 @@ properties {
[string]$publishedArtifactZipFileName = "artifact.zip"

[int]$maximumParallelJobs = 8

#test parameters
#The build uses Lucene.Net.Tests.Analysis.Common to determine all of the targets for the solution:
[string]$projectWithAllTestFrameworks = "$baseDirectory/src/Lucene.Net.Tests.Analysis.Common/Lucene.Net.Tests.Analysis.Common.csproj"
Expand Down Expand Up @@ -116,7 +116,7 @@ task Init -depends CheckSDK, UpdateLocalSDKVersion -description "This task makes
task Restore -description "This task restores the dependencies" {
Write-Host "##teamcity[progressMessage 'Restoring']"
Write-Host "##vso[task.setprogress]'Restoring'"
Exec {
Exec {
& dotnet restore $solutionFile --no-dependencies /p:TestFrameworks=true
}
}
Expand Down Expand Up @@ -195,13 +195,13 @@ task Publish -depends Compile -description "This task uses dotnet publish to pac

try {
$frameworksToTest = Get-FrameworksToTest

if ($zipPublishedArtifacts) {
$outDirectory = New-TemporaryDirectory
} else {
$outDirectory = $publishDirectory
}

foreach ($framework in $frameworksToTest) {

# Pause if we have queued too many parallel jobs
Expand All @@ -215,7 +215,7 @@ task Publish -depends Compile -description "This task uses dotnet publish to pac

# Do this first so there is no conflict
Ensure-Directory-Exists $outputPath

Write-Host "Configuration: $configuration"

$expression = "dotnet publish `"$solutionFile`" --configuration `"$configuration`" --framework `"$framework`" --output `"$outputPath`""
Expand Down Expand Up @@ -271,7 +271,7 @@ task Test -depends CheckSDK, UpdateLocalSDKVersion, Restore -description "This t
popd

$testProjects = $testProjects | Sort-Object -Property FullName

$frameworksToTest = Get-FrameworksToTest

[int]$totalProjects = $testProjects.Length * $frameworksToTest.Length
Expand All @@ -281,7 +281,7 @@ task Test -depends CheckSDK, UpdateLocalSDKVersion, Restore -description "This t

foreach ($testProject in $testProjects) {
$testName = $testProject.Directory.Name

# Call the target to get the configured test frameworks for this project. We only read the first line because MSBuild adds extra output.
$frameworksString = $(dotnet build "$testProject" --verbosity minimal --nologo --no-restore /t:PrintTargetFrameworks /p:TestProjectsOnly=true /p:TestFrameworks=true)[0].Trim()

Expand All @@ -296,15 +296,15 @@ task Test -depends CheckSDK, UpdateLocalSDKVersion, Restore -description "This t

$frameworks = [System.Collections.Generic.HashSet[string]]::new($frameworksString -split '\s*;\s*')
foreach ($framework in $frameworksToTest) {

# If the framework is not valid for this configuration, we need to adjust our
# initial estimate and skip the combination.
if (-not $frameworks.Contains($framework)) {
$totalProjects--
$remainingProjects--
continue
}

Write-Host ""
Write-Host " Next Project in Queue: $testName, Framework: $framework" -ForegroundColor Yellow

Expand Down Expand Up @@ -336,7 +336,7 @@ task Test -depends CheckSDK, UpdateLocalSDKVersion, Restore -description "This t
# Also log to a file in TRX format, so we have a build artifact both when
# doing release inspection and on the CI server.
$testExpression = "$testExpression --logger:""trx;LogFileName=TestResults.trx"""

if (![string]::IsNullOrEmpty($where)) {
$testExpression = "$testExpression --TestCaseFilter:""$where"""
}
Expand Down Expand Up @@ -580,7 +580,7 @@ function Summarize-Test-Results([string[]]$frameworksToTest) {
$_.FullName
}
popd

[int]$totalCountForFramework = 0
[int]$executedCountForFramework = 0
[int]$passedCountForFramework = 0
Expand All @@ -604,7 +604,7 @@ function Summarize-Test-Results([string[]]$frameworksToTest) {
$reader = [System.Xml.XmlReader]::Create($testReport)
try {
while ($reader.Read()) {

if ($reader.NodeType -eq [System.Xml.XmlNodeType]::Element -and $reader.Name -eq 'ResultSummary') {
$outcome = $reader.GetAttribute('outcome')
if ($outcomeForFramework -eq 'Completed') {
Expand Down Expand Up @@ -751,4 +751,4 @@ function New-TemporaryDirectory {
function Normalize-FileSystemSlashes([string]$path) {
$sep = [System.IO.Path]::DirectorySeparatorChar
return $($path -replace '/',$sep -replace '\\',$sep)
}
}
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ variables:
- name: BuildCounter
value: $[counter(variables['VersionSuffix'],coalesce(variables['BuildCounterSeed'], 1250))]
- name: DotNetSDKVersion
value: '7.0.100'
value: '8.0.202'
- name: DocumentationArtifactName
value: 'docs'
- name: DocumentationArtifactZipFileName
Expand Down

0 comments on commit f511c09

Please sign in to comment.