-
Notifications
You must be signed in to change notification settings - Fork 21
/
build.ps1
63 lines (51 loc) · 1.85 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
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 "Archive `n '$file' `n to `n '$archiveFile'"
Compress-Archive -Force -Path $file -DestinationPath $archiveFile
}
Function GetVersion() {
$gitCommand = Get-Command -Name git
$nearestTag = & $gitCommand describe --exact-match --tags HEAD
if(-Not $?) {
Info "The commit is not tagged. Use 'v0.0-dev' as a tag instead"
$nearestTag = "v0.0-dev"
}
$commitHash = & $gitCommand rev-parse --short HEAD
CheckReturnCodeOfPreviousCommand "Failed to get git commit hash"
return "$($nearestTag.Substring(1))-$commitHash"
}
Function ForceCopy($file, $dstFolder) {
Info "Copy `n '$file' `n to `n '$dstFolder'"
New-Item $publishFolder -Force -ItemType "directory" > $null
Copy-Item $buildResultExecutable -Destination $publishFolder -Force
}
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$root = Resolve-Path "$PSScriptRoot"
$buildRoot = "$root/build"
$buildResultsFolder = "$buildRoot/Release/net472"
$projectName = "BluetoothDevicePairing"
$buildResultExecutable = "$buildResultsFolder/$projectName.exe"
$publishFolder = "$buildRoot/Publish"
$version = GetVersion
Info "Run 'dotnet build'. version=$version"
dotnet build `
--configuration Release `
/property:DebugType=None `
/property:Version=$version `
$root/BluetoothDevicePairing.sln
CheckReturnCodeOfPreviousCommand "'dotnet build' command failed"
ForceCopy $buildResultExecutable $publishFolder
CreateZipArchive $publishFolder/BluetoothDevicePairing.exe $publishFolder/BluetoothDevicePairing.zip