-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.ps1
76 lines (70 loc) · 2.76 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
[cmdletbinding()]
param (
[parameter(Mandatory = $false)]
[System.IO.FileInfo]$modulePath = "$PSScriptRoot\ConfigMgr.AdminService",
[parameter(Mandatory = $false)]
[switch]$buildLocal
)
try {
#region Generate a new version number
$moduleName = Split-Path -Path $modulePath -Leaf
$PreviousVersion = Find-Module -Name $moduleName -ErrorAction SilentlyContinue | Sort-Object Version -Descending | Select-Object -First 1 *
[Version]$exVer = $PreviousVersion ? $PreviousVersion.Version : $null
if ($buildLocal) {
$releases = Get-ChildItem -Path "$PSScriptRoot\bin\release\" -ErrorAction SilentlyContinue
if($releases) {
$rev = ($releases.Name | Measure-Object -Maximum | Select-Object -ExpandProperty Maximum) + 1
}
else {
$rev = 1
}
$newVersion = New-Object -TypeName Version -ArgumentList 1, 0, 0, $rev
}
else {
if(Test-Path "$PSScriptRoot\bin\release\") {
Remove-Item -Path "$PSScriptRoot\bin\release\" -Recurse -Force
}
$newVersion = if ($exVer) {
$rev = ($exVer.Revision + 1)
New-Object version -ArgumentList $exVer.Major, $exVer.Minor, $exVer.Build, $rev
}
else {
$rev = ((Get-ChildItem "$PSScriptRoot\bin\release\" -ErrorAction SilentlyContinue).Name | Measure-Object -Maximum | Select-Object -ExpandProperty Maximum) + 1
New-Object Version -ArgumentList 1, 0, 0, $rev
}
}
$releaseNotes = (Get-Content ".\$moduleName\ReleaseNotes.txt" -Raw -ErrorAction SilentlyContinue).Replace("{{NewVersion}}", $newVersion)
if ($PreviousVersion) {
$releaseNotes = @"
$releaseNotes
$($previousVersion.releaseNotes)
"@
}
#endregion
#region Build out the release
if ($buildLocal) {
$relPath = "$PSScriptRoot\bin\release\$rev\$moduleName"
}
else {
$relPath = "$PSScriptRoot\bin\release\$moduleName"
}
"Version is $newVersion"
"Module Path is $modulePath"
"Module Name is $moduleName"
"Release Path is $relPath"
if (!(Test-Path -Path $relPath)) {
New-Item -Path $relPath -ItemType Directory -Force | Out-Null
}
Copy-Item -Path "$modulePath\*" -Destination "$relPath" -Recurse -Exclude ".gitKeep", "releaseNotes.txt", "description.txt","docs"
$Manifest = @{
Path = "$relPath\$moduleName.psd1"
ModuleVersion = $newVersion
Description = (Get-Content "$modulePath\description.txt" -Raw).ToString()
FunctionsToExport = (Get-ChildItem -Path "$relPath\Public\*.ps1" -Recurse).BaseName
ReleaseNotes = $releaseNotes
}
Update-ModuleManifest @Manifest
}
catch {
$_
}