Skip to content

Commit bc8bb00

Browse files
committed
feat(#97): clean up output and result contracts for structured data
- Enhance output structure for version updates and module installations - Introduce ReleaseNotesUri in update workflows for better user feedback - Refactor functions to return structured data consistently
1 parent 3c4d789 commit bc8bb00

19 files changed

Lines changed: 295 additions & 51 deletions

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
106106
- CI bump now reuses the already activated built-module command when the current session is already running from
107107
`dist/`, so publish-then-bump prerelease automation can continue in the same session without losing private helper
108108
bindings.
109+
- Keep standalone `nova bump` output stable by formatting version-update results in the CLI layer instead of relying on
110+
PowerShell's default object rendering.
111+
- `nova bump --what-if` and `% run.ps1` now surface a predictable summary for previous version, new version, label,
112+
and commit count.
109113

110114
### Changed
111115

src/private/cli/FormatNovaCliCommandResult.ps1

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,61 @@ function Test-NovaCliNoUpdateResult {
1313
return ($propertyNames -contains 'UpdateAvailable') -and ($propertyNames -contains 'CurrentVersion') -and -not $Result.UpdateAvailable
1414
}
1515

16-
function Format-NovaCliCommandResult {
16+
function Test-NovaCliVersionUpdateResult {
1717
[CmdletBinding()]
1818
param(
1919
[string]$Command,
2020
[object]$Result
2121
)
2222

23-
if (-not (Test-NovaCliNoUpdateResult -Command $Command -Result $Result)) {
24-
return $Result
23+
if ($Command -ne 'bump' -or $null -eq $Result) {
24+
return $false
25+
}
26+
27+
$propertyNames = @($Result.PSObject.Properties.Name)
28+
foreach ($requiredPropertyName in @('PreviousVersion', 'NewVersion', 'Label', 'CommitCount', 'Applied')) {
29+
if ($propertyNames -notcontains $requiredPropertyName) {
30+
return $false
31+
}
32+
}
33+
34+
return $true
35+
}
36+
37+
function Format-NovaCliVersionUpdateResult {
38+
[CmdletBinding()]
39+
param(
40+
[Parameter(Mandatory)][object]$Result
41+
)
42+
43+
$summaryPrefix = if ($Result.Applied) {
44+
'Version bump completed:'
2545
}
46+
else {
47+
'Version plan:'
48+
}
49+
50+
return "$summaryPrefix $( $Result.PreviousVersion ) -> $( $Result.NewVersion ) | Label: $( $Result.Label ) | Commits: $( $Result.CommitCount )"
51+
}
2652

27-
return @(
28-
"You're up to date!"
29-
"$( $Result.ModuleName ) $( $Result.CurrentVersion ) is currently the newest version available."
53+
function Format-NovaCliCommandResult {
54+
[CmdletBinding()]
55+
param(
56+
[string]$Command,
57+
[object]$Result
3058
)
59+
60+
if (Test-NovaCliNoUpdateResult -Command $Command -Result $Result) {
61+
return @(
62+
"You're up to date!"
63+
"$( $Result.ModuleName ) $( $Result.CurrentVersion ) is currently the newest version available."
64+
)
65+
}
66+
67+
if (Test-NovaCliVersionUpdateResult -Command $Command -Result $Result) {
68+
return Format-NovaCliVersionUpdateResult -Result $Result
69+
}
70+
71+
return $Result
3172
}
3273

src/private/cli/InvokeNovaCliCommandRoute.ps1

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ function Invoke-NovaCliUpdateRouteCommand {
6464
Format-NovaCliCommandResult -Command $InvocationContext.Command -Result $result
6565
}
6666

67+
function Invoke-NovaCliBumpRouteCommand {
68+
[CmdletBinding()]
69+
param(
70+
[Parameter(Mandatory)][pscustomobject]$InvocationContext
71+
)
72+
73+
$result = Invoke-NovaCliParsedCommand -InvocationContext $InvocationContext -ParserCommand 'ConvertFrom-NovaBumpCliArgument' -ActionCommand 'Update-NovaModuleVersion'
74+
return Format-NovaCliCommandResult -Command $InvocationContext.Command -Result $result
75+
}
76+
6777
function Invoke-NovaCliNotificationRouteCommand {
6878
[CmdletBinding()]
6979
param(
@@ -125,7 +135,7 @@ function Invoke-NovaCliCommandRoute {
125135
return Invoke-NovaCliInitCommand -Arguments $InvocationContext.Arguments -ForwardedParameters $mutatingCommonParameters -WhatIfEnabled:$InvocationContext.WhatIfEnabled
126136
}
127137
'bump' {
128-
return Invoke-NovaCliParsedCommand -InvocationContext $InvocationContext -ParserCommand 'ConvertFrom-NovaBumpCliArgument' -ActionCommand 'Update-NovaModuleVersion'
138+
return Invoke-NovaCliBumpRouteCommand -InvocationContext $InvocationContext
129139
}
130140
'update' {
131141
return Invoke-NovaCliUpdateRouteCommand -InvocationContext $InvocationContext

src/private/cli/InvokeNovaCliInstallWorkflow.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ function Invoke-NovaCliInstallWorkflow {
1010
Write-Warning "Installed nova to $( $WorkflowContext.TargetDirectory ), but that directory is not currently in PATH. Add it to your shell profile before using nova directly from zsh/bash."
1111
}
1212

13-
Write-NovaModuleReleaseNotesLink
13+
$releaseNotesUri = Get-NovaModuleReleaseNotesUri
1414

1515
return [pscustomobject]@{
1616
CommandName = 'nova'
1717
InstalledPath = $installedPath
1818
DestinationDirectory = $WorkflowContext.TargetDirectory
1919
DirectoryOnPath = $directoryOnPath
20+
ReleaseNotesUri = $releaseNotesUri
2021
}
2122
}

src/private/release/InvokeNovaVersionUpdateWorkflow.ps1

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@ function Invoke-NovaVersionUpdateWorkflow {
66
[switch]$WhatIfEnabled
77
)
88

9+
$versionWriteResult = $null
910
if ($ShouldRun) {
10-
Set-NovaModuleVersion -ProjectInfo $WorkflowContext.ProjectInfo -Label $WorkflowContext.Label -PreviewRelease:$WorkflowContext.PreviewRelease -Confirm:$false
11+
$versionWriteResult = Set-NovaModuleVersion -ProjectInfo $WorkflowContext.ProjectInfo -Label $WorkflowContext.Label -PreviewRelease:$WorkflowContext.PreviewRelease -Confirm:$false
1112
}
1213

1314
if (-not (Test-NovaVersionUpdateResultRequired -ShouldRun:$ShouldRun -WhatIfEnabled:$WhatIfEnabled)) {
1415
return
1516
}
1617

17-
return Get-NovaVersionUpdateResult -WorkflowContext $WorkflowContext
18+
return Get-NovaVersionUpdateResult -WorkflowContext $WorkflowContext -Applied:($null -ne $versionWriteResult -and $versionWriteResult.Applied)
1819
}
1920

2021
function Test-NovaVersionUpdateResultRequired {
@@ -30,13 +31,15 @@ function Test-NovaVersionUpdateResultRequired {
3031
function Get-NovaVersionUpdateResult {
3132
[CmdletBinding()]
3233
param(
33-
[Parameter(Mandatory)][pscustomobject]$WorkflowContext
34+
[Parameter(Mandatory)][pscustomobject]$WorkflowContext,
35+
[switch]$Applied
3436
)
3537

3638
return [pscustomobject]@{
3739
PreviousVersion = $WorkflowContext.PreviousVersion
3840
NewVersion = $WorkflowContext.NewVersion
3941
Label = $WorkflowContext.Label
4042
CommitCount = $WorkflowContext.CommitCount
43+
Applied = [bool]$Applied
4144
}
4245
}

src/private/release/SetNovaModuleVersion.ps1

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
function Get-NovaModuleVersionWriteResult {
2+
[CmdletBinding()]
3+
param(
4+
[Parameter(Mandatory)][string]$ProjectFile,
5+
[Parameter(Mandatory)][string]$PreviousVersion,
6+
[Parameter(Mandatory)][string]$NewVersion,
7+
[switch]$Applied
8+
)
9+
10+
return [pscustomobject]@{
11+
ProjectFile = $ProjectFile
12+
Target = [System.IO.Path]::GetFileName($ProjectFile)
13+
PreviousVersion = $PreviousVersion
14+
NewVersion = $NewVersion
15+
Applied = [bool]$Applied
16+
}
17+
}
18+
119
function Set-NovaModuleVersion {
220
[CmdletBinding(SupportsShouldProcess = $true)]
321
param(
@@ -11,13 +29,16 @@ function Set-NovaModuleVersion {
1129

1230
$versionUpdatePlan = Get-NovaVersionUpdatePlan -ProjectInfo $ProjectInfo -Label $Label -PreviewRelease:$PreviewRelease -StableRelease:$StableRelease
1331
$jsonContent = Read-ProjectJsonData -ProjectJsonPath $versionUpdatePlan.ProjectFile
32+
$previousVersion = [string]$jsonContent.Version
1433
$newVersion = $versionUpdatePlan.NewVersion.ToString()
1534
$target = [System.IO.Path]::GetFileName($versionUpdatePlan.ProjectFile)
1635
$action = "Set module version to $newVersion"
1736

18-
if ( $PSCmdlet.ShouldProcess($target, $action)) {
19-
$jsonContent.Version = $newVersion
20-
Write-Host "Version bumped to : $newVersion"
21-
Write-ProjectJsonData -ProjectJsonPath $versionUpdatePlan.ProjectFile -Data $jsonContent
37+
if (-not $PSCmdlet.ShouldProcess($target, $action)) {
38+
return Get-NovaModuleVersionWriteResult -ProjectFile $versionUpdatePlan.ProjectFile -PreviousVersion $previousVersion -NewVersion $newVersion
2239
}
40+
41+
$jsonContent.Version = $newVersion
42+
Write-ProjectJsonData -ProjectJsonPath $versionUpdatePlan.ProjectFile -Data $jsonContent
43+
return Get-NovaModuleVersionWriteResult -ProjectFile $versionUpdatePlan.ProjectFile -PreviousVersion $previousVersion -NewVersion $newVersion -Applied
2344
}
Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,36 @@
1+
function Get-NovaModuleReleaseNotesMessage {
2+
[CmdletBinding(DefaultParameterSetName = 'Module')]
3+
param(
4+
[Parameter(ParameterSetName = 'Module')]
5+
[object]$Module = $ExecutionContext.SessionState.Module,
6+
[Parameter(ParameterSetName = 'Uri')]
7+
[AllowNull()][string]$ReleaseNotesUri
8+
)
9+
10+
if ($PSCmdlet.ParameterSetName -eq 'Module') {
11+
$ReleaseNotesUri = Get-NovaModuleReleaseNotesUri -Module $Module
12+
}
13+
14+
if ( [string]::IsNullOrWhiteSpace($ReleaseNotesUri)) {
15+
return $null
16+
}
17+
18+
return "Release notes: $($ReleaseNotesUri.Trim() )"
19+
}
20+
121
function Write-NovaModuleReleaseNotesLink {
2-
[CmdletBinding()]
22+
[CmdletBinding(DefaultParameterSetName = 'Module')]
323
param(
4-
[object]$Module = $ExecutionContext.SessionState.Module
24+
[Parameter(ParameterSetName = 'Module')]
25+
[object]$Module = $ExecutionContext.SessionState.Module,
26+
[Parameter(ParameterSetName = 'Uri')]
27+
[AllowNull()][string]$ReleaseNotesUri
528
)
629

7-
$releaseNotesUri = Get-NovaModuleReleaseNotesUri -Module $Module
8-
if ($null -eq $releaseNotesUri) {
30+
$message = Get-NovaModuleReleaseNotesMessage @PSBoundParameters
31+
if ($null -eq $message) {
932
return
1033
}
1134

12-
Write-Host "Release notes: $releaseNotesUri"
35+
Write-Host $message
1336
}

src/private/update/InvokeNovaModuleSelfUpdateWorkflow.ps1

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,22 @@ function Invoke-NovaModuleSelfUpdateOrStop {
1212
}
1313
}
1414

15+
function Complete-NovaModuleSelfUpdateResult {
16+
[CmdletBinding()]
17+
param(
18+
[Parameter(Mandatory)][pscustomobject]$Plan,
19+
[AllowNull()][string]$ReleaseNotesUri
20+
)
21+
22+
if ($Plan.PSObject.Properties.Name -contains 'ReleaseNotesUri') {
23+
$Plan.ReleaseNotesUri = $ReleaseNotesUri
24+
return $Plan
25+
}
26+
27+
$Plan | Add-Member -NotePropertyName 'ReleaseNotesUri' -NotePropertyValue $ReleaseNotesUri
28+
return $Plan
29+
}
30+
1531
function Invoke-NovaModuleSelfUpdateWorkflow {
1632
[CmdletBinding()]
1733
param(
@@ -20,11 +36,11 @@ function Invoke-NovaModuleSelfUpdateWorkflow {
2036

2137
$plan = $WorkflowContext.Plan
2238
if (-not $plan.UpdateAvailable) {
23-
return $plan
39+
return Complete-NovaModuleSelfUpdateResult -Plan $plan -ReleaseNotesUri $null
2440
}
2541

2642
Invoke-NovaModuleSelfUpdateOrStop -Plan $plan
2743
$plan.Updated = $true
28-
Write-NovaModuleReleaseNotesLink
29-
return $plan
44+
$releaseNotesUri = Get-NovaModuleReleaseNotesUri
45+
return Complete-NovaModuleSelfUpdateResult -Plan $plan -ReleaseNotesUri $releaseNotesUri
3046
}

src/public/InstallNovaCli.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,7 @@ function Install-NovaCli {
1111
return
1212
}
1313

14-
return Invoke-NovaCliInstallWorkflow -WorkflowContext $workflowContext
14+
$result = Invoke-NovaCliInstallWorkflow -WorkflowContext $workflowContext
15+
Write-NovaModuleReleaseNotesLink -ReleaseNotesUri $result.ReleaseNotesUri
16+
return $result
1517
}

src/public/UpdateNovaModuleTools.ps1

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,19 @@ function Update-NovaModuleTool {
66
$workflowContext = Get-NovaModuleSelfUpdateWorkflowContext
77
$plan = $workflowContext.Plan
88
if (-not $plan.UpdateAvailable) {
9-
return $plan
9+
return Complete-NovaModuleSelfUpdateResult -Plan $plan -ReleaseNotesUri $null
1010
}
1111

1212
if ($plan.IsPrereleaseTarget -and -not (Confirm-NovaPrereleaseModuleUpdate -Cmdlet $PSCmdlet -CurrentVersion $plan.CurrentVersion -TargetVersion $plan.TargetVersion)) {
1313
$plan.Cancelled = $true
14-
return $plan
14+
return Complete-NovaModuleSelfUpdateResult -Plan $plan -ReleaseNotesUri $null
1515
}
1616

1717
if (-not $PSCmdlet.ShouldProcess($plan.ModuleName, $workflowContext.Action)) {
18-
return $plan
18+
return Complete-NovaModuleSelfUpdateResult -Plan $plan -ReleaseNotesUri $null
1919
}
2020

21-
return Invoke-NovaModuleSelfUpdateWorkflow -WorkflowContext $workflowContext
21+
$result = Invoke-NovaModuleSelfUpdateWorkflow -WorkflowContext $workflowContext
22+
Write-NovaModuleReleaseNotesLink -ReleaseNotesUri $result.ReleaseNotesUri
23+
return $result
2224
}

0 commit comments

Comments
 (0)