forked from apache/lucenenet
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathrunbuild.ps1
More file actions
774 lines (656 loc) · 35.2 KB
/
Copy pathrunbuild.ps1
File metadata and controls
774 lines (656 loc) · 35.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
# -----------------------------------------------------------------------------------
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# 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.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# -----------------------------------------------------------------------------------
properties {
[string]$baseDirectory = Resolve-Path "../."
[string]$artifactsDirectory = "$baseDirectory/_artifacts"
[string]$sourceDirectory = "$baseDirectory/src"
[string]$testDirectory = "$baseDirectory/src"
[string]$toolsDirectory = "$baseDirectory/lib"
[string]$nugetPackageDirectory = "$artifactsDirectory/NuGetPackages"
[string]$testResultsDirectory = "$artifactsDirectory/TestResults"
[string]$publishDirectory = "$artifactsDirectory/Publish"
[string]$solutionFile = "$baseDirectory/Lucene.Net.sln"
[string]$minimumSdkVersion = "9.0.200" # We need at least 9.0.200 for ICU4N satellite assemblies with 3-character language codes to get copied to the output.
[string]$globalJsonFile = "$baseDirectory/global.json"
[string]$versionPropsFile = "$baseDirectory/version.props"
[string]$luceneReadmeFile = "$baseDirectory/src/Lucene.Net/readme-nuget.md"
[string]$luceneCLIReadmeFile = "$baseDirectory/src/dotnet/tools/lucene-cli/docs/index.md"
[string]$rootWebsiteUrl = "https://lucenenet.apache.org"
[string]$rootDocsWebsiteUrl = "$rootWebsiteUrl/docs"
[string]$buildCounter = $(if ($buildCounter) { $buildCounter } else { $env:BuildCounter }) #NOTE: Pass in as a parameter (not a property) or environment variable to override
[string]$preReleaseCounterPattern = $(if ($preReleaseCounterPattern) { $preReleaseCounterPattern } else { if ($env:PreReleaseCounterPattern) { $env:PreReleaseCounterPattern } else { "0000000000" } }) #NOTE: Pass in as a parameter (not a property) or environment variable to override
[string]$versionSuffix = $(if ($versionSuffix -ne $null) { $versionSuffix } else { if ($env:VersionSuffix -ne $null) { $env:VersionSuffix } else { 'ci' }}) #NOTE: Pass in as a parameter (not a property) or environment variable to override
[string]$packageVersion = Get-Package-Version #NOTE: Pass in as a parameter (not a property) or environment variable to override
[string]$version = Get-Version
[string]$configuration = $(if ($configuration) { $configuration } else { if ($env:BuildConfiguration) { $env:BuildConfiguration } else { "Release" } }) #NOTE: Pass in as a parameter (not a property) or environment variable to override
[string]$platform = $(if ($platform) { $platform } else { if ($env:BuildPlatform) { $env:BuildPlatform } else { "Any CPU" } }) #NOTE: Pass in as a parameter (not a property) or environment variable to override
[bool]$backupFiles = $true
[bool]$prepareForBuild = $true
[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"
[string]$where = ""
}
$backedUpFiles = New-Object System.Collections.ArrayList
$addedFiles = New-Object System.Collections.ArrayList
task default -depends Pack
task Clean -description "This task cleans up the build directory" {
Write-Host "##teamcity[progressMessage 'Cleaning']"
Write-Host "##vso[task.setprogress]'Cleaning'"
Remove-Item $artifactsDirectory -Force -Recurse -ErrorAction SilentlyContinue
Get-ChildItem $baseDirectory -Include *.bak -Recurse | foreach ($_) {Remove-Item $_.FullName}
}
task UpdateLocalSDKVersion -description "Backs up the project.json file and pins the version to $minimumSdkVersion" {
Backup-File $globalJsonFile
Update-Global-Json `
-sdkVersion $minimumSdkVersion `
-file $globalJsonFile
}
task CheckSDK -description "This task makes sure the correct SDK version is installed" {
# Check prerequisites
$sdkVersion = ((& dotnet --version) | Out-String).Trim()
if ($LASTEXITCODE -ne 0) {
throw "dotnet command was not found. Please install .NET $minimumSdkVersion or higher SDK and make sure it is in your PATH."
}
$releaseVersion = if ($sdkVersion.Contains('-')) { "$sdkVersion".Substring(0, "$sdkVersion".IndexOf('-')) } else { $sdkVersion }
if ([version]$releaseVersion -lt ([version]$minimumSdkVersion)) {
throw "Minimum .NET SDK $minimumSdkVersion required. Current SDK version is $releaseVersion. Please install the required SDK before running the command."
}
}
task Init -depends CheckSDK, UpdateLocalSDKVersion -description "This task makes sure the build environment is correctly setup" {
#Update TeamCity, MyGet, or Azure Pipelines with packageVersion
Write-Output "##teamcity[buildNumber '$packageVersion']"
Write-Output "##myget[buildNumber '$packageVersion']"
Write-Host "##vso[build.updatebuildnumber]$packageVersion"
& dotnet --version
& dotnet --info
Write-Host "Base Directory: $(Normalize-FileSystemSlashes "$baseDirectory")"
Write-Host "Release Directory: $(Normalize-FileSystemSlashes "$artifactsDirectory")"
Write-Host "Source Directory: $(Normalize-FileSystemSlashes "$sourceDirectory")"
Write-Host "Test Directory: $(Normalize-FileSystemSlashes "$testDirectory")"
Write-Host "Tools Directory: $(Normalize-FileSystemSlashes "$toolsDirectory")"
Write-Host "NuGet Package Directory: $(Normalize-FileSystemSlashes "$nugetPackageDirectory")"
Write-Host "BuildCounter: $buildCounter"
Write-Host "PreReleaseCounterPattern: $preReleaseCounterPattern"
Write-Host "VersionSuffix: $versionSuffix"
Write-Host "Package Version: $packageVersion"
Write-Host "File Version: $version"
Write-Host "Configuration: $configuration"
Write-Host "Platform: $platform"
Write-Host "MaximumParallelJobs: $($maximumParallelJobs.ToString())"
Write-Host "Powershell Version: $($PSVersionTable.PSVersion)"
Ensure-Directory-Exists "$artifactsDirectory"
Ensure-Directory-Exists "$nugetPackageDirectory" # helpful when adding this path to your nuget sources for local installs
}
task Restore -description "This task restores the dependencies" {
Write-Host "##teamcity[progressMessage 'Restoring']"
Write-Host "##vso[task.setprogress]'Restoring'"
Exec {
& dotnet restore $solutionFile --no-dependencies /p:TestFrameworks=true
}
}
task Compile -depends Clean, Init, Restore -description "This task compiles the solution" {
Write-Host "##teamcity[progressMessage 'Compiling']"
Write-Host "##vso[task.setprogress]'Compiling'"
try {
if ($prepareForBuild -eq $true) {
Prepare-For-Build
}
Exec {
# NOTE: Version information is not passed in at the command line,
# instead it is output to the version.props file. This file is then
# used during a release to "freeze" the build at a specific version
# so it is always a constant in release distributions.
& dotnet build "$solutionFile" `
--configuration "$configuration" `
--no-restore `
-p:Platform=$platform `
-p:PortableDebugTypeOnly=true `
-p:TestFrameworks=true # workaround for parsing issue: https://github.com/Microsoft/msbuild/issues/471#issuecomment-181963350
}
$success = $true
} finally {
if ($success -ne $true) {
Delete-Added-Files $addedFiles
Restore-Files $backedUpFiles
}
}
}
task Pack -depends Compile -description "This task creates the NuGet packages" {
Write-Host "##teamcity[progressMessage 'Packing']"
Write-Host "##vso[task.setprogress]'Packing'"
#create the nuget package output directory
Ensure-Directory-Exists "$nugetPackageDirectory"
Update-Lucene-Readme-For-Pack $packageVersion
Update-LuceneCLI-Readme-For-Pack $packageVersion
try {
Exec {
# NOTE: Package version information is not passed in at the command line,
# instead it is output to the version.props file. This file is then
# used during a release to "freeze" the build at a specific version
# so it is always a constant in release distributions.
& dotnet pack $solutionFile --configuration $configuration --output $nugetPackageDirectory --no-build
}
# Set the SYSTEM_DEFAULTWORKINGDIRECTORY if we are not on Azure DevOps. This will optimize the lucene-cli
# installation test so it doesn't rebuild the NuGet package during a local build.
if (-Not (Test-Path 'env:SYSTEM_DEFAULTWORKINGDIRECTORY')) {
$env:SYSTEM_DEFAULTWORKINGDIRECTORY = "$baseDirectory"
}
Write-Host ""
Write-Host "\nSYSTEM_DEFAULTWORKINGDIRECTORY is $env:SYSTEM_DEFAULTWORKINGDIRECTORY (for lucene-cli installation tests)" -ForegroundColor Yellow
$success = $true
} finally {
#if ($success -ne $true) {
Delete-Added-Files $addedFiles
Restore-Files $backedUpFiles
#}
}
}
# Loops through each framework in the TestTargetFrameworks variable and
# publishes the solution in the artifact staging directory with the framework
# as part of the folder structure.
task Publish -depends Compile -description "This task uses dotnet publish to package the binaries with all of their dependencies so they can be run xplat" {
Write-Host "##teamcity[progressMessage 'Publishing']"
Write-Host "##vso[task.setprogress]'Publishing'"
try {
$frameworksToTest = Get-FrameworksToTest
$outDirectory = $publishDirectory
foreach ($framework in $frameworksToTest) {
# Pause if we have queued too many parallel jobs
$running = @(Get-Job | Where-Object { $_.State -eq 'Running' })
if ($running.Count -ge $maximumParallelJobs) {
$running | Wait-Job -Any | Out-Null
}
$logPath = "$outDirectory/$framework"
# Do this first so there is no conflict
Ensure-Directory-Exists $logPath
Write-Host "Configuration: $configuration"
$expression = "dotnet publish `"$solutionFile`" --configuration `"$configuration`" --framework `"$framework`""
$expression = "$expression --no-build --no-restore --verbosity Normal /p:TestFrameworks=true /p:Platform=`"$platform`" /p:AlternatePublishRootDirectory=`"$outDirectory`""
$expression = "$expression > `"$logPath/dotnet-publish.log`" 2> `"$logPath/dotnet-publish-error.log`""
$scriptBlock = {
param([string]$expression)
Write-Host $expression
# Note: Cannot use Psake Exec in background
Invoke-Expression $expression
}
# Execute the jobs in parallel
Start-Job -Name "$framework" -ScriptBlock $scriptBlock -ArgumentList @($expression) | Out-Null
}
# Wait for it all to complete
do {
$running = @(Get-Job | Where-Object { $_.State -eq 'Running' })
if ($running.Count -gt 0) {
Write-Host ""
Write-Host " Almost finished, only $($running.Count) projects left to publish..." -ForegroundColor Cyan
$running | Wait-Job -Any | Out-Null
}
} until ($running.Count -eq 0)
# Getting the information back from the jobs (time consuming)
#Get-Job | Receive-Job
$success = $true
} finally {
#if ($success -ne $true) {
Delete-Added-Files $addedFiles
Restore-Files $backedUpFiles
#}
}
}
task Test -depends CheckSDK, UpdateLocalSDKVersion, Restore -description "This task runs the tests" {
Write-Host "##teamcity[progressMessage 'Testing']"
Write-Host "##vso[task.setprogress]'Testing'"
Write-Host "Running tests..." -ForegroundColor DarkCyan
pushd $baseDirectory
$testProjects = Get-ChildItem -Path "$testDirectory/**/*.csproj" -Recurse | ? { $_.Directory.Name.Contains(".Tests") }
popd
$testProjects = $testProjects | Sort-Object -Property FullName
$frameworksToTest = Get-FrameworksToTest
[int]$totalProjects = $testProjects.Length * $frameworksToTest.Length
[int]$remainingProjects = $totalProjects
Ensure-Directory-Exists $testResultsDirectory
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 = Get-SupportedTargetFrameworksString $testProject
Write-Host ""
Write-Host "Frameworks To Test for ${testProject}: $frameworksString" -ForegroundColor Yellow
if ($frameworksString -eq 'none') {
Write-Host ""
Write-Host "Skipping project '$testProject' because it is not marked with `<IsTestProject`>true`<`/IsTestProject`> and/or it contains no test frameworks for the current environment." -ForegroundColor DarkYellow
continue
}
$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
# Pause if we have queued too many parallel jobs
$running = @(Get-Job | Where-Object { $_.State -eq 'Running' })
if ($running.Count -ge $maximumParallelJobs) {
Write-Host ""
Write-Host " Running tests in parallel on $($running.Count) projects out of approximately $totalProjects total." -ForegroundColor Cyan
Write-Host " $remainingProjects projects are waiting in the queue to run. This will take a bit, please wait..." -ForegroundColor Cyan
$running | Wait-Job -Any | Out-Null
}
$remainingProjects -= 1
$testResultDirectory = "$testResultsDirectory/$framework/$testName"
Ensure-Directory-Exists $testResultDirectory
$testProjectPath = $testProject.FullName
$testExpression = "dotnet test $testProjectPath --configuration $configuration --framework $framework --no-build"
$testExpression = "$testExpression --no-restore --blame --blame-hang --blame-hang-dump-type mini --blame-hang-timeout 15minutes --results-directory $testResultDirectory"
# Breaking change: We need to explicitly set the logger for it to work with TeamCity.
# See: https://github.com/microsoft/vstest/issues/1590#issuecomment-393460921
# Log to the console normal verbosity. With the TeamCity.VSTest.TestAdapter
# referenced by the test DLL, this will output teamcity service messages.
# Also, it displays pretty user output on the console.
$testExpression = "$testExpression --logger:""console;verbosity=normal"""
# 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"""
}
# Anything after here is test run settings, following the "--" separator
$testExpression = "$testExpression --"
# Specify NUnit.DisplayName to get the full test class name in the output
$testExpression = "$testExpression NUnit.DisplayName=FullName"
Write-Host $testExpression -ForegroundColor Magenta
$scriptBlock = {
param([string]$testExpression, [string]$testResultDirectory)
$testExpression = "$testExpression > '$testResultDirectory/dotnet-test.log' 2> '$testResultDirectory/dotnet-test-error.log'"
Invoke-Expression $testExpression
}
# Execute the jobs in parallel
Start-Job -Name "$testName,$framework" -ScriptBlock $scriptBlock -ArgumentList $testExpression,$testResultDirectory | Out-Null
#Invoke-Expression $testExpression
## fail the build on negative exit codes (NUnit errors - if positive it is a test count or, if 1, it could be a dotnet error)
#if ($LASTEXITCODE -lt 0) {
# throw "Test execution failed"
#}
}
}
do {
$running = @(Get-Job | Where-Object { $_.State -eq 'Running' })
if ($running.Count -gt 0) {
Write-Host ""
Write-Host " Almost finished, only $($running.Count) test projects left..." -ForegroundColor Cyan
[int]$number = 0
foreach ($runningJob in $running) {
$number++
$jobName = $runningJob | Select-Object -ExpandProperty Name
Write-Host "$number. $jobName"
}
$running | Wait-Job -Any
}
} until ($running.Count -eq 0)
Summarize-Test-Results -FrameworksToTest $frameworksToTest
}
function Get-Package-Version() {
Write-Host $parameters.packageVersion -ForegroundColor Red
#If $packageVersion is not passed in (as a parameter or environment variable), get it from Version.proj
if (![string]::IsNullOrWhiteSpace($parameters.packageVersion) -and $parameters.packageVersion -ne "0.0.0") {
return $parameters.packageVersion
} elseif (![string]::IsNullOrWhiteSpace($env:PackageVersion) -and $env:PackageVersion -ne "0.0.0") {
return $env:PackageVersion
} else {
#Get the version info
$versionFile = "$baseDirectory/Directory.Build.props"
$xml = [xml](Get-Content $versionFile)
$versionPrefix = ([string]$xml.Project.PropertyGroup.VersionPrefix).Trim()
if ([string]::IsNullOrWhiteSpace($versionSuffix)) {
# this is a production release - use 4 segment version number 0.0.0.0
if ([string]::IsNullOrWhiteSpace($buildCounter)) {
$buildCounter = "0"
}
$packageVersion = "$versionPrefix.$buildCounter"
} else {
if (![string]::IsNullOrWhiteSpace($buildCounter)) {
$buildCounter = ([Int32]$buildCounter).ToString($preReleaseCounterPattern)
}
# this is a pre-release - use 3 segment version number with (optional) zero-padded pre-release tag
$packageVersion = "$versionPrefix-$versionSuffix$buildCounter"
}
return $packageVersion
}
}
function Get-Version() {
#If $version is not passed in, parse it from $packageVersion
if ([string]::IsNullOrWhiteSpace($version) -or $version -eq "0.0.0") {
$version = Get-Package-Version
if ($version.Contains("-") -eq $true) {
$version = $version.SubString(0, $version.IndexOf("-"))
}
}
return $version
}
function Get-FrameworksToTest() {
# Call the target to get the configured test frameworks for a project known to contain all of them. We only read the first line because MSBuild adds extra output.
$frameworksString = Get-SupportedTargetFrameworksString -ProjectPath $projectWithAllTestFrameworks
$frameworksToTest = $frameworksString -split '\s*;\s*'
Assert($frameworksToTest.Length -gt 0) "The project at $(Normalize-FileSystemSlashes "$projectWithAllTestFrameworks") contains no target frameworks. Please configure a project that includes all testable target frameworks."
return $frameworksToTest
}
function Get-SupportedTargetFrameworksString([Parameter(Mandatory)][string] $ProjectPath) {
# NOTE: This will not appear when run directly in the console with minimal verbosity. MSBuild only produces the output when using a pipe, which is what we are doing here.
$output = dotnet build "$ProjectPath" --verbosity minimal --nologo --no-restore /t:PrintTargetFrameworks /p:TestProjectsOnly=true /p:TestFrameworks=true 2>&1 | Out-String
if ($output -match 'SupportedTargetFrameworks=([^\s]+)') {
return $matches[1]
}
throw "Failed to determine supported target frameworks for project: $ProjectPath"
}
function Prepare-For-Build() {
#Use only the major version as the assembly version.
#This ensures binary compatibility unless the major version changes.
$version -match "(^\d+)"
$assemblyVersion = $Matches[0]
$assemblyVersion = "$assemblyVersion.0.0"
Write-Host "Assembly version set to: $assemblyVersion" -ForegroundColor Green
$informationalVersion = $packageVersion
# Only update the version if git is present and the command to read the commit succeeds
$gitCommit = ((git rev-parse --verify --short=10 head) | Out-String).Trim()
if ($LASTEXITCODE -eq 0) {
$informationalVersion = "$packageVersion commit:[$gitCommit]"
}
Write-Host "##vso[task.setvariable variable=AssemblyVersion;]$assemblyVersion"
Write-Host "##vso[task.setvariable variable=FileVersion;]$version"
Write-Host "##vso[task.setvariable variable=InformationalVersion;]$informationalVersion"
Write-Host "##vso[task.setvariable variable=PackageVersion;]$packageVersion"
Write-Host "Assembly informational version set to: $informationalVersion" -ForegroundColor Green
Generate-Version-Props `
-AssemblyVersion $assemblyVersion `
-FileVersion $version `
-InformationalVersion $informationalVersion `
-PackageVersion $packageVersion `
-File $versionPropsFile
Update-Constants-Version $packageVersion
}
function Update-Constants-Version([string]$version) {
$constantsFile = "$baseDirectory/src/Lucene.Net/Util/Constants.cs"
Backup-File $constantsFile
(Get-Content $constantsFile) | % {
$_-replace "(?<=LUCENE_VERSION\s*?=\s*?"")([^""]*)", $version
} | Set-Content $constantsFile -Force
}
function Update-Lucene-Readme-For-Pack([string]$version) {
Backup-File $luceneReadmeFile
(Get-Content $luceneReadmeFile) | % {
# Replace version in lucene-cli install command
$_ -replace "(?<=lucene-cli(?:\s?-{1,2}\w*?)*?\s+--version\s+)(\d+\.\d+\.\d+(?:\.\d+)?(?:-\w*)?)", $version
} | % {
# NuGet absoluteLatest package URL references with current version
$_ -replace "(?<=https?://(?:[\w/\.]*?))(absoluteLatest)", $version
} | % {
# Replace doc version number URL with the current version
$_ -replace "(?<=https?://(?:[\w/\.]*?)/docs/)(\d+\.\d+\.\d+(?:\.\d+)?(?:-\w*)?)", $version
} | Set-Content $luceneReadmeFile -Force
}
function Update-LuceneCLI-Readme-For-Pack([string]$version) {
Backup-File $luceneCLIReadmeFile
(Get-Content $luceneCLIReadmeFile) | % {
# Replace version in lucene-cli install command
$_ -replace "(?<=lucene-cli(?:\s?-{1,2}\w*?)*?\s+--version\s+)(\d+\.\d+\.\d+(?:\.\d+)?(?:-\w*)?)", $version
} | % {
# Replace markdown file references with website URLs to the correct documentation version
$_ -replace "(?<=\()(\w*/index).md(?=\))", "$rootDocsWebsiteUrl/$version/cli/`$1.html"
} | Set-Content $luceneCLIReadmeFile -Force
}
function Update-Global-Json {
param(
[string]$sdkVersion,
[string]$file = $(throw "file is a required parameter.")
)
$dir = [System.IO.Path]::GetDirectoryName($file)
Ensure-Directory-Exists $dir
# Read existing JSON file if it exists
if (Test-Path $file) {
$jsonContent = Get-Content $file -Raw | ConvertFrom-Json
} else {
# Create a new object if the file doesn't exist
$jsonContent = [pscustomobject]@{
"msbuild-sdks" = @{
"Microsoft.Build.NoTargets" = "3.7.56"
}
"sources" = @("src")
}
}
# Ensure sdk is an object, even if it exists but is null
if (-not $jsonContent.PSObject.Properties.Match('sdk') -or $null -eq $jsonContent.sdk) {
# Add the "sdk" property if it doesn't exist
$jsonContent | Add-Member -MemberType NoteProperty -Name "sdk" -Value @{}
}
# Now update the sdk properties
$jsonContent.sdk.version = $sdkVersion
$jsonContent.sdk.rollForward = "latestMajor"
Write-Host "Generating global.json file: $(Normalize-FileSystemSlashes "$file")"
Track-Added-File $file
# Convert the updated object back to JSON and write it to the file
$jsonContent | ConvertTo-Json -Depth 10 | Set-Content -Path $file -Encoding UTF8
}
function Generate-Version-Props {
param(
[string]$assemblyVersion,
[string]$fileVersion,
[string]$informationalVersion,
[string]$packageVersion,
[string]$file = $(throw "file is a required parameter.")
)
$fileText = "<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. 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. See the License for the
specific language governing permissions and limitations
under the License.
-->
<Project>
<PropertyGroup Label=""Version Override Properties"">
<AssemblyVersion>$assemblyVersion</AssemblyVersion>
<FileVersion>$fileVersion</FileVersion>
<InformationalVersion>$informationalVersion</InformationalVersion>
<PackageVersion>$packageVersion</PackageVersion>
</PropertyGroup>
</Project>"
$dir = [System.IO.Path]::GetDirectoryName($file)
Ensure-Directory-Exists $dir
Write-Host "Generating version.props file: $(Normalize-FileSystemSlashes "$file")"
Track-Added-File $file
Out-File -filePath $file -encoding UTF8 -inputObject $fileText
}
function New-CountersObject ([string]$project, [string]$outcome, [int]$total, [int]$executed, [int]$passed, [int]$failed, [int]$warning, [int]$inconclusive) {
$counters = New-Object -TypeName PSObject
$fields = [ordered]@{Project=$project;Outcome=$outcome;Total=$total;Executed=$executed;Passed=$passed;Failed=$failed;Warning=$warning;Inconclusive=$inconclusive}
$counters | Add-Member -NotePropertyMembers $fields -TypeName Counters
return $counters
}
function Summarize-Test-Results([string[]]$frameworksToTest) {
# Workaround for issue when ForeGroundColor cannot be read. https://stackoverflow.com/a/26583010
$defaultForeground = (Get-Host).UI.RawUI.ForegroundColor
if ($defaultForeground -eq -1) {
$defaultForeground = 'White'
}
foreach ($framework in $frameworksToTest) {
pushd $baseDirectory
$testReports = Get-ChildItem -Path "$testResultsDirectory/$framework" -Recurse -File -Filter "*.trx" | ForEach-Object {
$_.FullName
}
popd
[int]$totalCountForFramework = 0
[int]$executedCountForFramework = 0
[int]$passedCountForFramework = 0
[int]$failedCountForFramework = 0
[int]$warningCountForFramework = 0
[int]$inconclusiveCountForFramework = 0
[string]$outcomeForFramework = 'Completed'
# HEADER FOR FRAMEWORK
Write-Host ""
Write-Host ""
Write-Host "**********************************************************************" -ForegroundColor Yellow
Write-Host "* *" -ForegroundColor Yellow
Write-Host "* Test Summary For $framework" -ForegroundColor Yellow
Write-Host "* *" -ForegroundColor Yellow
Write-Host "**********************************************************************" -ForegroundColor Yellow
foreach ($testReport in $testReports) {
$testName = [System.IO.Path]::GetFileName([System.IO.Path]::GetDirectoryName($testReport))
$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') {
$outcomeForFramework = $outcome
}
}
if ($reader.NodeType -eq [System.Xml.XmlNodeType]::Element -and $reader.Name -eq 'Counters') {
$counters = New-CountersObject `
-Project $testName `
-Outcome $outcome `
-Total $reader.GetAttribute('total') `
-Executed $reader.GetAttribute('executed') `
-Passed $reader.GetAttribute('passed') `
-Failed $reader.GetAttribute('failed') `
-Warning $reader.GetAttribute('warning') `
-Inconclusive $reader.GetAttribute('inconclusive')
$totalCountForFramework += $counters.Total
$executedCountForFramework += $counters.Executed
$passedCountForFramework += $counters.Passed
$failedCountForFramework += $counters.Failed
$warningCountForFramework += $counters.Warning
$inconclusiveCountForFramework += $counters.Inconclusive
$skippedCountForFramework += $counters.Skipped
$format = @{Expression={$_.Project};Label='Project';Width=35},
@{Expression={$_.Outcome};Label='Outcome';Width=7},
@{Expression={$_.Total};Label='Total';Width=6},
@{Expression={$_.Executed};Label='Executed';Width=8},
@{Expression={$_.Passed};Label='Passed';Width=6},
@{Expression={$_.Failed};Label='Failed';Width=6},
@{Expression={$_.Warning};Label='Warning';Width=7},
@{Expression={$_.Inconclusive};Label='Inconclusive';Width=14}
if ($counters.Failed -gt 0) {
$Counters | Format-Table $format
}
}
}
} finally {
$reader.Dispose()
}
}
# FOOTER FOR FRAMEWORK
#Write-Host "**********************************************************************" -ForegroundColor Magenta
#Write-Host "* *" -ForegroundColor Magenta
#Write-Host "* Totals For $framework" -ForegroundColor Magenta
#Write-Host "* *" -ForegroundColor Magenta
#Write-Host "**********************************************************************" -ForegroundColor Magenta
#Write-Host ""
$foreground = if ($outcomeForFramework -eq 'Failed') { 'Red' } else { 'Green' }
Write-Host "Result: " -NoNewline; Write-Host "$outcomeForFramework" -ForegroundColor $foreground
Write-Host ""
Write-Host "Total: $totalCountForFramework"
Write-Host "Executed: $executedCountForFramework"
$foreground = if ($failedCountForFramework -gt 0) { 'Green' } else { $defaultForeground }
Write-Host "Passed: " -NoNewline; Write-Host "$passedCountForFramework" -ForegroundColor $foreground
$foreground = if ($failedCountForFramework -gt 0) { 'Red' } else { $defaultForeground }
Write-Host "Failed: " -NoNewline; Write-Host "$failedCountForFramework" -ForegroundColor $foreground
$foreground = if ($failedCountForFramework -gt 0) { 'Yellow' } else { $defaultForeground }
Write-Host "Warning: " -NoNewline; Write-Host "$warningCountForFramework" -ForegroundColor $foreground
$foreground = if ($failedCountForFramework -gt 0) { 'Cyan' } else { $defaultForeground }
Write-Host "Inconclusive: " -NoNewline; Write-Host "$inconclusiveCountForFramework" -ForegroundColor $foreground
Write-Host ""
Write-Host "See the .trx logs in $(Normalize-FileSystemSlashes "$testResultsDirectory/$framework") for more details." -ForegroundColor DarkCyan
}
}
function Backup-Files([string[]]$paths) {
foreach ($path in $paths) {
Backup-File $path
}
}
function Backup-File([string]$path) {
if ($backupFiles -eq $true) {
Copy-Item $path "$path.bak" -Force
$backedUpFiles.Insert(0, $path)
} else {
Write-Host "Ignoring backup of file $(Normalize-FileSystemSlashes "$path")" -ForegroundColor DarkRed
}
}
function Restore-Files([string[]]$paths) {
foreach ($path in $paths) {
Restore-File $path
}
}
function Restore-File([string]$path) {
if ($backupFiles -eq $true) {
if (Test-Path "$path.bak") {
Move-Item "$path.bak" $path -Force
}
$backedUpFiles.Remove($path)
}
}
function Track-Added-Files([string[]]$paths) {
foreach ($path in $paths) {
Track-Added-File $path
}
}
function Track-Added-File([string]$path) {
if ($backupFiles -eq $true) {
$addedFiles.Insert(0, $path)
} else {
Write-Host "Ignoring tracking of file $(Normalize-FileSystemSlashes "$path")" -ForegroundColor DarkRed
}
}
function Delete-Added-Files([string[]]$paths) {
foreach ($path in $paths) {
Delete-Added-File $path
}
}
function Delete-Added-File([string]$path) {
if ($backupFiles -eq $true) {
if (Test-Path "$path") {
Remove-Item "$path" -Force
}
$addedFiles.Remove($path)
}
}
function Ensure-Directory-Exists([string] $path) {
if (!(Test-Path $path)) {
New-Item $path -ItemType Directory | Out-Null
}
}
function New-TemporaryDirectory {
$parent = [System.IO.Path]::GetTempPath()
[string] $name = [System.Guid]::NewGuid()
New-Item -ItemType Directory -Path (Join-Path $parent $name) | Out-Null
}
function Normalize-FileSystemSlashes([string]$path) {
$sep = [System.IO.Path]::DirectorySeparatorChar
return $($path -replace '/',$sep -replace '\\',$sep)
}