From e6df6d596a51ee3d795f8707d43654f4516adc61 Mon Sep 17 00:00:00 2001 From: Ivan Dlugos Date: Fri, 7 Feb 2025 15:34:19 +0100 Subject: [PATCH 1/3] fix: truncate changelog if oldTag is missing --- updater/scripts/get-changelog.ps1 | 49 ++++++++++++++++++++++----- updater/tests/get-changelog.Tests.ps1 | 19 +++++++++++ 2 files changed, 59 insertions(+), 9 deletions(-) diff --git a/updater/scripts/get-changelog.ps1 b/updater/scripts/get-changelog.ps1 index d7ae438..90d5d72 100644 --- a/updater/scripts/get-changelog.ps1 +++ b/updater/scripts/get-changelog.ps1 @@ -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" diff --git a/updater/tests/get-changelog.Tests.ps1 b/updater/tests/get-changelog.Tests.ps1 index 313ec4b..0e2b5c5 100644 --- a/updater/tests/get-changelog.Tests.ps1 +++ b/updater/tests/get-changelog.Tests.ps1 @@ -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' From 964582e9c2c9676770867e0136e27f5cb8979c38 Mon Sep 17 00:00:00 2001 From: Ivan Dlugos Date: Fri, 7 Feb 2025 15:35:29 +0100 Subject: [PATCH 2/3] chore: changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index afb7fcc..7a9157d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 the earliest older SemVer even if if the previous version is missing ([#84](https://github.com/getsentry/github-workflows/pull/84)) ## 2.11.0 From 1e702e5d795a6053c0745e4c5915371402b9f7b1 Mon Sep 17 00:00:00 2001 From: Ivan Dlugos Date: Fri, 7 Feb 2025 15:37:47 +0100 Subject: [PATCH 3/3] chore: changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a9157d..d65c03c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +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 the earliest older SemVer even if if the previous version is missing ([#84](https://github.com/getsentry/github-workflows/pull/84)) +- Truncate changelog to nearest SemVer even if actual previous version is missing ([#84](https://github.com/getsentry/github-workflows/pull/84)) ## 2.11.0