forked from PowerShell/Polaris
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.ps1
87 lines (71 loc) · 2.42 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
#!/usr/bin/env pwsh
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
param(
[Parameter()]
[switch]
$Bootstrap,
[Parameter()]
[switch]
$Test,
[Parameter()]
[switch]
$Package
)
$NeededTools = @{
Pester = "Pester latest"
}
function needsPester() {
if (Get-Module -ListAvailable -Name Pester) {
return $false
}
return $true
}
function getMissingTools () {
$missingTools = @()
if (needsPester) {
$missingTools += $NeededTools.Pester
}
return $missingTools
}
function hasMissingTools () {
return ((getMissingTools).Count -gt 0)
}
if ($Bootstrap) {
$string = "Here is what your environment is missing:`n"
$missingTools = getMissingTools
if (($missingTools).Count -eq 0) {
$string += "* nothing!`n`n Run this script without a flag to build or a -Clean to clean."
}
else {
$missingTools | ForEach-Object { $string += "* $_`n" }
}
Write-Output "`n$string`n"
}
elseif (hasMissingTools) {
Write-Output "You are missing needed tools. Run './build.ps1 -Bootstrap' to see what they are."
}
else {
if ($Test) {
Push-Location $PSScriptRoot\Tests
$res = Invoke-Pester -OutputFormat NUnitXml -OutputFile TestsResults.xml -PassThru
if ($res.FailedCount -gt 0) { throw "$($res.FailedCount) tests failed." }
Pop-Location
}
if ($Package) {
if ((Test-Path "$PSScriptRoot\out")) {
Remove-Item -Path $PSScriptRoot\out -Recurse -Force
}
New-Item -ItemType directory -Path $PSScriptRoot\out
New-Item -ItemType directory -Path $PSScriptRoot\out\Polaris
Copy-Item -Path "$PSScriptRoot\Polaris.ps*1" -Destination "$PSScriptRoot\out\Polaris\" -Force
Copy-Item -Path "$PSScriptRoot\README.md" -Destination "$PSScriptRoot\out\Polaris\" -Force
Copy-Item -Path "$PSScriptRoot\LICENSE.txt" -Destination "$PSScriptRoot\out\Polaris\" -Force
Copy-Item -Path "$PSScriptRoot\lib" -Destination "$PSScriptRoot\out\Polaris\" -Force -Recurse
Copy-Item -Path "$PSScriptRoot\Public" -Destination "$PSScriptRoot\out\Polaris\" -Force -Recurse
Copy-Item -Path "$PSScriptRoot\Private" -Destination "$PSScriptRoot\out\Polaris\" -Force -Recurse
if ($null -ne $env:TF_BUILD) {
Compress-Archive "$PSScriptRoot/out/Polaris/" (Join-Path $env:BUILD_ARTIFACTSTAGINGDIRECTORY Polaris.zip)
}
}
}