This repository has been archived by the owner on May 16, 2020. It is now read-only.
/
build.ps1
108 lines (93 loc) · 2.88 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
100
101
102
103
104
105
106
107
108
#requires -Version 6.0
[CmdletBinding(DefaultParameterSetName = 'Build')]
param(
[Parameter(ParameterSetName = 'Build')]
[ValidateSet('Debug', 'Release')]
[string]
$Configuration = 'Debug',
[Parameter(ParameterSetName = 'Build')]
[switch]
$Clean,
[Parameter(ParameterSetName = 'Test')]
[switch]
$Build,
[Parameter(ParameterSetName = 'Test')]
[switch]
$Test
)
$ErrorActionPreference = 'Stop'
$script:ModuleName = 'PSUnixUtilCompleters'
$script:OutDir = "$PSScriptRoot/out"
$script:OutModuleDir = "$script:OutDir/$script:ModuleName"
$script:SrcDir = "$PSScriptRoot/PSUnixUtilCompleters"
$script:Framework = 'netstandard2.0'
$script:ZshCompleterScriptLocation = "$script:OutModuleDir/zcomplete.sh"
$script:Artifacts = @{
"OnStart.ps1" = "OnStart.ps1"
"${script:ModuleName}.psd1" = "${script:ModuleName}.psd1"
"PSUnixUtilCompleters/bin/$Configuration/${script:Framework}/PSUnixUtilCompleters.dll" = 'PSUnixUtilCompleters.dll'
"PSUnixUtilCompleters/bin/$Configuration/${script:Framework}/PSUnixUtilCompleters.pdb" = 'PSUnixUtilCompleters.pdb'
"LICENSE" = "LICENSE.txt"
}
function Exec([scriptblock]$sb, [switch]$IgnoreExitcode)
{
$backupEAP = $script:ErrorActionPreference
$script:ErrorActionPreference = "Continue"
try
{
& $sb
# note, if $sb doesn't have a native invocation, $LASTEXITCODE will
# point to the obsolete value
if ($LASTEXITCODE -ne 0 -and -not $IgnoreExitcode)
{
throw "Execution of {$sb} failed with exit code $LASTEXITCODE"
}
}
finally
{
$script:ErrorActionPreference = $backupEAP
}
}
if ($PSCmdlet.ParameterSetName -eq 'Build' -or $Build)
{
try
{
$null = Get-Command dotnet -ErrorAction Stop
}
catch
{
throw 'Unable to find dotnet executable'
}
if ($Clean)
{
foreach ($path in $script:OutDir,"${script:SrcDir}/bin","${script:SrcDir}/obj")
{
if (Test-Path -Path $path)
{
Remove-Item -Force -Recurse -Path $path -ErrorAction Stop
}
}
}
Push-Location $script:SrcDir
try
{
Exec { dotnet build }
}
finally
{
Pop-Location
}
New-Item -ItemType Directory -Path $script:OutModuleDir -ErrorAction SilentlyContinue
foreach ($artifactEntry in $script:Artifacts.GetEnumerator())
{
Copy-Item -Path $artifactEntry.Key -Destination (Join-Path $script:OutModuleDir $artifactEntry.Value) -ErrorAction Stop
}
# We need the zsh completer script to drive zsh completions
Invoke-WebRequest -Uri 'https://raw.githubusercontent.com/Valodim/zsh-capture-completion/master/capture.zsh' -OutFile $script:ZshCompleterScriptLocation
}
if ($Test)
{
$pwsh = (Get-Process -Id $PID).Path
$testPath = "$PSScriptRoot/tests"
& $pwsh -c "Invoke-Pester '$testPath'"
}