@@ -206,6 +206,95 @@ function Update-Changelog {
206206 Pop-Location
207207}
208208
209+ <#
210+ . SYNOPSIS
211+ Updates version in repository.
212+ . DESCRIPTION
213+ Note that our Git tags and changelog prefix all versions with `v`.
214+
215+ PowerShellEditorServices: version is `x.y.z-preview.d`
216+
217+ - PowerShellEditorServices.psd1:
218+ - `ModuleVersion` variable with `'x.y.z'` string, no pre-release info
219+ - PowerShellEditorServices.Common.props:
220+ - `VersionPrefix` field with `x.y.z`
221+ - `VersionSuffix` field with pre-release portion excluding hyphen
222+
223+ vscode-powershell: version is `yyyy.mm.x-preview`
224+
225+ - package.json:
226+ - `version` field with `"x.y.z"` and no prefix or suffix
227+ - `preview` field set to `true` or `false` if version is a preview
228+ - `name` field has `-preview` appended similarly
229+ - `displayName` field has ` Preview` appended similarly
230+ - `description` field has `(Preview) ` prepended similarly
231+ #>
232+ function Update-Version {
233+ [CmdletBinding (SupportsShouldProcess )]
234+ param (
235+ [Parameter (Mandatory )]
236+ [ValidateSet ([RepoNames ])]
237+ [string ]$RepositoryName
238+ )
239+ # NOTE: This a side effect neccesary for Git operations to work.
240+ Push-Location - Path " $PSScriptRoot /../../$RepositoryName "
241+
242+ $Version = Get-Version - RepositoryName $RepositoryName
243+ $v = " $ ( $Version.Major ) .$ ( $Version.Minor ) .$ ( $Version.Patch ) "
244+ # TODO: Maybe cleanup the replacement logic.
245+ switch ($RepositoryName ) {
246+ " vscode-powershell" {
247+ $d = " Develop PowerShell scripts in Visual Studio Code!"
248+ if ($Version.PreReleaseLabel ) {
249+ $name = " powershell-preview"
250+ $displayName = " PowerShell Preview"
251+ $preview = " true"
252+ $description = " (Preview) $d "
253+ } else {
254+ $name = " powershell"
255+ $displayName = " PowerShell"
256+ $preview = " false"
257+ $description = $d
258+ }
259+ $path = " package.json"
260+ $f = Get-Content - Path $path
261+ # NOTE: The prefix regex match two spaces exactly to avoid matching
262+ # nested objects in the file.
263+ $f = $f -replace ' ^(?<prefix> "name":\s+")(.+)(?<suffix>",)$' , " `$ {prefix}${name} `$ {suffix}"
264+ $f = $f -replace ' ^(?<prefix> "displayName":\s+")(.+)(?<suffix>",)$' , " `$ {prefix}${displayName} `$ {suffix}"
265+ $f = $f -replace ' ^(?<prefix> "version":\s+")(.+)(?<suffix>",)$' , " `$ {prefix}${v} `$ {suffix}"
266+ $f = $f -replace ' ^(?<prefix> "preview":\s+)(.+)(?<suffix>,)$' , " `$ {prefix}${preview} `$ {suffix}"
267+ $f = $f -replace ' ^(?<prefix> "description":\s+")(.+)(?<suffix>",)$' , " `$ {prefix}${description} `$ {suffix}"
268+ $f | Set-Content - Path $path
269+ git add $path
270+ }
271+ " PowerShellEditorServices" {
272+ $path = " PowerShellEditorServices.Common.props"
273+ $f = Get-Content - Path $path
274+ $f = $f -replace ' ^(?<prefix>\s+<VersionPrefix>)(.+)(?<suffix></VersionPrefix>)$' , " `$ {prefix}${v} `$ {suffix}"
275+ $f = $f -replace ' ^(?<prefix>\s+<VersionSuffix>)(.*)(?<suffix></VersionSuffix>)$' , " `$ {prefix}$ ( $Version.PreReleaseLabel ) `$ {suffix}"
276+ $f | Set-Content - Path $path
277+ git add $path
278+
279+ $path = " module/PowerShellEditorServices/PowerShellEditorServices.psd1"
280+ $f = Get-Content - Path $path
281+ $f = $f -replace " ^(?<prefix>ModuleVersion = ')(.+)(?<suffix>')`$ " , " `$ {prefix}${v} `$ {suffix}"
282+ $f | Set-Content - Path $path
283+ git add $path
284+ }
285+ }
286+
287+ if ($PSCmdlet.ShouldProcess (" $RepositoryName /v$Version " , " git commit" )) {
288+ git commit - m " Bump version to v$Version "
289+ }
290+
291+ if ($PSCmdlet.ShouldProcess (" $RepositoryName /v$Version " , " git tag" )) {
292+ git tag " v$Version "
293+ }
294+
295+ Pop-Location
296+ }
297+
209298<#
210299. SYNOPSIS
211300 Creates a new draft GitHub release from the updated changelog.
@@ -237,4 +326,4 @@ function New-DraftRelease {
237326 New-GitHubRelease @ReleaseParams
238327}
239328
240- Export-ModuleMember - Function Update-Changelog , New-DraftRelease
329+ Export-ModuleMember - Function Update-Changelog , Update-Version , New-DraftRelease
0 commit comments