-
Notifications
You must be signed in to change notification settings - Fork 162
Expand file tree
/
Copy pathbuild.ps1
More file actions
126 lines (100 loc) · 4.47 KB
/
build.ps1
File metadata and controls
126 lines (100 loc) · 4.47 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
[CmdletBinding(DefaultParameterSetName = 'Build')]
param(
[Parameter(ParameterSetName = "Build")]
[switch] $Clean,
[Parameter(ParameterSetName = "Build")]
[ValidateSet("Debug", "Release")]
[string] $Configuration = "Debug",
[string] $OutputDir = "$PSScriptRoot/out",
[Parameter(ParameterSetName = "Test", Mandatory)]
[switch] $Test,
[Parameter(ParameterSetName = "Test", Position = 0)]
[string]$TestPath,
[Parameter(ParameterSetName = "Test")]
[string] $XUnitLogPath = "$PSScriptRoot/xunit.tests.xml",
[Parameter(ParameterSetName = "Test")]
[string] $PesterLogPath = "$PSScriptRoot/pester.tests.xml",
[Parameter(ParameterSetName = "Package")]
[switch]$Package
)
$ModuleName = "Microsoft.PowerShell.PlatyPS"
if ($PSCmdlet.ParameterSetName -eq 'Build') {
try {
if ($Clean) {
if (Test-Path $OutputDir) {
Write-Verbose -Verbose "Cleaning output directory: $OutputDir"
Remove-Item -Recurse -path $OutputDir -Force
}
$binFolder = "$PSScriptRoot/src/bin"
if (Test-Path $binFolder) {
Write-Verbose -Verbose "Cleaning output directory: $binFolder"
Remove-Item -Recurse -path $binFolder -Force
}
$objFolder = "$PSScriptRoot/src/obj"
if (Test-Path $objFolder) {
Write-Verbose -Verbose "Cleaning output directory: $objFolder"
Remove-Item -Recurse -path $objFolder -Force
}
}
Push-Location "$PSScriptRoot/src"
dotnet build --configuration $Configuration
if ($LASTEXITCODE -ne 0) {
throw "Build failure."
}
$expectedBuildPath = "./bin/$Configuration/net472/"
$expectedDllPath = "$expectedBuildPath/${ModuleName}.dll"
$expectedPdbPath = "$expectedBuildPath/${ModuleName}.pdb"
if (-not (Test-Path $expectedDllPath)) {
throw "Build did not succeed."
}
$moduleRoot = New-Item -Item Directory -Path "$OutputDir/${ModuleName}" -Force
$depsFolder = New-Item -Item Directory -Path "$moduleRoot/Dependencies" -Force
$moduleFiles = "$PSScriptRoot/src/${ModuleName}.psd1", "${PSScriptRoot}/src/${ModuleName}.psm1", "$PSScriptRoot/src/${ModuleName}.Format.ps1xml",$expectedDllPath
if ($configuration -eq "debug") {
$moduleFiles += $expectedPdbPath
}
$neededAssemblies = "System.Buffers.dll", "System.Memory.dll",
"System.Numerics.Vectors.dll", "System.Runtime.CompilerServices.Unsafe.dll",
"Markdig.Signed.dll","YamlDotNet.dll"
$neededAssemblyLocations = $neededAssemblies | ForEach-Object { "${expectedBuildPath}/${_}" }
Copy-Item -Path $neededAssemblyLocations -Destination $depsFolder -Verbose
Copy-Item -Path $moduleFiles -Destination $moduleRoot -Verbose
}
finally {
Pop-Location
}
}
elseif ($PSCmdlet.ParameterSetName -eq 'Test') {
$pesterTestRoot = "$PSScriptRoot/test/Pester"
Write-Verbose "Executing Pester tests under $pesterTestRoot" -Verbose
$sb = "Import-Module -Max 4.99 Pester
`$PSModuleAutoloadingPreference = 'none'
`$env:PSModulePath = '${OutputDir}$([io.path]::PathSeparator)${env:PSModulePath}'
Import-Module -Name '${ModuleName}' -Force
Push-Location $pesterTestRoot
Invoke-Pester -Outputformat nunitxml -outputfile $PesterLogPath $TestPath"
write-verbose -verbose -message "$sb"
# we need to run on both pwsh and powershell
$PSEXE = (Get-Process -Id $PID).MainModule.FileName
Write-Verbose -Verbose -Message ("Running tests on PowerShell Version: " + $PSVersionTable.PSVersion)
& $PSEXE -noprofile -c "$sb"
$results = [xml](Get-Content $PesterLogPath)
if ($results."test-results".failures -ne 0) {
throw "Pester Tests failed."
}
}
if ($Package) {
if (! (Test-Path "$PSScriptRoot/out/Microsoft.PowerShell.PlatyPS")) {
throw "Module is missing, run build first"
}
$moduleDir = Join-Path $OutputDir $ModuleName
$localRepoName = [guid]::newguid().ToString("N")
try {
Register-PSRepository -Name $localRepoName -SourceLocation $PSScriptRoot -PublishLocation $PSScriptRoot -InstallationPolicy Trusted
Publish-Module -Repository $localRepoName -Path $moduleDir
}
finally {
Unregister-PSRepository -Name $localRepoName -ErrorAction SilentlyContinue
}
Get-ChildItem -Path $PSScriptRoot/*.nupkg
}