-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.ps1
95 lines (77 loc) · 2.5 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
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 GetVersion() {
$gitCommand = Get-Command -Name git
try { $tag = & $gitCommand describe --exact-match --tags HEAD } catch { }
if(-Not $?) {
Info "The commit is not tagged. Use 'v0.0-dev' as a version instead"
$tag = "v0.0-dev"
}
$commitHash = & $gitCommand rev-parse --short HEAD
CheckReturnCodeOfPreviousCommand "Failed to get git commit hash"
return "$($tag.Substring(1))-$commitHash"
}
Function GetInstallerVersion($version) {
return $version.Split("-")[0];
}
Function FindMsBuild() {
$vswhereCommand = Get-Command -Name "${Env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
$msbuild = `
& $vswhereCommand `
-latest `
-requires Microsoft.Component.MSBuild `
-find MSBuild\**\Bin\MSBuild.exe `
| select-object -first 1
if(!$msbuild)
{
Error "Can't find MsBuild"
}
Info "MsBuild found: `n $msbuild"
return $msbuild
}
Function RemoveFileIfExists($fileName) {
Info "Remove '$fileName'"
Remove-Item $fileName -Force -Recurse -ErrorAction SilentlyContinue
}
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$ProgressPreference = "SilentlyContinue"
$root = Resolve-Path "$PSScriptRoot"
$buildDir = "$root/build"
$publishDir = "$buildDir/Release/Installer"
$projectName = "ShowWhatProcessLocksFile"
$version = GetVersion
$installerVersion = GetInstallerVersion $version
$msbuild = FindMsBuild
Info "Version: '$version'. InstallerVersion: '$installerVersion'"
Info "Build project"
& $msbuild `
/property:RestorePackagesConfig=true `
/property:Configuration=Release `
/property:DebugType=None `
/property:Version=$version `
/property:InstallerVersion=$installerVersion `
/verbosity:Minimal `
/target:"restore;build" `
$root/$projectName.sln
CheckReturnCodeOfPreviousCommand "build failed"
Info "Run tests"
dotnet test `
--no-build `
--configuration Release `
$root/$projectName.sln
CheckReturnCodeOfPreviousCommand "tests failed"
RemoveFileIfExists "$publishDir/${projectName}.msi.zip"
Info "Create zip archive from msi installer"
Compress-Archive -Path "$publishDir/$projectName.msi" -DestinationPath "$publishDir/${projectName}.msi.zip"