-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ps1
74 lines (60 loc) · 1.89 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
Function Info($msg) {
Write-Host -ForegroundColor DarkGreen "`nINFO: $msg`n"
}
Function Error($msg) {
Write-Host `n`n
Write-Error $msg
exit 1
}
Function CheckReturnCodeOfPreviousCommand($msg) {
if(-Not $?) {
Error "${msg}. Error code: $LastExitCode"
}
}
Function CreateZipArchive($file, $archiveFile) {
Info "Create a zip archive from `n '$file' `n to `n '$archiveFile'"
Compress-Archive -Force -Path $file -DestinationPath $archiveFile
}
Function GetVersion() {
$gitCommand = Get-Command -Name git
$tag = & $gitCommand describe --exact-match --tags HEAD
if(-Not $?) {
Info "The commit is not tagged. Use 'v0.0-dev' as a tag instead"
$tag = "v0.0-dev"
}
$commitHash = & $gitCommand rev-parse --short HEAD
CheckReturnCodeOfPreviousCommand "Failed to get git commit hash"
return "$($tag.Substring(1))-$commitHash"
}
Function ForceCopy($srcFile, $dstFile) {
Info "Copy `n '$srcFile' `n to `n '$dstFile'"
New-Item $dstFile -Force -ItemType File > $null
Copy-Item $srcFile -Destination $dstFile -Force
}
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$root = Resolve-Path $PSScriptRoot
$buildDir = "$root/build"
$publishDir = "$buildDir/publish"
$version = GetVersion
Info "version=$version"
Info "Build the project"
dotnet build `
--nologo `
--configuration Release `
-verbosity:minimal `
/property:DebugType=None `
/property:Version=$version `
"$root/Handle2.sln"
CheckReturnCodeOfPreviousCommand "Cmake generation phase failed"
Info "Run tests"
dotnet test `
--nologo `
--no-build `
--configuration Release `
-verbosity:minimal `
--logger:"console;verbosity=normal" `
"$root/Handle2.sln"
CheckReturnCodeOfPreviousCommand "Tests failed"
ForceCopy "$buildDir/Release/Handle2/net462/Handle2.exe" "$publishDir/Handle2.exe"
CreateZipArchive "$publishDir/Handle2.exe" "$publishDir/Handle2.zip"