-
Notifications
You must be signed in to change notification settings - Fork 45
/
build.ps1
67 lines (61 loc) · 2.36 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
[cmdletbinding()]
param (
[parameter(Mandatory = $true)]
[System.IO.FileInfo]$modulePath,
[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 | Select-Object *
[Version]$exVer = $PreviousVersion ? $PreviousVersion.Version : $null
if ($buildLocal) {
$rev = ((Get-ChildItem -Path "$PSScriptRoot\bin\release\" -ErrorAction SilentlyContinue).Name | Measure-Object -Maximum | Select-Object -ExpandProperty Maximum) + 1
$newVersion = New-Object -TypeName Version -ArgumentList 1, 0, 0, $rev
}
else {
$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"
$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 {
$_
}