-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.ps1
80 lines (69 loc) · 2.18 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
#!/usr/bin/env pwsh
param (
[string] $Configuration = "Release",
[string] $Version = ""
)
$SOLUTION_DIR = Resolve-Path "."
$ARTIFACTS = Join-Path $SOLUTION_DIR "artifacts"
$CONFIGURATION = $Configuration
# CLEAN
write-host "< clean >" -f cyan
if (-not (Test-Path $ARTIFACTS)) {
New-Item $ARTIFACTS -ItemType Directory | Out-Null
}
Get-ChildItem $ARTIFACTS | Remove-Item -Recurse -Force
& dotnet clean -v q /nologo
if ($LASTEXITCODE -ne 0) {
Write-Host "'dotnet clean' failed with $LASTEXITCODE" -f red
exit $LASTEXITCODE
}
write-host "Dropped build output"
# VERSION
write-host "< version >" -f cyan
$VERSION = $Version
if ([string]::IsNullOrEmpty($Version)) {
if ((git tag | measure).Count -eq 0) {
$VERSION = "0.0.0-dev"
write-host "there are no tags! Will use '$VERSION' as version number" -f red
}
else {
$VERSION = "$(git describe --abbrev=0 --tags)"
}
}
if ($env:APPVEYOR) {
$BUILD_NUMBER = [int]($env:APPVEYOR_BUILD_NUMBER)
if ($env:APPVEYOR_REPO_TAG -ne "true") {
$tag = $(git log -n 1 --pretty=format:%h)
$VERSION = "$VERSION-$tag+$env:APPVEYOR_BUILD_NUMBER"
}
}
write-host "version number : $VERSION"
if ($env:APPVEYOR) {
appveyor SetVariable -Name VERSION -Value $VERSION
appveyor UpdateBuild -Version "$VERSION"
}
# COMPILE
write-host "< compile >" -f cyan
& dotnet build -v q -c $CONFIGURATION /nologo /p:Version=$VERSION
if ($LASTEXITCODE -ne 0) {
Write-Host "'dotnet build' failed with $LASTEXITCODE" -f red
exit $LASTEXITCODE
}
# TEST
write-host "< test >" -f cyan
& dotnet test -v q -c $CONFIGURATION --no-restore --no-build /nologo
if ($LASTEXITCODE -ne 0) {
Write-Host "'dotnet test' failed with $LASTEXITCODE" -f red
exit $LASTEXITCODE
}
# PACK
write-host "< pack >" -f cyan
& dotnet pack -v q -c $CONFIGURATION /p:Version=$VERSION --include-symbols --include-source `
--no-restore --no-build --output $ARTIFACTS ./CLI.sln /nologo
if ($LASTEXITCODE -ne 0) {
Write-Host "`"dotnet pack`" failed with $LASTEXITCODE"
exit $LASTEXITCODE
}
Write-Host "Generated packages:"
gci $ARTIFACTS -file -filter *.nupkg | % { write-host "`t$($_.Name)" }
Write-Host "Completed" -f Green