@@ -14,11 +14,41 @@ class RepoNames: IValidateSetValuesGenerator {
14
14
15
15
$ChangelogFile = " CHANGELOG.md"
16
16
17
+ <#
18
+ . SYNOPSIS
19
+ Given the repository name, execute the script in its directory.
20
+ #>
21
+ function Use-Repository {
22
+ [CmdletBinding ()]
23
+ param (
24
+ [Parameter (Mandatory )]
25
+ [ValidateSet ([RepoNames ])]
26
+ [string ]$RepositoryName ,
27
+
28
+ [Parameter (Mandatory )]
29
+ [scriptblock ]$Script
30
+ )
31
+ try {
32
+ switch ($RepositoryName ) {
33
+ " vscode-powershell" {
34
+ Push-Location - Path " $PSScriptRoot /../"
35
+ }
36
+ " PowerShellEditorServices" {
37
+ Push-Location - Path " $PSScriptRoot /../../PowerShellEditorServices"
38
+ }
39
+ }
40
+ & $Script
41
+ } finally {
42
+ Pop-Location
43
+ }
44
+ }
45
+
17
46
<#
18
47
. SYNOPSIS
19
48
Given a collection of PRs, generates a bulleted list.
20
49
#>
21
50
function Get-Bullets {
51
+ [CmdletBinding ()]
22
52
param (
23
53
[Parameter (Mandatory )]
24
54
[ValidateSet ([RepoNames ])]
@@ -124,7 +154,9 @@ function Get-FirstChangelog {
124
154
[ValidateSet ([RepoNames ])]
125
155
[string ]$RepositoryName
126
156
)
127
- $Changelog = Get-Content - Path " $PSScriptRoot /../../$RepositoryName /$ChangelogFile "
157
+ $Changelog = Use-Repository - Name $RepositoryName - Script {
158
+ Get-Content - Path $ChangelogFile
159
+ }
128
160
# NOTE: The space after the header marker is important! Otherwise ### matches.
129
161
$Header = $Changelog.Where ({$_.StartsWith (" ## " )}, " First" )
130
162
$Changelog.Where (
@@ -140,10 +172,17 @@ function Get-FirstChangelog {
140
172
#>
141
173
function Update-Branch {
142
174
[CmdletBinding (SupportsShouldProcess )]
143
- $Branch = git branch -- show-current
144
- if ($Branch -ne " release" ) {
145
- if ($PSCmdlet.ShouldProcess (" release" , " git checkout -b" )) {
146
- git checkout - b " release"
175
+ param (
176
+ [Parameter (Mandatory )]
177
+ [ValidateSet ([RepoNames ])]
178
+ [string ]$RepositoryName
179
+ )
180
+ Use-Repository - Name $RepositoryName - Script {
181
+ $Branch = git branch -- show-current
182
+ if ($Branch -ne " release" ) {
183
+ if ($PSCmdlet.ShouldProcess (" release" , " git checkout -b" )) {
184
+ git checkout - b " release"
185
+ }
147
186
}
148
187
}
149
188
}
@@ -187,12 +226,12 @@ function Update-Changelog {
187
226
[ValidateScript ({ $_.StartsWith (" v" ) })]
188
227
[string ]$Version
189
228
)
190
- # NOTE: This a side effect neccesary for Git operations to work.
191
- Push-Location - Path " $PSScriptRoot /../../$RepositoryName "
192
229
193
230
# Get the repo object, latest release, and commits since its tag.
194
231
$Repo = Get-GitHubRepository - OwnerName PowerShell - RepositoryName $RepositoryName
195
- $Commits = git rev- list " v$ ( Get-Version - RepositoryName $RepositoryName ) ..."
232
+ $Commits = Use-Repository - Name $RepositoryName - Script {
233
+ git rev- list " v$ ( Get-Version - RepositoryName $RepositoryName ) ..."
234
+ }
196
235
197
236
# NOTE: This is a slow API as it gets all PRs, and then filters.
198
237
$Bullets = $Repo | Get-GitHubPullRequest - State All |
@@ -220,28 +259,27 @@ function Update-Changelog {
220
259
}
221
260
}
222
261
223
- $CurrentChangelog = Get-Content - Path $ChangelogFile
224
-
225
- @ (
226
- $CurrentChangelog [0 .. 1 ]
227
- " ## $Version "
228
- " ### $ ( [datetime ]::Now.ToString(' dddd, MMMM dd, yyyy' )) "
229
- " "
230
- $NewSection
231
- " "
232
- $CurrentChangelog [2 .. $CurrentChangelog.Length ]
233
- ) | Set-Content - Encoding utf8NoBOM - Path $ChangelogFile
234
-
235
- Update-Branch
236
-
237
- if ($PSCmdlet.ShouldProcess (" $RepositoryName /$ChangelogFile " , " git commit" )) {
238
- git add $ChangelogFile
239
- git commit - m " Update CHANGELOG for `` $Version `` "
262
+ Update-Branch - RepositoryName $RepositoryName
263
+
264
+ Use-Repository - Name $RepositoryName - Script {
265
+ $CurrentChangelog = Get-Content - Path $ChangelogFile
266
+ @ (
267
+ $CurrentChangelog [0 .. 1 ]
268
+ " ## $Version "
269
+ " ### $ ( [datetime ]::Now.ToString(' dddd, MMMM dd, yyyy' )) "
270
+ " "
271
+ $NewSection
272
+ " "
273
+ $CurrentChangelog [2 .. $CurrentChangelog.Length ]
274
+ ) | Set-Content - Encoding utf8NoBOM - Path $ChangelogFile
275
+
276
+ if ($PSCmdlet.ShouldProcess (" $RepositoryName /$ChangelogFile " , " git commit" )) {
277
+ git add $ChangelogFile
278
+ git commit - m " Update CHANGELOG for `` $Version `` "
279
+ }
240
280
}
241
281
242
282
Update-Version - RepositoryName $RepositoryName
243
-
244
- Pop-Location
245
283
}
246
284
247
285
<#
@@ -274,63 +312,62 @@ function Update-Version {
274
312
[ValidateSet ([RepoNames ])]
275
313
[string ]$RepositoryName
276
314
)
277
- # NOTE: This a side effect neccesary for Git operations to work.
278
- Push-Location - Path " $PSScriptRoot /../../$RepositoryName "
279
-
280
315
$Version = Get-Version - RepositoryName $RepositoryName
281
316
$v = " $ ( $Version.Major ) .$ ( $Version.Minor ) .$ ( $Version.Patch ) "
317
+
318
+ Update-Branch - RepositoryName $RepositoryName
319
+
282
320
# TODO: Maybe cleanup the replacement logic.
283
- switch ($RepositoryName ) {
284
- " vscode-powershell" {
285
- $d = " Develop PowerShell modules, commands and scripts in Visual Studio Code!"
286
- if ($Version.PreReleaseLabel ) {
287
- $name = " powershell-preview"
288
- $displayName = " PowerShell Preview"
289
- $preview = " true"
290
- $description = " (Preview) $d "
291
- } else {
292
- $name = " powershell"
293
- $displayName = " PowerShell"
294
- $preview = " false"
295
- $description = $d
321
+ Use-Repository - Name $RepositoryName - Script {
322
+ switch ($RepositoryName ) {
323
+ " vscode-powershell" {
324
+ $d = " Develop PowerShell modules, commands and scripts in Visual Studio Code!"
325
+ if ($Version.PreReleaseLabel ) {
326
+ $name = " powershell-preview"
327
+ $displayName = " PowerShell Preview"
328
+ $preview = " true"
329
+ $description = " (Preview) $d "
330
+ } else {
331
+ $name = " powershell"
332
+ $displayName = " PowerShell"
333
+ $preview = " false"
334
+ $description = $d
335
+ }
336
+
337
+ $path = " package.json"
338
+ $f = Get-Content - Path $path
339
+ # NOTE: The prefix regex match two spaces exactly to avoid matching
340
+ # nested objects in the file.
341
+ $f = $f -replace ' ^(?<prefix> "name":\s+")(.+)(?<suffix>",)$' , " `$ {prefix}${name} `$ {suffix}"
342
+ $f = $f -replace ' ^(?<prefix> "displayName":\s+")(.+)(?<suffix>",)$' , " `$ {prefix}${displayName} `$ {suffix}"
343
+ $f = $f -replace ' ^(?<prefix> "version":\s+")(.+)(?<suffix>",)$' , " `$ {prefix}${v} `$ {suffix}"
344
+ $f = $f -replace ' ^(?<prefix> "preview":\s+)(.+)(?<suffix>,)$' , " `$ {prefix}${preview} `$ {suffix}"
345
+ $f = $f -replace ' ^(?<prefix> "description":\s+")(.+)(?<suffix>",)$' , " `$ {prefix}${description} `$ {suffix}"
346
+ $f | Set-Content - Path $path
347
+ git add $path
348
+ }
349
+ " PowerShellEditorServices" {
350
+ $path = " PowerShellEditorServices.Common.props"
351
+ $f = Get-Content - Path $path
352
+ $f = $f -replace ' ^(?<prefix>\s+<VersionPrefix>)(.+)(?<suffix></VersionPrefix>)$' , " `$ {prefix}${v} `$ {suffix}"
353
+ $f = $f -replace ' ^(?<prefix>\s+<VersionSuffix>)(.*)(?<suffix></VersionSuffix>)$' , " `$ {prefix}$ ( $Version.PreReleaseLabel ) `$ {suffix}"
354
+ $f | Set-Content - Path $path
355
+ git add $path
356
+
357
+ $path = " module/PowerShellEditorServices/PowerShellEditorServices.psd1"
358
+ $f = Get-Content - Path $path
359
+ $f = $f -replace " ^(?<prefix>ModuleVersion = ')(.+)(?<suffix>')`$ " , " `$ {prefix}${v} `$ {suffix}"
360
+ $f | Set-Content - Path $path
361
+ git add $path
296
362
}
297
- $path = " package.json"
298
- $f = Get-Content - Path $path
299
- # NOTE: The prefix regex match two spaces exactly to avoid matching
300
- # nested objects in the file.
301
- $f = $f -replace ' ^(?<prefix> "name":\s+")(.+)(?<suffix>",)$' , " `$ {prefix}${name} `$ {suffix}"
302
- $f = $f -replace ' ^(?<prefix> "displayName":\s+")(.+)(?<suffix>",)$' , " `$ {prefix}${displayName} `$ {suffix}"
303
- $f = $f -replace ' ^(?<prefix> "version":\s+")(.+)(?<suffix>",)$' , " `$ {prefix}${v} `$ {suffix}"
304
- $f = $f -replace ' ^(?<prefix> "preview":\s+)(.+)(?<suffix>,)$' , " `$ {prefix}${preview} `$ {suffix}"
305
- $f = $f -replace ' ^(?<prefix> "description":\s+")(.+)(?<suffix>",)$' , " `$ {prefix}${description} `$ {suffix}"
306
- $f | Set-Content - Path $path
307
- git add $path
308
- }
309
- " PowerShellEditorServices" {
310
- $path = " PowerShellEditorServices.Common.props"
311
- $f = Get-Content - Path $path
312
- $f = $f -replace ' ^(?<prefix>\s+<VersionPrefix>)(.+)(?<suffix></VersionPrefix>)$' , " `$ {prefix}${v} `$ {suffix}"
313
- $f = $f -replace ' ^(?<prefix>\s+<VersionSuffix>)(.*)(?<suffix></VersionSuffix>)$' , " `$ {prefix}$ ( $Version.PreReleaseLabel ) `$ {suffix}"
314
- $f | Set-Content - Path $path
315
- git add $path
316
-
317
- $path = " module/PowerShellEditorServices/PowerShellEditorServices.psd1"
318
- $f = Get-Content - Path $path
319
- $f = $f -replace " ^(?<prefix>ModuleVersion = ')(.+)(?<suffix>')`$ " , " `$ {prefix}${v} `$ {suffix}"
320
- $f | Set-Content - Path $path
321
- git add $path
322
363
}
323
- }
324
-
325
- Update-Branch
326
364
327
- if ($PSCmdlet.ShouldProcess (" $RepositoryName /v$Version " , " git commit" )) {
328
- git commit - m " Bump version to `` v$Version `` "
329
- } # TODO: Git reset to unstage
365
+ if ($PSCmdlet.ShouldProcess (" $RepositoryName /v$Version " , " git commit" )) {
366
+ git commit - m " Bump version to `` v$Version `` "
367
+ } # TODO: Git reset to unstage
368
+ }
330
369
331
370
New-ReleasePR - RepositoryName $RepositoryName
332
-
333
- Pop-Location
334
371
}
335
372
336
373
<#
@@ -346,17 +383,15 @@ function New-ReleasePR {
346
383
[ValidateSet ([RepoNames ])]
347
384
[string ]$RepositoryName
348
385
)
349
- # NOTE: This a side effect neccesary for Git operations to work.
350
- Push-Location - Path " $PSScriptRoot /../../$RepositoryName "
351
-
352
386
$Version = Get-Version - RepositoryName $RepositoryName
353
387
$Branch = " release/v$Version "
354
388
355
- Update-Branch - Version $Version
356
-
357
- if ($PSCmdlet.ShouldProcess (" $RepositoryName /$Branch " , " git push" )) {
358
- Write-Host " Pushing branch `` $Branch `` ..."
359
- git push origin $Branch
389
+ Update-Branch - RepositoryName $RepositoryName
390
+ Use-Repository - Name $RepositoryName - Script {
391
+ if ($PSCmdlet.ShouldProcess (" $RepositoryName /$Branch " , " git push" )) {
392
+ Write-Host " Pushing branch `` $Branch `` ..."
393
+ git push origin $Branch
394
+ }
360
395
}
361
396
362
397
$Repo = Get-GitHubRepository - OwnerName PowerShell - RepositoryName $RepositoryName
@@ -376,8 +411,6 @@ function New-ReleasePR {
376
411
# NOTE: The API is weird. According to GitHub, all PRs are Issues, so this
377
412
# works, but the module doesn't support it as easily as it could.
378
413
$Repo | Add-GitHubIssueLabel - Issue $PR.PullRequestNumber - LabelName " Ignore"
379
-
380
- Pop-Location
381
414
}
382
415
383
416
<#
0 commit comments