Skip to content

Commit a21ed78

Browse files
authored
Fix version detection and enhance changelog generation
Fixed version detection logic and improved changelog generation.
1 parent 9a731f8 commit a21ed78

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

.github/workflows/dotnet-desktop.yml

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ jobs:
2828
restore-keys: |
2929
${{ runner.os }}-nuget-
3030
31-
# 3. SMART VERSION DETECTION (Fixes your Release vs Pre-Release logic)
31+
32+
# 3. SMART VERSION DETECTION (FIXED)
3233
- name: Detect Version & Release Type
3334
id: version_logic
3435
shell: pwsh
@@ -38,7 +39,7 @@ jobs:
3839
if (-not $projectFile) { Write-Error "❌ Dimmer.csproj not found"; exit 1 }
3940
4041
[xml]$xml = Get-Content $projectFile.FullName
41-
$currentVersionStr = $xml.Project.PropertyGroup.Version
42+
$currentVersionStr = $xml.Project.PropertyGroup.Version.Trim()
4243
4344
if ([string]::IsNullOrWhiteSpace($currentVersionStr)) {
4445
Write-Error "❌ No <Version> tag found in Dimmer.csproj."
@@ -47,17 +48,20 @@ jobs:
4748
4849
$newTag = "v$currentVersionStr"
4950
Write-Host "🔹 Current File Version: $currentVersionStr"
51+
Write-Host "🔹 New Tag target: $newTag"
5052
echo "NEW_TAG=$newTag" >> $env:GITHUB_ENV
5153
5254
# --- B. FIND PREVIOUS TAG ---
5355
git fetch --tags --force
54-
# Find latest tag that isn't the current one
55-
$prevTag = git tag --sort=-version:refname | Where-Object { $_ -ne $newTag } | Select-Object -First 1
56+
57+
# Get all tags sorted by version, exclude the NEW tag explicitly
58+
$allTags = git tag --sort=-version:refname
59+
$prevTag = $allTags | Where-Object { $_.Trim() -ne $newTag } | Select-Object -First 1
5660
57-
if (-not $prevTag) {
58-
Write-Host "⚠️ No previous tag found. Defaulting to Release."
59-
echo "IS_PRE=false" >> $env:GITHUB_ENV
61+
if ([string]::IsNullOrWhiteSpace($prevTag)) {
62+
Write-Host "⚠️ No previous tag found. Will log all history."
6063
echo "LATEST_TAG=" >> $env:GITHUB_ENV
64+
echo "IS_PRE=false" >> $env:GITHUB_ENV # Default to release if first tag
6165
exit 0
6266
}
6367
@@ -85,7 +89,7 @@ jobs:
8589
echo "IS_PRE=true" >> $env:GITHUB_ENV
8690
}
8791
88-
# 3.5 GENERATE CHANGELOG
92+
# 3.5 GENERATE CHANGELOG (FIXED with Fallback)
8993
- name: Generate Changelog
9094
shell: pwsh
9195
run: |
@@ -94,18 +98,34 @@ jobs:
9498
9599
Write-Host "Generating log from '$prevTag' to 'HEAD'"
96100
101+
# 1. Try Standard Range Log
97102
if ([string]::IsNullOrEmpty($prevTag)) {
98103
$log = git log --pretty=format:"- %s (%h)" --no-merges
99104
} else {
100105
$log = git log $prevTag..HEAD --pretty=format:"- %s (%h)" --no-merges
101106
}
102107
108+
# Convert array to string if necessary
103109
if ($log -is [Array]) { $logString = $log -join "`n" } else { $logString = $log }
104-
if ([string]::IsNullOrWhiteSpace($logString)) { $logString = "- No commit messages found since last tag." }
110+
111+
# 2. Fallback: If empty, grab last 15 commits (Ensures no empty release notes)
112+
if ([string]::IsNullOrWhiteSpace($logString)) {
113+
Write-Warning "Standard log range was empty. Falling back to last 15 commits."
114+
$log = git log -n 15 --pretty=format:"- %s (%h)" --no-merges
115+
if ($log -is [Array]) { $logString = $log -join "`n" } else { $logString = $log }
116+
}
117+
118+
# 3. Final Check
119+
if ([string]::IsNullOrWhiteSpace($logString)) {
120+
$logString = "- No commit messages found (Manual Check Recommended)."
121+
}
105122
106123
$content = "## Changes in $newTag`n`n$logString"
107124
Set-Content -Path "release_notes.md" -Value $content -Encoding UTF8
125+
126+
Write-Host "--- RELEASE NOTES PREVIEW ---"
108127
Write-Host $content
128+
Write-Host "-----------------------------"
109129
110130
# 4. CHECKOUT DEPENDENCIES
111131
- name: Checkout Last.fm

0 commit comments

Comments
 (0)