Skip to content

Commit e9e4be4

Browse files
authored
fix: truncate changelog to nearest SemVer even if actual previous version is missing (#84)
* fix: truncate changelog if oldTag is missing * chore: changelog * chore: changelog
1 parent 1456273 commit e9e4be4

File tree

3 files changed

+60
-9
lines changed

3 files changed

+60
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
- Don't update from a manually-updated prerelease to a latest stable release that is earlier than the prerelease ([#78](https://github.com/getsentry/github-workflows/pull/78))
88
- Cross-repo links in changelog notes ([#82](https://github.com/getsentry/github-workflows/pull/82))
9+
- Truncate changelog to nearest SemVer even if actual previous version is missing ([#84](https://github.com/getsentry/github-workflows/pull/84))
910

1011
## 2.11.0
1112

updater/scripts/get-changelog.ps1

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,32 +40,63 @@ finally
4040
Remove-Item -Recurse -Force -ErrorAction Continue -Path $tmpDir
4141
}
4242

43-
$foundFirst = $false
43+
$startIndex = -1
44+
$endIndex = -1
4445
$changelog = ''
4546
for ($i = 0; $i -lt $lines.Count; $i++)
4647
{
4748
$line = $lines[$i]
4849

49-
if (-not $foundFirst)
50+
if ($startIndex -lt 0)
5051
{
5152
if ($line -match "^#+ +v?$NewTag\b")
5253
{
53-
$foundFirst = $true
54-
}
55-
else
56-
{
57-
continue
54+
$startIndex = $i
5855
}
5956
}
6057
elseif ($line -match "^#+ +v?$OldTag\b")
6158
{
59+
$endIndex = $i - 1
6260
break
6361
}
62+
}
6463

65-
$changelog += "$line`n"
64+
# If the changelog doesn't have a section for the oldTag, stop at the first SemVer that's lower than oldTag.
65+
if ($endIndex -lt 0)
66+
{
67+
$endIndex = $lines.Count - 1 # fallback, may be overwritten below
68+
try
69+
{
70+
$semverOldTag = [System.Management.Automation.SemanticVersion]::Parse($OldTag)
71+
for ($i = $startIndex; $i -lt $lines.Count; $i++)
72+
{
73+
$line = $lines[$i]
74+
if ($line -match '^#+ +v?([0-9]+.*)$')
75+
{
76+
try
77+
{
78+
if ($semverOldTag -ge [System.Management.Automation.SemanticVersion]::Parse($matches[1]))
79+
{
80+
$endIndex = $i - 1
81+
break
82+
}
83+
}
84+
catch {}
85+
}
86+
}
87+
}
88+
catch {}
6689
}
6790

68-
$changelog = $changelog.Trim()
91+
# Slice changelog lines from startIndex to endIndex.
92+
if ($startIndex -ge 0)
93+
{
94+
$changelog = ($lines[$startIndex..$endIndex] -join "`n").Trim()
95+
}
96+
else
97+
{
98+
$changelog = ''
99+
}
69100
if ($changelog.Length -gt 1)
70101
{
71102
$changelog = "# Changelog`n$changelog"

updater/tests/get-changelog.Tests.ps1

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,25 @@ Features, fixes and improvements in this release have been contributed by:
8989
$actual | Should -Be $expected
9090
}
9191

92+
It 'Does not show versions older than OldTag even if OldTag is missing' {
93+
$actual = & "$PSScriptRoot/../scripts/get-changelog.ps1" `
94+
-RepoUrl 'https://github.com/getsentry/github-workflows' -OldTag '2.1.5' -NewTag '2.2.1'
95+
$actual | Should -Be @'
96+
## Changelog
97+
### 2.2.1
98+
99+
#### Fixes
100+
101+
- Support comments when parsing pinned actions in Danger ([#40](https://github-redirect.dependabot.com/getsentry/github-workflows/pull/40))
102+
103+
### 2.2.0
104+
105+
#### Features
106+
107+
- Danger - check for that actions are pinned to a commit ([#39](https://github-redirect.dependabot.com/getsentry/github-workflows/pull/39))
108+
'@
109+
}
110+
92111
It 'truncates too long text' {
93112
$actual = & "$PSScriptRoot/../scripts/get-changelog.ps1" `
94113
-RepoUrl 'https://github.com/getsentry/sentry-cli' -OldTag '1.0.0' -NewTag '2.4.0'

0 commit comments

Comments
 (0)