This repository has been archived by the owner on Sep 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.ps1
99 lines (79 loc) · 2.26 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
#!/usr/bin/env bash
<#
.SYNOPSIS
Build project
.DESCRIPTION
.PARAMETER
#>
[CmdletBinding(SupportsShouldProcess=$false)]
Param (
[Parameter()]
[switch]$BinaryLog,
[Parameter()]
[switch]$Pack,
[ValidateSet('Debug', 'Release')]
[string]$Configuration='Debug',
[Parameter()]
[string]$Projects,
[Parameter()]
[switch]$Clean,
[Parameter()]
[switch]$Test,
[Parameter()]
[string]$BuildNumber
)
function Create-Directory([string[]] $path) {
if (!(Test-Path $path)) {
New-Item -path $path -force -itemType 'Directory' | Out-Null
}
}
$HeaderColor = 'Green'
$BuildNumber = $BuildNumber -replace "['.']",''
$DotNet = & "$PSScriptRoot\azure-pipelines\Get-Dotnet.ps1"
$RepoRoot = $PSScriptRoot
$ArtifactsRoot = Join-Path $RepoRoot 'artifacts'
$LogDir = Join-Path (Join-Path $ArtifactsRoot 'log') $Configuration
$TestResultRoot = Join-Path (Join-Path $ArtifactsRoot 'TestResults') $Configuration
if ($Clean){
if ((Test-Path $ArtifactsRoot)){
Write-Host "Clean Artifacts..." -ForegroundColor $HeaderColor
Remove-Item $ArtifactsRoot -Recurse -Force -Confirm:$false
}
exit $lastexitcode
}
Create-Directory $LogDir
$MsBuildArgs = "-property:Configuration=$Configuration"
if ($Projects){
$Projects = ($Projects.Split(';').ForEach({Resolve-Path $_}) -join ';')
Write-Host "Build projects $Projects" -ForegroundColor $HeaderColor
$MsBuildArgs = $Projects + " " + $MsBuildArgs
}else{
$sln = 'AzCopy.Net.sln '
$MsBuildArgs = $sln + $MsBuildArgs
}
if ($BinaryLog){
Write-Host "Write BinaryLog to $LogDir" -ForegroundColor $HeaderColor
$MsBuildArgs += ' -bl:' + (Join-Path $LogDir 'Build.binlog')
}
if ($Pack){
$MsBuildArgs += ' -target:Build,Pack'
}
Push-Location $PSScriptRoot
try{
Write-Host "MsBuildArgs $MsBuildArgs" -ForegroundColor $HeaderColor
$p = Start-Process $DotNet ('msbuild','-restore', $MsBuildArgs, "-property:BUILDNUMBER=$BuildNumber") -NoNewWindow -Wait -PassThru
if ($p.ExitCode -ne 0){
throw "Build task fail"
}
if ($Test){
Write-Host "Start Testing..." $HeaderColor
$p = Start-Process $DotNet "test $sln -v n -r $TestResultRoot -l trx --no-build -c $Configuration --collect ""Code Coverage""" -NoNewWindow -Wait -PassThru
}
}
catch{
Write-Error $error[0]
throw $p.ExitCode
}
finally {
Pop-Location
}