forked from domaindrivendev/Swashbuckle.AspNetCore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-definition.ps1
126 lines (92 loc) · 3.7 KB
/
build-definition.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
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
Properties {
# This number will be used to replace the * in all versions of all libraries.
# This should be overwritten by a CI system like VSTS, AppVeyor, TeamCity, ...
$VersionSuffix = ""
# The build configuration used for compilation
$BuildConfiguration = "Release"
# The folder in which all output artifacts should be placed
$ArtifactsPath = "artifacts"
# Artifacts-subfolder in which NuGet packages should be placed
$ArtifactsPathNuGet = "nuget"
# A list of projects for which NuGet packages should be created
$NugetLibraries = @(
"src/Swashbuckle.AspNetCore",
"src/Swashbuckle.AspNetCore.Swagger",
"src/Swashbuckle.AspNetCore.SwaggerGen",
"src/Swashbuckle.AspNetCore.SwaggerUI"
)
if ($env:APPVEYOR -eq "True") {
if ($env:APPVEYOR_REPO_TAG -ne "true") {
$VersionSuffix = "preview-" + $env:APPVEYOR_BUILD_NUMBER.PadLeft(4, '0')
} elseif ($env:APPVEYOR_REPO_TAG_NAME.Contains("-")) {
$VersionSuffix = $env:APPVEYOR_REPO_TAG_NAME.SubString(6) # i.e. the part after "-"
}
}
}
FormatTaskName ("`n" + ("-"*25) + "[{0}]" + ("-"*25) + "`n")
Task Default -depends init, clean, dotnet-restore, bower-restore, dotnet-build, dotnet-test, dotnet-pack
Task init {
Write-Host "VersionSuffix: $VersionSuffix"
Write-Host "BuildConfiguration: $BuildConfiguration"
Write-Host "ArtifactsPath: $ArtifactsPath"
Write-Host "ArtifactsPathNuGet: $ArtifactsPathNuGet"
Assert ($VersionSuffix -ne $null) "Property 'VersionSuffix' may not be null."
Assert ($BuildConfiguration -ne $null) "Property 'BuildConfiguration' may not be null."
Assert ($ArtifactsPath -ne $null) "Property 'ArtifactsPath' may not be null."
Assert ($ArtifactsPathNuGet -ne $null) "Property 'ArtifactsPathNuGet' may not be null."
}
Task clean {
if (Test-Path $ArtifactsPath) { Remove-Item -Path $ArtifactsPath -Recurse -Force -ErrorAction Ignore }
New-Item $ArtifactsPath -ItemType Directory -ErrorAction Ignore | Out-Null
Write-Host "Created artifacts folder '$ArtifactsPath'"
}
Task dotnet-restore {
exec { dotnet restore -v Minimal }
}
Task bower-restore {
exec { cd src/Swashbuckle.AspNetCore.SwaggerUI }
exec { bower install }
exec { cd ../../ }
}
Task dotnet-build {
if ($VersionSuffix.Length -gt 0) {
exec { dotnet build -c $BuildConfiguration --version-suffix $VersionSuffix }
} else {
exec { dotnet build -c $BuildConfiguration }
}
}
Task dotnet-test {
$testFailed = $false
# Find all projects that are directly under the tests folder
Get-ChildItem -Path "test\**\*.csproj" | ForEach-Object {
Write-Host ""
Write-Host "Testing $library"
Write-Host ""
dotnet test $_.FullName -c $BuildConfiguration --no-build
if ($LASTEXITCODE -ne 0) {
$testFailed = $true
}
}
if ($testFailed) {
throw "Tests for at least one library failed"
}
}
Task dotnet-pack {
if ($NugetLibraries -eq $null -or $NugetLibraries.Count -eq 0) {
Write-Host "No NugetLibraries configured"
return
}
$NugetLibraries | ForEach-Object {
$library = $_
$outputPath = Join-Path $ArtifactsPath $ArtifactsPathNuGet
$fullOutputPath = Join-Path $env:APPVEYOR_BUILD_FOLDER $outputPath
Write-Host ""
Write-Host "Packaging $library to $fullOutputPath"
Write-Host ""
if ($VersionSuffix.Length -gt 0) {
exec { dotnet pack $library -c $BuildConfiguration --no-build -o $fullOutputPath --version-suffix $VersionSuffix }
} else {
exec { dotnet pack $library -c $BuildConfiguration --no-build -o $fullOutputPath }
}
}
}