forked from giraffe-fsharp/Giraffe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.ps1
150 lines (116 loc) · 4.33 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
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
# ----------------------------------------------
# Build script
# ----------------------------------------------
param
(
[switch] $Release,
[switch] $IncludeTests,
[switch] $IncludeSamples,
[switch] $All,
[switch] $Pack,
[switch] $Run,
[switch] $OnlyNetStandard
)
$ErrorActionPreference = "Stop"
# ----------------------------------------------
# Helper functions
# ----------------------------------------------
function Invoke-Cmd ($cmd)
{
Write-Host $cmd -ForegroundColor DarkCyan
$command = "cmd.exe /C $cmd"
Invoke-Expression -Command $command
if ($LastExitCode -ne 0) { Write-Error "An error occured when executing '$cmd'."; return }
}
function Write-DotnetVersion
{
$dotnetVersion = Invoke-Cmd "dotnet --version"
Write-Host ".NET Core runtime version: $dotnetVersion" -ForegroundColor Cyan
}
function dotnet-restore ($project, $argv) { Invoke-Cmd "dotnet restore $project $argv" }
function dotnet-build ($project, $argv) { Invoke-Cmd "dotnet build $project $argv" }
function dotnet-run ($project, $argv) { Invoke-Cmd "dotnet run --project $project $argv" }
function dotnet-test ($project, $argv) { Invoke-Cmd "dotnet test $project $argv" }
function dotnet-pack ($project, $argv) { Invoke-Cmd "dotnet pack $project $argv" }
function Test-Version ($project)
{
if ($env:APPVEYOR_REPO_TAG -eq $true)
{
Write-Host "Matching version against git tag..." -ForegroundColor Magenta
[xml] $xml = Get-Content $project
[string] $version = $xml.Project.PropertyGroup.Version
[string] $gitTag = $env:APPVEYOR_REPO_TAG_NAME
Write-Host "Project version: $version" -ForegroundColor Cyan
Write-Host "Git tag version: $gitTag" -ForegroundColor Cyan
if (!$gitTag.EndsWith($version))
{
Write-Error "Version and Git tag do not match."
}
}
}
function Update-AppVeyorBuildVersion ($project)
{
if ($env:APPVEYOR -eq $true)
{
Write-Host "Updating AppVeyor build version..." -ForegroundColor Magenta
[xml]$xml = Get-Content $project
$version = $xml.Project.PropertyGroup.Version
$buildVersion = "$version-$env:APPVEYOR_BUILD_NUMBER"
Write-Host "Setting AppVeyor build version to $buildVersion."
Update-AppveyorBuild -Version $buildVersion
}
}
function Remove-OldBuildArtifacts
{
Write-Host "Deleting old build artifacts..." -ForegroundColor Magenta
Get-ChildItem -Include "bin", "obj" -Recurse -Directory `
| ForEach-Object {
Write-Host "Removing folder $_" -ForegroundColor DarkGray
Remove-Item $_ -Recurse -Force }
}
# ----------------------------------------------
# Main
# ----------------------------------------------
$giraffe = ".\src\Giraffe\Giraffe.fsproj"
Update-AppVeyorBuildVersion $giraffe
Test-Version $giraffe
Write-DotnetVersion
Remove-OldBuildArtifacts
$configuration = if ($Release.IsPresent) { "Release" } else { "Debug" }
Write-Host "Building Giraffe..." -ForegroundColor Magenta
dotnet-restore $giraffe
$framework = if ($OnlyNetStandard.IsPresent) { "-f netstandard1.6" } else { "" }
dotnet-build $giraffe "-c $configuration $framework"
if ($All.IsPresent -or $IncludeTests.IsPresent)
{
Write-Host "Building and running tests..." -ForegroundColor Magenta
$giraffeTests = ".\tests\Giraffe.Tests\Giraffe.Tests.fsproj"
dotnet-restore $giraffeTests
dotnet-build $giraffeTests
dotnet-test $giraffeTests
}
if ($All.IsPresent -or $IncludeSamples.IsPresent)
{
Write-Host "Building and testing samples..." -ForegroundColor Magenta
$sampleApp = ".\samples\SampleApp\SampleApp\SampleApp.fsproj"
$sampleAppTests = ".\samples\SampleApp\SampleApp.Tests\SampleApp.Tests.fsproj"
dotnet-restore $sampleApp
dotnet-build $sampleApp
dotnet-restore $sampleAppTests
dotnet-build $sampleAppTests
dotnet-test $sampleAppTests
}
if ($Run.IsPresent)
{
Write-Host "Launching sample application..." -ForegroundColor Magenta
$sampleApp = ".\samples\SampleApp\SampleApp\SampleApp.fsproj"
dotnet-restore $sampleApp
dotnet-build $sampleApp
dotnet-run $sampleApp
}
if ($Pack.IsPresent)
{
Write-Host "Packaging Giraffe and giraffe-template..." -ForegroundColor Magenta
dotnet-pack $giraffe "-c $configuration"
Invoke-Cmd "nuget pack template/giraffe-template.nuspec"
}