Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- 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))
- Cross-repo links in changelog notes ([#82](https://github.com/getsentry/github-workflows/pull/82))
- Truncate changelog to nearest SemVer even if actual previous version is missing ([#84](https://github.com/getsentry/github-workflows/pull/84))

## 2.11.0

Expand Down
49 changes: 40 additions & 9 deletions updater/scripts/get-changelog.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -40,32 +40,63 @@ finally
Remove-Item -Recurse -Force -ErrorAction Continue -Path $tmpDir
}

$foundFirst = $false
$startIndex = -1
$endIndex = -1
$changelog = ''
for ($i = 0; $i -lt $lines.Count; $i++)
{
$line = $lines[$i]

if (-not $foundFirst)
if ($startIndex -lt 0)
{
if ($line -match "^#+ +v?$NewTag\b")
{
$foundFirst = $true
}
else
{
continue
$startIndex = $i
}
}
elseif ($line -match "^#+ +v?$OldTag\b")
{
$endIndex = $i - 1
break
}
}

$changelog += "$line`n"
# If the changelog doesn't have a section for the oldTag, stop at the first SemVer that's lower than oldTag.
if ($endIndex -lt 0)
{
$endIndex = $lines.Count - 1 # fallback, may be overwritten below
try
{
$semverOldTag = [System.Management.Automation.SemanticVersion]::Parse($OldTag)
for ($i = $startIndex; $i -lt $lines.Count; $i++)
{
$line = $lines[$i]
if ($line -match '^#+ +v?([0-9]+.*)$')
{
try
{
if ($semverOldTag -ge [System.Management.Automation.SemanticVersion]::Parse($matches[1]))
{
$endIndex = $i - 1
break
}
}
catch {}
}
}
}
catch {}
}

$changelog = $changelog.Trim()
# Slice changelog lines from startIndex to endIndex.
if ($startIndex -ge 0)
{
$changelog = ($lines[$startIndex..$endIndex] -join "`n").Trim()
}
else
{
$changelog = ''
}
if ($changelog.Length -gt 1)
{
$changelog = "# Changelog`n$changelog"
Expand Down
19 changes: 19 additions & 0 deletions updater/tests/get-changelog.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,25 @@ Features, fixes and improvements in this release have been contributed by:
$actual | Should -Be $expected
}

It 'Does not show versions older than OldTag even if OldTag is missing' {
$actual = & "$PSScriptRoot/../scripts/get-changelog.ps1" `
-RepoUrl 'https://github.com/getsentry/github-workflows' -OldTag '2.1.5' -NewTag '2.2.1'
$actual | Should -Be @'
## Changelog
### 2.2.1

#### Fixes

- Support comments when parsing pinned actions in Danger ([#40](https://github-redirect.dependabot.com/getsentry/github-workflows/pull/40))

### 2.2.0

#### Features

- Danger - check for that actions are pinned to a commit ([#39](https://github-redirect.dependabot.com/getsentry/github-workflows/pull/39))
'@
}

It 'truncates too long text' {
$actual = & "$PSScriptRoot/../scripts/get-changelog.ps1" `
-RepoUrl 'https://github.com/getsentry/sentry-cli' -OldTag '1.0.0' -NewTag '2.4.0'
Expand Down