-
Notifications
You must be signed in to change notification settings - Fork 2
/
roll-changelog.ps1
19 lines (16 loc) · 1007 Bytes
/
roll-changelog.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
param ($path, $version)
$absolutePath = Resolve-Path -Path $path
[System.Collections.Generic.List[string]]$lines = Get-Content -Path $absolutePath
$unreleasedRefLineIndex = $lines.FindLastIndex({ param ($x) $x.StartsWith("[Unreleased]:") })
$unreleasedRefLine = $lines[$unreleasedRefLineIndex]
$versionStartIndex = $unreleasedRefLine.LastIndexOf('/') + 1
$unreleasedRefPrefix = $unreleasedRefLine.Substring(0, $versionStartIndex)
$newUnreleasedRefLine = "${unreleasedRefPrefix}v${version}...HEAD"
$lines[$unreleasedRefLineIndex] = $unreleasedRefLine.Replace("Unreleased", $version).Replace("...HEAD", "...v${version}")
$lines.Insert($unreleasedRefLineIndex, $newUnreleasedRefLine)
$unreleasedStartLineIndex = $lines.IndexOf("## [Unreleased]")
$formattedDate = Get-Date -UFormat "%Y-%m-%d"
$lines[$unreleasedStartLineIndex] = "## [${version}] - ${formattedDate}"
$lines.Insert($unreleasedStartLineIndex, "")
$lines.Insert($unreleasedStartLineIndex, "## [Unreleased]")
Set-Content -Path $path -Value $lines