Skip to content

Commit 2a564d3

Browse files
authored
Enhance version comparison logic in workflow
1 parent fee1abd commit 2a564d3

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

.github/workflows/dotnet-desktop.yml

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,45 +37,50 @@ jobs:
3737
# --- A. READ CURRENT VERSION FROM FILE ---
3838
$projectFile = Get-ChildItem -Recurse -Filter "Dimmer.csproj" | Select-Object -First 1
3939
if (-not $projectFile) { Write-Error "❌ Dimmer.csproj not found"; exit 1 }
40-
40+
4141
[xml]$xml = Get-Content $projectFile.FullName
4242
$currentVersionStr = $xml.Project.PropertyGroup.Version.Trim()
4343
4444
if ([string]::IsNullOrWhiteSpace($currentVersionStr)) {
4545
Write-Error "❌ No <Version> tag found in Dimmer.csproj."
4646
exit 1
4747
}
48-
48+
4949
$newTag = "v$currentVersionStr"
5050
Write-Host "🔹 Current File Version: $currentVersionStr"
5151
echo "NEW_TAG=$newTag" >> $env:GITHUB_ENV
52-
52+
5353
# --- B. FIND PREVIOUS TAG ---
5454
git fetch --tags --force
5555
56-
# Get all tags, exclude the NEW tag explicitly (Trim ensures exact match)
56+
# Get all tags
5757
$allTags = git tag --sort=-version:refname
58-
$prevTag = $allTags | Where-Object { $_.Trim() -ne $newTag } | Select-Object -First 1
59-
58+
59+
# Filter: Exclude current tag AND ensure tag looks like a standard version (e.g. v1.0, 1.0.5)
60+
# This ignores tags like "v1.92a" which cause the crash
61+
$validPattern = "^v?\d+(\.\d+)+$"
62+
$prevTag = $allTags | Where-Object { $_.Trim() -ne $newTag -and $_.Trim() -match $validPattern } | Select-Object -First 1
63+
6064
if ([string]::IsNullOrWhiteSpace($prevTag)) {
61-
Write-Host "⚠️ No previous tag found. Defaulting to Release."
65+
Write-Host "⚠️ No previous standard tag found. Treating as first STABLE release."
6266
echo "IS_PRE=false" >> $env:GITHUB_ENV
6367
echo "LATEST_TAG=" >> $env:GITHUB_ENV
64-
# Don't exit here, let it continue to set IS_PRE
6568
} else {
66-
Write-Host "🔹 Previous Tag found: $prevTag"
69+
Write-Host "🔹 Previous Valid Tag found: $prevTag"
6770
echo "LATEST_TAG=$prevTag" >> $env:GITHUB_ENV
6871
}
69-
72+
7073
# --- C. COMPARE VERSIONS ---
7174
if ($prevTag) {
72-
$prevVersionStr = $prevTag -replace "^v", ""
75+
# Sanitize: Remove 'v' and anything that isn't a number or dot
76+
$prevVersionStr = $prevTag -replace "[^0-9\.]", ""
77+
7378
try {
7479
$curV = [System.Version]$currentVersionStr
7580
$prevV = [System.Version]$prevVersionStr
76-
81+
7782
Write-Host "Comparing $curV vs $prevV"
78-
83+
7984
if ($curV.Major -gt $prevV.Major -or $curV.Minor -gt $prevV.Minor) {
8085
Write-Host "🚀 Major/Minor change. Marking as STABLE RELEASE."
8186
echo "IS_PRE=false" >> $env:GITHUB_ENV
@@ -84,12 +89,9 @@ jobs:
8489
echo "IS_PRE=true" >> $env:GITHUB_ENV
8590
}
8691
} catch {
87-
Write-Warning "Could not parse versions. Defaulting to Pre-Release."
92+
Write-Warning "Could not parse versions despite sanitization. Defaulting to Pre-Release."
8893
echo "IS_PRE=true" >> $env:GITHUB_ENV
8994
}
90-
} else {
91-
# If no previous tag, assume it's a first release (Stable)
92-
echo "IS_PRE=false" >> $env:GITHUB_ENV
9395
}
9496
9597
# 3.5 GENERATE CHANGELOG (FIXED with Fallback)

0 commit comments

Comments
 (0)