-
Notifications
You must be signed in to change notification settings - Fork 132
Expand file tree
/
Copy pathSet-Version.ps1
More file actions
56 lines (43 loc) · 2.12 KB
/
Set-Version.ps1
File metadata and controls
56 lines (43 loc) · 2.12 KB
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
[CmdletBinding()]
Param(
[Parameter()]
[switch]$preview = $false
)
## Initialize
Import-Module "$PSScriptRoot\CommonFunctions.psm1" -Force -WarningAction SilentlyContinue -ErrorAction Stop
$ModuleRoot = "./src/powershell"
$ModuleManifestPath = "./src/powershell/*.psd1"
$ManifestPath = Get-PathInfo $ModuleManifestPath -DefaultFilename "*.psd1" -ErrorAction Stop | Select-Object -Last 1
$moduleName = Split-Path $ManifestPath -LeafBase
if ( -not (Test-Path $ManifestPath )) {
Write-Error "Could not find PowerShell module manifest ($ManifestPath)"
throw
} else {
# Get the current version of the module from the PowerShell gallery
$previousVersion = (Find-Module -Name $moduleName -AllowPrerelease:$preview).Version
Write-Host "Previous version: $previousVersion"
$ver = [version]($previousVersion -replace '-preview')
# Set new version number. If it is pre-release, increment the build number otherwise increment the minor version.
$major = $ver.Major # Update this to change the major version number.
$minor = $ver.Minor
if ($preview) {
$build = $ver.Build + 1
} else {
$minor = $ver.Minor + 1
$build = 0 # Reset the build number when incrementing the minor version.
}
$NewVersion = '{0}.{1}.{2}' -f $major, $minor, $build
$publicScripts = @( Get-ChildItem -Path "$ModuleRoot/public" -Recurse -Filter "*.ps1" )
$FunctionNames = @( $publicScripts.BaseName | Sort-Object )
$previewLabel = if ($preview) { '-preview' } else { '' }
Write-Debug -Message ('Updating FunctionsToExport...')
Update-Metadata -Path $ManifestPath -PropertyName FunctionsToExport -Value $FunctionNames
Write-Debug -Message ('Updating ModuleVersion...')
Update-Metadata -Path $ManifestPath -PropertyName ModuleVersion -Value $NewVersion
Write-Debug -Message ('Updating Prerelease...')
Update-Metadata -Path $ManifestPath -PropertyName Prerelease -Value $previewLabel
}
$NewVersion += $previewLabel
Write-Host "New version: $NewVersion"
#Add-Content -Path $env:GITHUB_OUTPUT -Value "newtag=$NewVersion"
#Add-Content -Path $env:GITHUB_OUTPUT -Value "tag=$NewVersion"