Skip to content

Commit 445f392

Browse files
vaindclaude
andcommitted
fix: correct PowerShell script exit code handling in get-changelog.ps1
- Restructure script to use result variable instead of early returns - Ensure proper exit handling in try/catch/finally blocks - Fix CI failures caused by exit code 1 from PowerShell script - All tests continue to pass (62/62 tests passing) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 470fc2e commit 445f392

File tree

1 file changed

+77
-65
lines changed

1 file changed

+77
-65
lines changed

updater/scripts/get-changelog.ps1

Lines changed: 77 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -43,92 +43,104 @@ function Get-ChangelogContent {
4343
return $false
4444
}
4545

46+
$result = ''
4647
try {
4748
Write-Host 'Fetching CHANGELOG files for comparison...'
4849

4950
# Fetch old changelog
5051
$oldChangelogPath = Join-Path $tmpDir 'old-changelog.md'
5152
if (-not (Get-ChangelogContent $OldTag $oldChangelogPath)) {
5253
Write-Warning "Could not find changelog at $OldTag"
53-
return
54+
$result = ''
5455
}
56+
else {
57+
# Fetch new changelog
58+
$newChangelogPath = Join-Path $tmpDir 'new-changelog.md'
59+
if (-not (Get-ChangelogContent $NewTag $newChangelogPath)) {
60+
Write-Warning "Could not find changelog at $NewTag"
61+
$result = ''
62+
}
63+
else {
5564

56-
# Fetch new changelog
57-
$newChangelogPath = Join-Path $tmpDir 'new-changelog.md'
58-
if (-not (Get-ChangelogContent $NewTag $newChangelogPath)) {
59-
Write-Warning "Could not find changelog at $NewTag"
60-
return
61-
}
62-
63-
Write-Host "Generating changelog diff between $OldTag and $NewTag..."
64-
65-
# Generate diff using git diff --no-index
66-
$fullDiff = git diff --no-index $oldChangelogPath $newChangelogPath
67-
68-
# The first lines are diff metadata, skip them
69-
$fullDiff = $fullDiff -split "`n" | Select-Object -Skip 4
70-
71-
if ([string]::IsNullOrEmpty($fullDiff)) {
72-
Write-Host "No differences found between $OldTag and $NewTag"
73-
return ''
74-
}
75-
76-
# Extract only the added lines (lines starting with + but not ++)
77-
$addedLines = $fullDiff | Where-Object { $_ -match '^[+][^+]*' } | ForEach-Object { $_.Substring(1) }
78-
79-
if ($addedLines.Count -gt 0) {
80-
# Create clean changelog from added lines
81-
$changelog = ($addedLines -join "`n").Trim()
82-
83-
# Apply formatting to clean changelog
84-
if ($changelog.Length -gt 0) {
85-
# Add header
86-
if (-not ($changelog -match '^(##|#) Changelog')) {
87-
$changelog = "## Changelog`n`n$changelog"
88-
}
65+
Write-Host "Generating changelog diff between $OldTag and $NewTag..."
8966

90-
# Increase header level by one for content (not the main header)
91-
$changelog = $changelog -replace '(^|\n)(#+) ', '$1$2# ' -replace '^### Changelog', '## Changelog'
67+
# Generate diff using git diff --no-index
68+
$fullDiff = git diff --no-index $oldChangelogPath $newChangelogPath
9269

93-
# Only add details section if there are deletions or modifications (not just additions)
94-
$hasModifications = $fullDiff | Where-Object { $_ -match '^[-]' -and $_ -notmatch '^[-]{3}' }
95-
if ($hasModifications) {
96-
$changelog += "`n`n<details>`n<summary>Full CHANGELOG.md diff</summary>`n`n"
97-
$changelog += '```diff' + "`n"
98-
$changelog += $fullDiff -join "`n"
99-
$changelog += "`n" + '```' + "`n`n</details>"
100-
}
70+
# The first lines are diff metadata, skip them
71+
$fullDiff = $fullDiff -split "`n" | Select-Object -Skip 4
10172

102-
# Apply standard formatting
103-
# Remove at-mentions.
104-
$changelog = $changelog -replace '@', ''
105-
# Make PR/issue references into links to the original repository (unless they already are links).
106-
$changelog = $changelog -replace '(?<!\[)#([0-9]+)(?![\]0-9])', ('[#$1](' + $RepoUrl + '/issues/$1)')
107-
# Replace any links pointing to github.com so that the target PRs/Issues don't get na notification.
108-
$changelog = $changelog -replace ('\(' + $prefix), '(https://github-redirect.dependabot.com/'
109-
110-
# Limit the changelog length to ~60k to allow for other text in the PR body (total PR limit is 65536 characters).
111-
$limit = 60000
112-
if ($changelog.Length -gt $limit) {
113-
$oldLength = $changelog.Length
114-
Write-Warning "Truncating changelog because it's $($changelog.Length - $limit) characters longer than the limit $limit."
115-
while ($changelog.Length -gt $limit) {
116-
$changelog = $changelog.Substring(0, $changelog.LastIndexOf("`n"))
73+
if ([string]::IsNullOrEmpty($fullDiff)) {
74+
Write-Host "No differences found between $OldTag and $NewTag"
75+
$result = ''
76+
}
77+
else {
78+
79+
# Extract only the added lines (lines starting with + but not ++)
80+
$addedLines = $fullDiff | Where-Object { $_ -match '^[+][^+]*' } | ForEach-Object { $_.Substring(1) }
81+
82+
if ($addedLines.Count -gt 0) {
83+
# Create clean changelog from added lines
84+
$changelog = ($addedLines -join "`n").Trim()
85+
86+
# Apply formatting to clean changelog
87+
if ($changelog.Length -gt 0) {
88+
# Add header
89+
if (-not ($changelog -match '^(##|#) Changelog')) {
90+
$changelog = "## Changelog`n`n$changelog"
91+
}
92+
93+
# Increase header level by one for content (not the main header)
94+
$changelog = $changelog -replace '(^|\n)(#+) ', '$1$2# ' -replace '^### Changelog', '## Changelog'
95+
96+
# Only add details section if there are deletions or modifications (not just additions)
97+
$hasModifications = $fullDiff | Where-Object { $_ -match '^[-]' -and $_ -notmatch '^[-]{3}' }
98+
if ($hasModifications) {
99+
$changelog += "`n`n<details>`n<summary>Full CHANGELOG.md diff</summary>`n`n"
100+
$changelog += '```diff' + "`n"
101+
$changelog += $fullDiff -join "`n"
102+
$changelog += "`n" + '```' + "`n`n</details>"
103+
}
104+
105+
# Apply standard formatting
106+
# Remove at-mentions.
107+
$changelog = $changelog -replace '@', ''
108+
# Make PR/issue references into links to the original repository (unless they already are links).
109+
$changelog = $changelog -replace '(?<!\[)#([0-9]+)(?![\]0-9])', ('[#$1](' + $RepoUrl + '/issues/$1)')
110+
# Replace any links pointing to github.com so that the target PRs/Issues don't get na notification.
111+
$changelog = $changelog -replace ('\(' + $prefix), '(https://github-redirect.dependabot.com/'
112+
113+
# Limit the changelog length to ~60k to allow for other text in the PR body (total PR limit is 65536 characters).
114+
$limit = 60000
115+
if ($changelog.Length -gt $limit) {
116+
$oldLength = $changelog.Length
117+
Write-Warning "Truncating changelog because it's $($changelog.Length - $limit) characters longer than the limit $limit."
118+
while ($changelog.Length -gt $limit) {
119+
$changelog = $changelog.Substring(0, $changelog.LastIndexOf("`n"))
120+
}
121+
$changelog += "`n`n> :warning: **Changelog content truncated by $($oldLength - $changelog.Length) characters because it was over the limit ($limit) and wouldn't fit into PR description.**"
122+
}
123+
124+
$result = $changelog
125+
} else {
126+
$result = ''
117127
}
118-
$changelog += "`n`n> :warning: **Changelog content truncated by $($oldLength - $changelog.Length) characters because it was over the limit ($limit) and wouldn't fit into PR description.**"
128+
} else {
129+
Write-Host "No changelog additions found between $OldTag and $NewTag"
130+
$result = ''
119131
}
120-
121-
return $changelog
132+
}
122133
}
123134
}
124-
125-
Write-Host "No changelog additions found between $OldTag and $NewTag"
126-
return ''
127135
} catch {
128136
Write-Warning "Failed to get changelog: $($_.Exception.Message)"
137+
$result = ''
129138
} finally {
130139
if (Test-Path $tmpDir) {
131140
Write-Host 'Cleaning up temporary files...'
132141
Remove-Item -Recurse -Force -ErrorAction Continue $tmpDir
133142
}
134143
}
144+
145+
# Output the result
146+
$result

0 commit comments

Comments
 (0)