|
1 |
| -[cmdletbinding()] |
| 1 | +[cmdletbinding()] |
2 | 2 | param (
|
3 | 3 | [parameter(Mandatory = $true)]
|
4 | 4 | [System.IO.FileInfo]$modulePath,
|
5 | 5 |
|
6 |
| - [parameter(Mandatory = $true)] |
7 |
| - [string]$moduleName, |
8 |
| - |
9 | 6 | [parameter(Mandatory = $false)]
|
10 | 7 | [switch]$buildLocal
|
11 | 8 | )
|
12 |
| -if ($buildLocal) { |
13 |
| - if (Test-Path $PSScriptRoot\localenv.ps1 -ErrorAction SilentlyContinue) { |
14 |
| - . $PSScriptRoot\localenv.ps1 |
15 |
| - if (Test-Path "$PSScriptRoot\bin\release\*") { |
16 |
| - $env:BUILD_BUILDID = ((Get-ChildItem $PSScriptRoot\bin\release\).Name | Measure-Object -Maximum | Select-Object -ExpandProperty Maximum) + 1 |
17 |
| - } |
18 |
| - } |
19 |
| -} |
| 9 | + |
20 | 10 | try {
|
21 | 11 | #region Generate a new version number
|
22 |
| - $newVersion = New-Object version -ArgumentList 1, 0, 1, $env:BUILD_BUILDID |
23 |
| - $lastVersion = (Find-Module $env:ModuleName).Version |
24 |
| - $releaseNotes = (Get-Content .\Intune.USB.Creator\ReleaseNotes.txt -Raw).Replace("{{NewVersion}}",$newVersion).Replace("{{LastVersion}}","$lastVersion") |
| 12 | + $moduleName = Split-Path -Path $modulePath -Leaf |
| 13 | + $PreviousVersion = Find-Module -Name $moduleName -ErrorAction SilentlyContinue | Select-Object * |
| 14 | + [Version]$exVer = $PreviousVersion ? $PreviousVersion.Version : $null |
| 15 | + if ($buildLocal) { |
| 16 | + $rev = ((Get-ChildItem -Path "$PSScriptRoot\bin\release\" -ErrorAction SilentlyContinue).Name | Measure-Object -Maximum | Select-Object -ExpandProperty Maximum) + 1 |
| 17 | + $newVersion = New-Object -TypeName Version -ArgumentList 1, 0, 0, $rev |
| 18 | + } |
| 19 | + else { |
| 20 | + $newVersion = if ($exVer) { |
| 21 | + $rev = ($exVer.Revision + 1) |
| 22 | + New-Object version -ArgumentList $exVer.Major, $exVer.Minor, $exVer.Build, $rev |
| 23 | + } |
| 24 | + else { |
| 25 | + $rev = ((Get-ChildItem "$PSScriptRoot\bin\release\" -ErrorAction SilentlyContinue).Name | Measure-Object -Maximum | Select-Object -ExpandProperty Maximum) + 1 |
| 26 | + New-Object Version -ArgumentList 1, 0, 0, $rev |
| 27 | + } |
| 28 | + } |
| 29 | + $releaseNotes = (Get-Content ".\$moduleName\ReleaseNotes.txt" -Raw -ErrorAction SilentlyContinue).Replace("{{NewVersion}}", $newVersion) |
| 30 | + if ($PreviousVersion) { |
| 31 | + $releaseNotes = @" |
| 32 | +$releaseNotes |
| 33 | +
|
| 34 | +$($previousVersion.releaseNotes) |
| 35 | +"@ |
| 36 | + } |
25 | 37 | #endregion
|
| 38 | + |
26 | 39 | #region Build out the release
|
27 |
| - $relPath = "$PSScriptRoot\bin\release\$env:BUILD_BUILDID\$moduleName" |
| 40 | + if ($buildLocal) { |
| 41 | + $relPath = "$PSScriptRoot\bin\release\$rev\$moduleName" |
| 42 | + } |
| 43 | + else { |
| 44 | + $relPath = "$PSScriptRoot\bin\release\$moduleName" |
| 45 | + } |
28 | 46 | "Version is $newVersion"
|
29 | 47 | "Module Path is $modulePath"
|
30 | 48 | "Module Name is $moduleName"
|
31 | 49 | "Release Path is $relPath"
|
32 |
| - if (!(Test-Path $relPath)) { |
| 50 | + if (!(Test-Path -Path $relPath)) { |
33 | 51 | New-Item -Path $relPath -ItemType Directory -Force | Out-Null
|
34 | 52 | }
|
35 |
| - Copy-Item "$modulePath\*" -Destination "$relPath" -Recurse -Exclude ".gitKeep" |
36 |
| - #endregion |
37 |
| - #region Generate a list of public functions and update the module manifest |
38 |
| - $functions = @(Get-ChildItem -Path $relPath\Public\*.ps1 -ErrorAction SilentlyContinue).basename |
39 |
| - $params = @{ |
40 |
| - Path = "$relPath\$ModuleName.psd1" |
41 |
| - ModuleVersion = $newVersion |
42 |
| - Description = (Get-Content $relPath\description.txt -raw).ToString() |
43 |
| - FunctionsToExport = $functions |
44 |
| - ReleaseNotes = $releaseNotes.ToString() |
| 53 | + |
| 54 | + Copy-Item -Path "$modulePath\*" -Destination "$relPath" -Recurse -Exclude ".gitKeep", "releaseNotes.txt", "description.txt" |
| 55 | + |
| 56 | + $Manifest = @{ |
| 57 | + Path = "$relPath\$moduleName.psd1" |
| 58 | + ModuleVersion = $newVersion |
| 59 | + Description = (Get-Content "$modulePath\description.txt" -Raw).ToString() |
| 60 | + FunctionsToExport = (Get-ChildItem -Path "$relPath\Public\*.ps1" -Recurse).BaseName |
| 61 | + ReleaseNotes = $releaseNotes |
45 | 62 | }
|
46 |
| - Update-ModuleManifest @params |
47 |
| - $moduleManifest = Get-Content $relPath\$ModuleName.psd1 -raw | Invoke-Expression |
48 |
| - #endregion |
49 |
| - #region Generate the nuspec manifest |
50 |
| - $t = [xml](Get-Content $PSScriptRoot\module.nuspec -Raw) |
51 |
| - $t.package.metadata.id = $moduleName |
52 |
| - $t.package.metadata.version = $newVersion.ToString() |
53 |
| - $t.package.metadata.authors = $moduleManifest.author.ToString() |
54 |
| - $t.package.metadata.owners = $moduleManifest.author.ToString() |
55 |
| - $t.package.metadata.requireLicenseAcceptance = "false" |
56 |
| - $t.package.metadata.description = (Get-Content $relPath\description.txt -raw).ToString() |
57 |
| - $t.package.metadata.description |
58 |
| - $t.package.metadata.releaseNotes = $releaseNotes.ToString() |
59 |
| - $t.package.metadata.releaseNotes |
60 |
| - $t.package.metadata.copyright = $moduleManifest.copyright.ToString() |
61 |
| - $t.package.metadata.tags = ($moduleManifest.PrivateData.PSData.Tags -join ',').ToString() |
62 |
| - $t.Save("$PSScriptRoot\$moduleName`.nuspec") |
63 |
| - #endregion |
| 63 | + Update-ModuleManifest @Manifest |
64 | 64 | }
|
65 | 65 | catch {
|
66 | 66 | $_
|
|
0 commit comments