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,72 +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
132
<#
213
133
. SYNOPSIS
214
134
Updates the CHANGELOG file with PRs merged since the last release.
@@ -224,12 +144,13 @@ function Update-Changelog {
224
144
[ValidateSet ([RepoNames ])]
225
145
[string ]$RepositoryName ,
226
146
227
- # TODO: Validate version style for each repo.
228
147
[Parameter (Mandatory )]
229
- [ValidateScript ({ $_.StartsWith (" v" ) })]
230
148
[string ]$Version
231
149
)
232
150
151
+ # Since we depend on both parameters, we can't do this with `ValidateScript`.
152
+ Test-VersionIsValid - RepositoryName $RepositoryName - Version $Version
153
+
233
154
# Get the repo object, latest release, and commits since its tag.
234
155
$Repo = Get-GitHubRepository - OwnerName PowerShell - RepositoryName $RepositoryName
235
156
$Commits = Use-Repository - RepositoryName $RepositoryName - Script {
@@ -300,8 +221,8 @@ function Update-Changelog {
300
221
301
222
- package.json:
302
223
- `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
305
226
#>
306
227
function Update-Version {
307
228
[CmdletBinding (SupportsShouldProcess )]
@@ -311,28 +232,26 @@ function Update-Version {
311
232
[string ]$RepositoryName
312
233
)
313
234
$Version = Get-Version - RepositoryName $RepositoryName
314
- $v = " $ ( $ Version.Major ) . $ ( $ Version.Minor ) . $ ( $Version .Patch ) "
235
+ $v = Get-MajorMinorPatch - Version $ Version
315
236
316
237
Update-Branch - RepositoryName $RepositoryName
317
238
318
239
Use-Repository - RepositoryName $RepositoryName - Script {
319
240
switch ($RepositoryName ) {
320
241
" 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
+ # }
328
248
329
249
$path = " package.json"
330
250
$f = Get-Content - Path $path
331
251
# NOTE: The prefix regex match two spaces exactly to avoid matching
332
252
# nested objects in the file.
333
253
$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}"
336
255
$f | Set-Content - Path $path
337
256
git add $path
338
257
}
0 commit comments