-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.ps1
78 lines (68 loc) · 1.9 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
# Copyright (c) James Truher 2019. All rights reserved.
# Licensed under the MIT License.
param ( [switch]$package, [switch]$test, [switch]$clean, [switch]$MakeModule )
$ModRoot = "${PSScriptRoot}"
$SrcRoot = "${ModRoot}/src"
$DocRoot = "${ModRoot}/docs"
$TstRoot = "${ModRoot}/test"
$ModName = "EnvironmentVariableCmdlet"
function Export-Module {
$target = "${ModRoot}/${ModName}"
if ( ! ( Test-Path $target) ) {
$null = New-Item -type Directory ${target}
}
Copy-Item "${ModRoot}/${ModName}.psd1" $target -force
Copy-Item "${SrcRoot}/bin/Debug/netstandard2.0/publish/${ModName}.dll" $target -force
$null = New-externalhelp -path ${DocRoot} -OutputPath "${target}/en-US" -force
}
function Test-IsAdmin
{
if ( $IsWindows ) {
$windowsIdentity = [Security.Principal.WindowsIdentity]::GetCurrent()
$windowsPrincipal = new-object 'Security.Principal.WindowsPrincipal' $windowsIdentity
if ($windowsPrincipal.IsInRole("Administrators") -eq 1) { $true } else { $false }
}
else {
$false
}
}
if ( $clean ) {
$null = dotnet clean
return
}
try {
Push-Location src
$result = dotnet publish
if ( ! $? ) {
throw "$result"
}
}
finally {
Pop-Location
}
if ( $test ) {
Export-Module
try {
Push-Location ${ModRoot}
if ( $IsWindows ) {
if ( Test-IsAdmin ) {
pwsh -c "Import-Module '${ModRoot}/${ModName}'; Set-Location ${TstRoot}; Invoke-Pester"
}
else {
pwsh -c "Import-Module '${ModRoot}/${ModName}'; Set-Location ${TstRoot}; Invoke-Pester -Exclude RequiresAdminOnWindows"
}
}
else {
pwsh -c "Import-Module '${ModRoot}/${ModName}'; Set-Location ${TstRoot}; Invoke-Pester"
}
}
finally {
Pop-Location
}
}
if ( $package ) {
dotnet pack
}
if ( $MakeModule ) {
Export-Module
}