Skip to content

Commit b0642f4

Browse files
committed
Refactor GitHub Actions workflow to improve commit collection for release notes. Changed variable names for clarity, ensured newlines are preserved when storing commits, and streamlined the creation of release notes.
1 parent 2b8f5e2 commit b0642f4

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

.github/workflows/build-and-release.yml

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -93,48 +93,48 @@ jobs:
9393
}
9494
9595
# Get commits since last tag (or all commits if no tag exists)
96-
$commits = ""
96+
$commitLines = @()
9797
if ($lastTag) {
9898
Write-Host "Collecting commits since tag: $lastTag"
99-
$commits = git log --pretty=format:"- %s" --no-merges "$lastTag..HEAD" 2>$null
99+
$commitLines = git log --pretty=format:"- %s" --no-merges "$lastTag..HEAD" 2>$null
100100
} else {
101101
Write-Host "No previous tag found, collecting all commits"
102-
$commits = git log --pretty=format:"- %s" --no-merges
102+
$commitLines = git log --pretty=format:"- %s" --no-merges
103103
}
104104
105105
# Handle empty commit list
106-
if ([string]::IsNullOrWhiteSpace($commits)) {
106+
if ($null -eq $commitLines -or $commitLines.Count -eq 0 -or ($commitLines.Count -eq 1 -and [string]::IsNullOrWhiteSpace($commitLines[0]))) {
107107
$commits = "- No changes (only merge commits)"
108108
Write-Host "Warning: No non-merge commits found"
109109
} else {
110-
Write-Host "Found commits for release notes"
110+
# Join commit lines with newlines
111+
$commits = $commitLines -join "`n"
112+
Write-Host "Found $($commitLines.Count) commits for release notes"
111113
}
112114
113-
# Store in GitHub output (escape newlines and special characters)
114-
$commitsEscaped = $commits -replace "`r?`n", "`n" -replace '"', '`"'
115-
echo "commits<<EOF" >> $env:GITHUB_OUTPUT
116-
echo "$commitsEscaped" >> $env:GITHUB_OUTPUT
117-
echo "EOF" >> $env:GITHUB_OUTPUT
115+
# Store in GitHub output using EOF delimiter to preserve newlines
116+
"commits<<EOF" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
117+
$commits | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
118+
"EOF" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
118119
119120
- name: Create Release
120121
run: |
121122
$version = "${{ steps.get_version.outputs.version }}"
122123
$exeName = "${{ steps.build_executable.outputs.exe_name }}"
123124
$exePath = "${{ steps.build_executable.outputs.exe_path }}"
124-
$commits = "${{ steps.collect_commits.outputs.commits }}"
125-
$notes = @"
126-
## Changes in v$version
125+
# Retrieve commits - EOF delimiter preserves newlines
126+
$commitsRaw = "${{ steps.collect_commits.outputs.commits }}"
127127
128-
$commits
128+
# Build release notes - newlines are preserved by EOF delimiter
129+
$notes = "## Changes in v$version`n`n"
130+
$notes += $commitsRaw
131+
$notes += "`n`n### Download`n"
132+
$notes += "Download the ``$exeName`` file below and run it to use the latest version.`n`n"
133+
$notes += "### Installation`n"
134+
$notes += "1. Download ``$exeName```n"
135+
$notes += "2. Run the executable`n"
136+
$notes += "3. Follow the setup wizard"
129137
130-
### Download
131-
Download the ``$exeName`` file below and run it to use the latest version.
132-
133-
### Installation
134-
1. Download ``$exeName``
135-
2. Run the executable
136-
3. Follow the setup wizard
137-
"@
138138
gh release create "v$version" --title "Release v$version" --notes $notes $exePath
139139
env:
140140
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }}

0 commit comments

Comments
 (0)