66using module PowerShellForGitHub
77using namespace System.Management.Automation
88
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
1610
1711<#
1812. SYNOPSIS
19- Given the repository name, execute the script in its directory .
13+ Creates and checks out `release` if not already on it .
2014#>
21- function Use-Repository {
22- [CmdletBinding ()]
15+ function Update-Branch {
16+ [CmdletBinding (SupportsShouldProcess )]
2317 param (
2418 [Parameter (Mandatory )]
2519 [ValidateSet ([RepoNames ])]
26- [string ]$RepositoryName ,
27-
28- [Parameter (Mandatory )]
29- [scriptblock ]$Script
20+ [string ]$RepositoryName
3021 )
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"
3827 }
3928 }
40- & $Script
41- } finally {
42- Pop-Location
4329 }
4430}
4531
@@ -143,72 +129,6 @@ function Get-Bullets {
143129 }
144130}
145131
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-
212132<#
213133. SYNOPSIS
214134 Updates the CHANGELOG file with PRs merged since the last release.
@@ -224,12 +144,13 @@ function Update-Changelog {
224144 [ValidateSet ([RepoNames ])]
225145 [string ]$RepositoryName ,
226146
227- # TODO: Validate version style for each repo.
228147 [Parameter (Mandatory )]
229- [ValidateScript ({ $_.StartsWith (" v" ) })]
230148 [string ]$Version
231149 )
232150
151+ # Since we depend on both parameters, we can't do this with `ValidateScript`.
152+ Test-VersionIsValid - RepositoryName $RepositoryName - Version $Version
153+
233154 # Get the repo object, latest release, and commits since its tag.
234155 $Repo = Get-GitHubRepository - OwnerName PowerShell - RepositoryName $RepositoryName
235156 $Commits = Use-Repository - RepositoryName $RepositoryName - Script {
@@ -300,8 +221,8 @@ function Update-Changelog {
300221
301222 - package.json:
302223 - `version` field with `"X.Y.Z"` and no prefix or suffix
303- - `preview` field set to `true` or ` false` if version is a preview
304- - `icon` field has `_Preview ` inserted if preview
224+ - `preview` field is always ` false` because now we do "pre-releases"
225+ - TODO: `icon` field has `_Preview ` inserted if preview
305226#>
306227function Update-Version {
307228 [CmdletBinding (SupportsShouldProcess )]
@@ -311,28 +232,26 @@ function Update-Version {
311232 [string ]$RepositoryName
312233 )
313234 $Version = Get-Version - RepositoryName $RepositoryName
314- $v = " $ ( $ Version.Major ) . $ ( $ Version.Minor ) . $ ( $Version .Patch ) "
235+ $v = Get-MajorMinorPatch - Version $ Version
315236
316237 Update-Branch - RepositoryName $RepositoryName
317238
318239 Use-Repository - RepositoryName $RepositoryName - Script {
319240 switch ($RepositoryName ) {
320241 " vscode-powershell" {
321- if ($Version.PreReleaseLabel ) {
322- $preview = " true"
323- $icon = " media/PowerShell_Preview_Icon.png"
324- } else {
325- $preview = " false"
326- $icon = " media/PowerShell_Icon.png"
327- }
242+ # TODO: Bring this back when the marketplace supports it.
243+ # if ($Version.PreReleaseLabel) {
244+ # $icon = "media/PowerShell_Preview_Icon.png"
245+ # } else {
246+ # $icon = "media/PowerShell_Icon.png"
247+ # }
328248
329249 $path = " package.json"
330250 $f = Get-Content - Path $path
331251 # NOTE: The prefix regex match two spaces exactly to avoid matching
332252 # nested objects in the file.
333253 $f = $f -replace ' ^(?<prefix> "version":\s+")(.+)(?<suffix>",)$' , " `$ {prefix}${v} `$ {suffix}"
334- $f = $f -replace ' ^(?<prefix> "preview":\s+)(.+)(?<suffix>,)$' , " `$ {prefix}${preview} `$ {suffix}"
335- $f = $f -replace ' ^(?<prefix> "icon":\s+")(.+)(?<suffix>",)$' , " `$ {prefix}${icon} `$ {suffix}"
254+ # TODO: $f = $f -replace '^(?<prefix> "icon":\s+")(.+)(?<suffix>",)$', "`${prefix}${icon}`${suffix}"
336255 $f | Set-Content - Path $path
337256 git add $path
338257 }
0 commit comments