-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
build.ps1
105 lines (87 loc) · 2.97 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
[cmdletBinding()]
param(
[Parameter()]
[Switch]
$Build,
[Parameter()]
[Switch]
$TestPrePublish,
[Parameter()]
[Switch]
$TestPostPublish,
[Parameter()]
[Switch]
$DeployToGallery,
[Parameter()]
[Switch]
$Choco,
[Parameter()]
[string]
$SemVer = $(
if (Get-Command gitversion -ErrorAction SilentlyContinue) {
(gitversion | ConvertFrom-Json).LegacySemVerPadded
}
)
)
process {
$root = Split-Path -Parent $MyInvocation.MyCommand.Definition
switch ($true) {
(-not $env:CI) {
. $PSScriptRoot\Requirements.ps1
}
$Build {
Build-Module -SemVer $SemVer
}
$TestPrePublish {
if (Test-Path $root\Output\NexuShell) {
if ($env:PSModulePath.Split(';') -notcontains "$root\Output") {
$env:PSModulePath = "$root\Output;$env:PSModulePath"
}
Import-Module NexuShell
}
$TestConfiguration = New-PesterConfiguration @{
Run = @{
Path = "$root\tests"
}
TestResult = @{
Enabled = $true
OutputPath = "$root\TestResults.xml"
OutputFormat = "JUnitXml"
}
Output = @{
Verbosity = "Detailed"
}
CodeCoverage = @{
Enabled = $true
Path = (Get-ChildItem $root\Output\NexuShell -Recurse -Filter '*.ps*1').FullName
OutputPath = "$root\Coverage.xml"
}
}
if (Test-Path $TestConfiguration.Run.Path.Value) {
Invoke-Pester -Configuration $TestConfiguration
}
}
$TestPostPublish {
Install-Module NexuShell -Force
Import-Module PoshBot -Force
Invoke-Pester "$root\tests\*.ps1"
}
$DeployToGallery {
Publish-Module -Path "$root\Output\NexuShell" -NuGetApiKey $env:NugetApiKey
}
$Choco {
$PackageSource = Join-Path $root "src\nuget"
$Nuspec = Get-ChildItem $PackageSource -recurse -filter *.nuspec
Copy-Item -Path $root\LICENSE -Destination $PackageSource
Compress-Archive -Path $root\Output\* -DestinationPath $PackageSource\tools\NexuShell.zip -Force #Added force to allow local testing without shenanigans
if (Test-Path "$PackageSource\tools\NexuShell.zip") {
choco pack $Nuspec.FullName --output-directory $root
} else {
throw "Welp, ya need the zip in the tools folder, dumby"
}
Get-ChildItem $PackageSource -recurse -filter *.nupkg | ForEach-Object {
choco push $_.FullName -s https://push.chocolatey.org --api-key="'$($env:ChocoApiKey)'"
}
}
}
}