|
6 | 6 | using module PowerShellForGitHub |
7 | 7 | using namespace System.Management.Automation |
8 | 8 |
|
9 | | -class RepoNames: IValidateSetValuesGenerator { |
10 | | - # NOTE: This is super over-engineered, but it was fun. |
11 | | - static [string[]] $Values = "vscode-powershell", "PowerShellEditorServices" |
12 | | - [String[]] GetValidValues() { return [RepoNames]::Values } |
13 | | -} |
14 | | - |
15 | | -$ChangelogFile = "CHANGELOG.md" |
| 9 | +Import-Module $PSScriptRoot/VersionTools.psm1 |
16 | 10 |
|
17 | 11 | <# |
18 | 12 | .SYNOPSIS |
19 | | - Given the repository name, execute the script in its directory. |
| 13 | + Creates and checks out `release` if not already on it. |
20 | 14 | #> |
21 | | -function Use-Repository { |
22 | | - [CmdletBinding()] |
| 15 | +function Update-Branch { |
| 16 | + [CmdletBinding(SupportsShouldProcess)] |
23 | 17 | param( |
24 | 18 | [Parameter(Mandatory)] |
25 | 19 | [ValidateSet([RepoNames])] |
26 | | - [string]$RepositoryName, |
27 | | - |
28 | | - [Parameter(Mandatory)] |
29 | | - [scriptblock]$Script |
| 20 | + [string]$RepositoryName |
30 | 21 | ) |
31 | | - try { |
32 | | - switch ($RepositoryName) { |
33 | | - "vscode-powershell" { |
34 | | - Push-Location -Path "$PSScriptRoot/../" |
35 | | - } |
36 | | - "PowerShellEditorServices" { |
37 | | - Push-Location -Path "$PSScriptRoot/../../PowerShellEditorServices" |
| 22 | + Use-Repository -RepositoryName $RepositoryName -Script { |
| 23 | + $Branch = git branch --show-current |
| 24 | + if ($Branch -ne "release") { |
| 25 | + if ($PSCmdlet.ShouldProcess("release", "git checkout -B")) { |
| 26 | + git checkout -B "release" |
38 | 27 | } |
39 | 28 | } |
40 | | - & $Script |
41 | | - } finally { |
42 | | - Pop-Location |
43 | 29 | } |
44 | 30 | } |
45 | 31 |
|
@@ -143,136 +129,6 @@ function Get-Bullets { |
143 | 129 | } |
144 | 130 | } |
145 | 131 |
|
146 | | -<# |
147 | | -.SYNOPSIS |
148 | | - Gets the unpublished content from the changelog. |
149 | | -.DESCRIPTION |
150 | | - This is used so that we can manually touch-up the automatically updated |
151 | | - changelog, and then bring its contents into the extension's changelog or |
152 | | - the GitHub release. It just gets the first header's contents. |
153 | | -#> |
154 | | -function Get-FirstChangelog { |
155 | | - param( |
156 | | - [Parameter(Mandatory)] |
157 | | - [ValidateSet([RepoNames])] |
158 | | - [string]$RepositoryName |
159 | | - ) |
160 | | - $Changelog = Use-Repository -RepositoryName $RepositoryName -Script { |
161 | | - Get-Content -Path $ChangelogFile |
162 | | - } |
163 | | - # NOTE: The space after the header marker is important! Otherwise ### matches. |
164 | | - $Header = $Changelog.Where({$_.StartsWith("## ")}, "First") |
165 | | - $Changelog.Where( |
166 | | - { $_ -eq $Header }, "SkipUntil" |
167 | | - ).Where( |
168 | | - { $_.StartsWith("## ") -and $_ -ne $Header }, "Until" |
169 | | - ) |
170 | | -} |
171 | | - |
172 | | -<# |
173 | | -.SYNOPSIS |
174 | | - Creates and checks out `release` if not already on it. |
175 | | -#> |
176 | | -function Update-Branch { |
177 | | - [CmdletBinding(SupportsShouldProcess)] |
178 | | - param( |
179 | | - [Parameter(Mandatory)] |
180 | | - [ValidateSet([RepoNames])] |
181 | | - [string]$RepositoryName |
182 | | - ) |
183 | | - Use-Repository -RepositoryName $RepositoryName -Script { |
184 | | - $Branch = git branch --show-current |
185 | | - if ($Branch -ne "release") { |
186 | | - if ($PSCmdlet.ShouldProcess("release", "git checkout -B")) { |
187 | | - git checkout -B "release" |
188 | | - } |
189 | | - } |
190 | | - } |
191 | | -} |
192 | | - |
193 | | -<# |
194 | | -.SYNOPSIS |
195 | | - Gets current version from changelog as `[semver]`. |
196 | | -#> |
197 | | -function Get-Version { |
198 | | - param( |
199 | | - [Parameter(Mandatory)] |
200 | | - [ValidateSet([RepoNames])] |
201 | | - [string]$RepositoryName |
202 | | - ) |
203 | | - # NOTE: The first line should always be the header. |
204 | | - $Changelog = (Get-FirstChangelog -RepositoryName $RepositoryName)[0] |
205 | | - if ($Changelog -match '## v(?<version>\d+\.\d+\.\d+(-preview\.?\d*)?)') { |
206 | | - return [semver]$Matches.version |
207 | | - } else { |
208 | | - Write-Error "Couldn't find version from changelog!" |
209 | | - } |
210 | | -} |
211 | | - |
212 | | -<# |
213 | | -.SYNOPSIS |
214 | | - Gets the version as a semantic version string without the 'v' prefix or |
215 | | - pre-release suffix. |
216 | | -#> |
217 | | -function Get-MajorMinorPatch { |
218 | | - param( |
219 | | - [Parameter(Mandatory)] |
220 | | - [semver]$Version |
221 | | - ) |
222 | | - return "$($Version.Major).$($Version.Minor).$($Version.Patch)" |
223 | | -} |
224 | | - |
225 | | -<# |
226 | | -.SYNOPSIS |
227 | | - Tests if this is a pre-release (specifically for the extension). |
228 | | -#> |
229 | | -function Test-IsPreRelease { |
230 | | - $Version = Get-Version -RepositoryName vscode-powershell |
231 | | - return [bool]$Version.PreReleaseLabel |
232 | | -} |
233 | | - |
234 | | -<# |
235 | | -.SYNOPSIS |
236 | | - Validates the given version string. |
237 | | -#> |
238 | | -function Test-VersionIsValid { |
239 | | - param( |
240 | | - [Parameter(Mandatory)] |
241 | | - [ValidateSet([RepoNames])] |
242 | | - [string]$RepositoryName, |
243 | | - |
244 | | - [Parameter(Mandatory)] |
245 | | - [string]$Version |
246 | | - ) |
247 | | - if (!$Version.StartsWith("v")) { |
248 | | - throw "Version should start with 'v' prefix!" |
249 | | - } |
250 | | - |
251 | | - $SemanticVersion = [semver]$Version.Substring(1) |
252 | | - switch ($RepositoryName) { |
253 | | - "vscode-powershell" { |
254 | | - $Date = Get-Date |
255 | | - if ($SemanticVersion.Major -ne $Date.Year) { |
256 | | - throw "Major version should be the current year!" |
257 | | - } |
258 | | - if ($SemanticVersion.Minor -ne $Date.Month) { |
259 | | - throw "Minor version should be the current month!" |
260 | | - } |
261 | | - if ($SemanticVersion.PreReleaseLabel) { |
262 | | - if ($SemanticVersion.PreReleaseLabel -ne "preview") { |
263 | | - throw "Suffix should only be 'preview'!" |
264 | | - } |
265 | | - } |
266 | | - } |
267 | | - "PowerShellEditorServices" { |
268 | | - if ($SemanticVersion.PreReleaseLabel) { |
269 | | - throw "Version shouldn't have a pre-release label!" |
270 | | - } |
271 | | - } |
272 | | - } |
273 | | - return $true |
274 | | -} |
275 | | - |
276 | 132 | <# |
277 | 133 | .SYNOPSIS |
278 | 134 | Updates the CHANGELOG file with PRs merged since the last release. |
|
0 commit comments