-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetNovaVersionUpdateWorkflowContext.ps1
More file actions
166 lines (137 loc) · 6.11 KB
/
Copy pathGetNovaVersionUpdateWorkflowContext.ps1
File metadata and controls
166 lines (137 loc) · 6.11 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
function Get-NovaVersionUpdateWorkflowContext {
[CmdletBinding()]
param(
[Parameter(Mandatory)][string]$ProjectRoot,
[switch]$PreviewRelease,
[switch]$ContinuousIntegrationRequested,
[switch]$OverrideWarningRequested
)
$projectInfo = Get-NovaProjectInfo -Path $ProjectRoot
$commitMessages = @(Get-GitCommitMessageForVersionBump -ProjectRoot $ProjectRoot)
Assert-NovaVersionBumpInferenceAvailability -ProjectRoot $ProjectRoot -CommitMessages $commitMessages -OverrideWarningRequested:$OverrideWarningRequested
$label = Get-NovaVersionLabelForBump -ProjectRoot $ProjectRoot -CommitMessages $commitMessages -ContinuousIntegrationRequested:$ContinuousIntegrationRequested
$labelResolution = Get-NovaVersionUpdateLabelResolution -ProjectInfo $projectInfo -Label $label -PreviewRelease:$PreviewRelease
$versionUpdatePlan = Get-NovaVersionUpdatePlan -ProjectInfo $projectInfo -Label $labelResolution.EffectiveLabel -PreviewRelease:$PreviewRelease
return Get-NovaVersionUpdateWorkflowContextObject -ProjectRoot $ProjectRoot -ProjectInfo $projectInfo -CommitMessages $commitMessages -Label $label -EffectiveLabel $labelResolution.EffectiveLabel -AdvisoryMessage $labelResolution.AdvisoryMessage -VersionUpdatePlan $versionUpdatePlan -PreviewRelease:$PreviewRelease -ContinuousIntegrationRequested:$ContinuousIntegrationRequested
}
function Assert-NovaVersionBumpInferenceAvailability {
[CmdletBinding()]
param(
[Parameter(Mandatory)][string]$ProjectRoot,
[AllowEmptyCollection()][string[]]$CommitMessages = @(),
[switch]$OverrideWarningRequested
)
if ($CommitMessages.Count -gt 0) {
return
}
if (Test-GitRepositoryIsAvailable -ProjectRoot $ProjectRoot) {
return
}
$message = Get-NovaVersionBumpInferenceUnavailableMessage
Write-Warning $message
if ($OverrideWarningRequested) {
Write-Verbose 'Continuing version bump because OverrideWarning was specified and Git-based bump inference is unavailable.'
return
}
Stop-NovaOperation -Message $message -ErrorId 'Nova.Workflow.VersionBumpInferenceUnavailable' -Category InvalidOperation -TargetObject $ProjectRoot
}
function Get-NovaVersionBumpInferenceUnavailableMessage {
[CmdletBinding()]
param()
return 'Cannot infer the version bump label from Git history because no Git repository was found for this project path. Use -OverrideWarning / --override-warning / -o to continue intentionally with a Patch fallback, for example in example or template flows.'
}
function Get-NovaVersionUpdateLabelResolution {
[CmdletBinding()]
param(
[Parameter(Mandatory)][pscustomobject]$ProjectInfo,
[Parameter(Mandatory)][string]$Label,
[switch]$PreviewRelease
)
$effectiveLabel = $Label
$advisoryMessage = $null
$currentVersion = Get-NovaCurrentVersionForUpdatePlan -ProjectInfo $ProjectInfo
if (Test-NovaVersionUpdateUsesPreviewPatchFallback -CurrentVersion $currentVersion -PreviewRelease:$PreviewRelease) {
$effectiveLabel = 'Patch'
}
if (Test-NovaVersionUpdateUsesInitialDevelopmentAdvisory -CurrentVersion $currentVersion -PreviewRelease:$PreviewRelease) {
$advisoryMessage = Get-NovaInitialDevelopmentVersioningMessage
}
if (Test-NovaVersionUpdateUsesMajorZeroFallback -CurrentVersion $currentVersion -Label $Label -PreviewRelease:$PreviewRelease) {
$effectiveLabel = 'Minor'
}
return [pscustomobject]@{
EffectiveLabel = $effectiveLabel
AdvisoryMessage = $advisoryMessage
}
}
function Test-NovaVersionUpdateUsesPreviewPatchFallback {
[CmdletBinding()]
param(
[Parameter(Mandatory)][semver]$CurrentVersion,
[switch]$PreviewRelease
)
if (-not $PreviewRelease) {
return $false
}
return [string]::IsNullOrWhiteSpace($CurrentVersion.PreReleaseLabel)
}
function Test-NovaVersionUpdateUsesInitialDevelopmentAdvisory {
[CmdletBinding()]
param(
[Parameter(Mandatory)][semver]$CurrentVersion,
[switch]$PreviewRelease
)
if ($PreviewRelease) {
return $false
}
return $CurrentVersion.Major -eq 0
}
function Test-NovaVersionUpdateUsesMajorZeroFallback {
[CmdletBinding()]
param(
[Parameter(Mandatory)][semver]$CurrentVersion,
[Parameter(Mandatory)][string]$Label,
[switch]$PreviewRelease
)
if ($PreviewRelease) {
return $false
}
if ($Label -ne 'Major') {
return $false
}
return $CurrentVersion.Major -eq 0
}
function Get-NovaInitialDevelopmentVersioningMessage {
[CmdletBinding()]
param()
return 'Major version zero (0.y.z) is for initial development, so Nova keeps stable bumps on the 0.y.z line and plans breaking-change bumps as the next minor version instead of 1.0.0. Set 1.0.0 manually once the software is stable; after that, automatic major-version bumps work normally.'
}
function Get-NovaVersionUpdateWorkflowContextObject {
[CmdletBinding()]
param(
[Parameter(Mandatory)][string]$ProjectRoot,
[Parameter(Mandatory)][pscustomobject]$ProjectInfo,
[AllowEmptyCollection()][string[]]$CommitMessages = @(),
[Parameter(Mandatory)][string]$Label,
[Parameter(Mandatory)][string]$EffectiveLabel,
[AllowEmptyString()][string]$AdvisoryMessage,
[Parameter(Mandatory)][pscustomobject]$VersionUpdatePlan,
[switch]$PreviewRelease,
[switch]$ContinuousIntegrationRequested
)
return [pscustomobject]@{
ProjectRoot = $ProjectRoot
ProjectInfo = $ProjectInfo
CommitMessages = $CommitMessages
CommitCount = $CommitMessages.Count
Label = $Label
EffectiveLabel = $EffectiveLabel
AdvisoryMessage = $AdvisoryMessage
PreviewRelease = [bool]$PreviewRelease
ContinuousIntegrationRequested = [bool]$ContinuousIntegrationRequested
Target = [System.IO.Path]::GetFileName($ProjectInfo.ProjectJSON)
Action = "Update module version using $Label release label"
PreviousVersion = $ProjectInfo.Version
NewVersion = $VersionUpdatePlan.NewVersion.ToString()
}
}