-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuild.ps1
64 lines (52 loc) · 2.19 KB
/
Build.ps1
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
#Requires -Version 5.0
Begin {
$ErrorActionPreference = "stop"
}
Process {
function Exec([scriptblock]$Command) {
& $Command
if ($LASTEXITCODE -ne 0) {
throw ("An error occurred while executing command: {0}" -f $Command)
}
}
function Compare-GeneratedAndExpectedFiles {
param(
[Parameter(Mandatory=$true)]
[string]$generatedFilePath,
[Parameter(Mandatory=$true)]
[string]$expectedFilePath
)
# Compare the generated file with the expected file
$generatedFileContent = Get-Content -Path $generatedFilePath
$expectedFileContent = Get-Content -Path $expectedFilePath
$diff = Compare-Object -ReferenceObject $generatedFileContent -DifferenceObject $expectedFileContent
if ($diff) {
$diff | Format-Table
Write-Error "The generated file does not match the expected file."
exit 1
} else {
Write-Host "The generated file matches the expected file."
}
}
$workingDir = Join-Path $PSScriptRoot "src"
$outputDir = Join-Path $PSScriptRoot ".output"
$nupkgsPath = Join-Path $outputDir "*.nupkg"
$projectPath = Join-Path $workingDir "tests/WebApi.OpenAPI.SystemTest"
$generatedFilePath = Join-Path $projectPath "openapi-v1.yaml"
$expectedFilePath = Join-Path $workingDir "tests/expected-openapi-document.yaml"
try {
Push-Location $workingDir
Remove-Item $outputDir -Force -Recurse -ErrorAction SilentlyContinue
Exec { & dotnet clean -c Release }
Exec { & dotnet build -c Release }
Exec { & dotnet test -c Release --no-build --results-directory "$outputDir" --no-restore -l "trx" -l "console;verbosity=detailed" }
Exec { & Compare-GeneratedAndExpectedFiles -generatedFilePath $generatedFilePath -expectedFilePath $expectedFilePath }
Exec { & dotnet pack -c Release -o "$outputDir" }
if (($null -ne $env:NUGET_SOURCE ) -and ($null -ne $env:NUGET_API_KEY)) {
Exec { & dotnet nuget push "$nupkgsPath" -s $env:NUGET_SOURCE -k $env:NUGET_API_KEY --skip-duplicate }
}
}
finally {
Pop-Location
}
}