Skip to content

Commit f2e8ae5

Browse files
CopilotDRSDavidSoft
andcommitted
Improve version parsing to handle complex version strings
Co-authored-by: DRSDavidSoft <[email protected]>
1 parent 4d21982 commit f2e8ae5

File tree

2 files changed

+54
-23
lines changed

2 files changed

+54
-23
lines changed

.github/workflows/vendor.yml

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,32 @@ jobs:
5656
$changeType = "unknown"
5757
$emoji = "🔄"
5858
try {
59-
$oldVer = [System.Version]::Parse($oldVersion.Split('-')[0])
60-
$newVer = [System.Version]::Parse($s.version.Split('-')[0])
61-
62-
if ($newVer.Major -gt $oldVer.Major) {
63-
$changeType = "major"
64-
$emoji = "⚠️"
65-
} elseif ($newVer.Minor -gt $oldVer.Minor) {
66-
$changeType = "minor"
67-
$emoji = "✨"
68-
} else {
69-
$changeType = "patch"
70-
$emoji = "🐛"
59+
# Handle versions with more than 4 parts
60+
$oldVerStr = $oldVersion.Split('-')[0]
61+
$newVerStr = $s.version.Split('-')[0]
62+
63+
# Split by dots and take only numeric parts, first 4 max
64+
$oldParts = $oldVerStr.Split('.') | Where-Object { $_ -match '^\d+$' } | Select-Object -First 4
65+
$newParts = $newVerStr.Split('.') | Where-Object { $_ -match '^\d+$' } | Select-Object -First 4
66+
67+
# Ensure we have at least 2 parts (major.minor)
68+
if ($oldParts.Count -ge 2 -and $newParts.Count -ge 2) {
69+
$oldVerParseable = $oldParts -join '.'
70+
$newVerParseable = $newParts -join '.'
71+
72+
$oldVer = [System.Version]::Parse($oldVerParseable)
73+
$newVer = [System.Version]::Parse($newVerParseable)
74+
75+
if ($newVer.Major -gt $oldVer.Major) {
76+
$changeType = "major"
77+
$emoji = "⚠️"
78+
} elseif ($newVer.Minor -gt $oldVer.Minor) {
79+
$changeType = "minor"
80+
$emoji = "✨"
81+
} else {
82+
$changeType = "patch"
83+
$emoji = "🐛"
84+
}
7185
}
7286
} catch {
7387
$changeType = "unknown"

scripts/update.ps1

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -303,29 +303,46 @@ foreach ($s in $sources) {
303303
# }
304304

305305
$count++
306-
306+
307307
# Analyze version change type
308308
$changeType = "unknown"
309309
try {
310310
# Try parsing as semantic version
311-
$oldVer = [System.Version]::Parse($s.version.Split('-')[0])
312-
$newVer = [System.Version]::Parse($version.Split('-')[0])
313-
314-
if ($newVer.Major -gt $oldVer.Major) {
315-
$changeType = "major"
316-
$hasBreakingChanges = $true
317-
} elseif ($newVer.Minor -gt $oldVer.Minor) {
318-
$changeType = "minor"
311+
# Handle versions with more than 4 parts by taking only the first 3-4 parts
312+
$oldVerStr = $s.version.Split('-')[0]
313+
$newVerStr = $version.Split('-')[0]
314+
315+
# Split by dots and take only numeric parts, first 4 max
316+
$oldParts = $oldVerStr.Split('.') | Where-Object { $_ -match '^\d+$' } | Select-Object -First 4
317+
$newParts = $newVerStr.Split('.') | Where-Object { $_ -match '^\d+$' } | Select-Object -First 4
318+
319+
# Ensure we have at least 2 parts (major.minor)
320+
if ($oldParts.Count -ge 2 -and $newParts.Count -ge 2) {
321+
$oldVerParseable = $oldParts -join '.'
322+
$newVerParseable = $newParts -join '.'
323+
324+
$oldVer = [System.Version]::Parse($oldVerParseable)
325+
$newVer = [System.Version]::Parse($newVerParseable)
326+
327+
if ($newVer.Major -gt $oldVer.Major) {
328+
$changeType = "major"
329+
$hasBreakingChanges = $true
330+
} elseif ($newVer.Minor -gt $oldVer.Minor) {
331+
$changeType = "minor"
332+
} else {
333+
$changeType = "patch"
334+
}
319335
} else {
320-
$changeType = "patch"
336+
# Not enough numeric parts for semantic versioning
337+
throw "Not enough numeric version parts"
321338
}
322339
} catch {
323340
# If semantic versioning fails, treat as unknown (potentially breaking)
324341
$changeType = "unknown"
325342
$hasBreakingChanges = $true
326343
Write-Verbose "Could not parse version as semantic version, treating as potentially breaking"
327344
}
328-
345+
329346
$updateDetails += @{
330347
name = $s.name
331348
oldVersion = $s.version

0 commit comments

Comments
 (0)