-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
update-changelog.ps1
49 lines (38 loc) · 1.15 KB
/
update-changelog.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#! /usr/bin/env pwsh
param(
[Parameter(Mandatory = $true)][string] $ReleaseVersion,
[Parameter(Mandatory = $true)][string] $ReleaseNotesText,
[Parameter(Mandatory = $true)][string] $GitHubServerUrl
)
$ErrorActionPreference = "Stop"
if ($ReleaseVersion.StartsWith("v")) {
$ReleaseVersion = $ReleaseVersion.Substring(1)
}
Write-Host "Updating CHANGELOG for v$ReleaseVersion"
$repo = Join-Path $PSScriptRoot ".."
$changelog = Join-Path $repo "CHANGELOG.md"
$lines = Get-Content $changelog
$lines = [System.Collections.Generic.List[string]]$lines
$entry = [System.Collections.Generic.List[string]]@(
"",
"## ${ReleaseVersion}",
""
)
$releaseNotes = $ReleaseNotesText.Split("`n") | Select-Object -Skip 1
foreach ($line in $releaseNotes) {
if ($line -eq "") {
continue
}
if ($line.StartsWith("##")) {
break
}
if (!$line.StartsWith("* ")) {
continue
}
# Update the user's login to link to their GitHub profile
$line = $line -Replace "\@(([a-zA-Z0-9\-]+))", ('[@$1](' + $GitHubServerUrl + '/$1)')
$entry.Add($line)
}
$index = $lines.IndexOf("<!-- next-release -->")
$lines.InsertRange($index + 1, $entry)
$lines | Set-Content $changelog