-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.ps1
123 lines (86 loc) · 3.5 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
[cmdletBinding()]
param(
[Parameter()]
[Switch]
$Build,
[Parameter()]
[Switch]
$TestPrePublish,
[Parameter()]
[Switch]
$TestPostPublish,
[Parameter()]
[Switch]
$DeployToGallery,
[Parameter()]
[Switch]
$Choco
)
process {
$root = Split-Path -Parent $MyInvocation.MyCommand.Definition
switch ($true) {
$Build {
Install-Module PoshBot -Force -SkipPublisherCheck
Import-Module PoshBot
if (Test-Path "$root\Output") {
Remove-Item "$root\Output\Uh-Oh\*.psm1" -Recurse -Force
}
if (Test-Path "$root\src\nuget\tools\Uh-Oh.zip") {
Remove-Item "$root\src\nuget\tools\Uh-Oh.zip" -Force
}
Get-ChildItem $root\src\public\*.ps1 |
Foreach-Object {
Get-Content $_.FullName | Add-Content "$root\Output\Uh-Oh\Uh-Oh.psm1"
}
Get-ChildItem $root\Poshbot\*.ps1 |
Foreach-Object {
Get-Content $_.FullName | Add-Content "$root\Output\Uh-Oh\Uh-Oh.psm1"
}
$manifest = Import-PowerShellDataFile "$root\Output\Uh-Oh\Uh-Oh.psd1"
[version]$version = $Manifest.ModuleVersion
# Add one to the build of the version number
if (($Version.Build + 1) -eq 10) {
[version]$NewVersion = "{0}.{1}.{2}" -f $Version.Major, ($Version.Minor + 1), '0'
}
else { [version]$NewVersion = "{0}.{1}.{2}" -f $Version.Major, $Version.Minor, ($Version.Build + 1) }
# Update the manifest file
Update-ModuleManifest -Path "$root\Output\Uh-Oh\Uh-Oh.psd1" -ModuleVersion $NewVersion
$manifest = Import-PowerShellDataFile "$root\Output\Uh-Oh\Uh-Oh.psd1"
$version = $Manifest.ModuleVersion
$Nuspec = Get-ChildItem "$root\src\nuget" -recurse -filter *.nuspec
(Get-Content "$($Nuspec.Fullname)").Replace('[[VERSION]]', "$version") | Set-Content "$($Nuspec.FullName)"
#Compress Module to zip file
Compress-Archive -Path "$root\Output\Uh-Oh\Uh-Oh.psd1", "$root\Output\Uh-Oh\Uh-Oh.psm1" -DestinationPath "$root\src\nuget\tools\Uh-Oh.zip"
}
$TestPrePublish {
Get-ChildItem $root\src\public\*.ps1, $root\Poshbot\*.ps1 |
Foreach-Object {
. $_.FullName
}
#Import-Module "$root\Output\Uh-Oh\Uh-Oh.psd1" -Force
Import-Module PoshBot -Force
Invoke-Pester "$root\tests\pre"
}
$TestPostPublish {
Install-Module Uh-Oh -Force
Import-Module PoshBot -Force
Invoke-Pester "$root\tests\*.ps1"
}
$DeployToGallery {
Publish-Module -Path "$root\Output\Uh-Oh" -NuGetApiKey $env:NugetApiKey
}
$Choco {
$Nuspec = Get-ChildItem "$root\src\nuget" -recurse -filter *.nuspec
if (Test-Path "$root\src\nuget\tools\Uh-Oh.zip") {
choco pack $Nuspec.Fullname --output-directory $Nuspec.directory
}
else {
throw "Welp, ya need the zip in the tools folder, dumby"
}
Get-ChildItem "$root\src\nuget" -recurse -filter *.nupkg |
Foreach-Object {
choco push $_.FullName -s https://push.chocolatey.org --api-key="'$($env:ChocoApiKey)'"
}
}
}
}