-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.ps1
84 lines (72 loc) · 1.98 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
[CmdletBinding()]
param(
[switch]
$Bootstrap,
[switch]
$Test,
[switch]
$Publish
)
# Bootstrap step
if ($Bootstrap.IsPresent)
{
Write-Host "Validate and install missing prerequisits for building ..."
# For testing
if (-not (Get-Module -Name Pester -ListAvailable))
{
Write-Warning "Module 'Pester' is missing. Installing 'Pester' ..."
Install-Module -Name Pester -Scope CurrentUser -Force
}
}
# Test step
if ($Test.IsPresent)
{
if (-not (Get-Module -Name Pester -ListAvailable))
{
throw "Cannot find the 'Pester' module. Please specify '-Bootstrap' to install build dependencies."
}
if ($env:TF_BUILD)
{
$res = Invoke-Pester "$PSScriptRoot/tests" -OutputFormat NUnitXml -OutputFile TestResults.xml -PassThru
if ($res.FailedCount -gt 0)
{
throw "$($res.FailedCount) tests failed."
}
}
else
{
$res = Invoke-Pester -Path "$PSScriptRoot/test" -PassThru
}
}
#Publish step
if ($Publish.IsPresent)
{
if ((Test-Path .\output))
{
Remove-Item -Path .\Output -Recurse -Force
}
# Copy Module Files to Output Folder
if (-not (Test-Path .\output\PSRES))
{
$null = New-Item -Path .\output\PSRES -ItemType Directory
}
Copy-Item -Path '.\src\*' -Filter *.* -Recurse -Destination .\output\PSRES -Force
# Copy Module README file
Copy-Item -Path '.\README.md' -Destination .\output\PSRES -Force
# Publish Module to PowerShell Gallery
Try
{
# Build a splat containing the required details and make sure to Stop for errors which will trigger the catch
$params = @{
Path = ('{0}\Output\PSRES' -f $PSScriptRoot )
NuGetApiKey = $env:psgallery
ErrorAction = 'Stop'
}
Publish-Module @params
Write-Output -InputObject ('PSRES PowerShell Module version published to the PowerShell Gallery')
}
Catch
{
throw $_
}
}