Skip to content

Commit 64f72c3

Browse files
committed
chore: improve version handling
1 parent ad0d107 commit 64f72c3

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

src/buddy.ts

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -555,19 +555,39 @@ export class Buddy {
555555
private getUpdateType(current: string, latest: string): 'major' | 'minor' | 'patch' {
556556
try {
557557
// Clean version strings, including v, @ prefix for version ranges
558-
const cleanCurrent = current.replace(/^[v^~>=<@]+/, '')
559-
const cleanLatest = latest.replace(/^[v^~>=<@]+/, '')
558+
let cleanCurrent = current.replace(/^[v^~>=<@]+/, '')
559+
let cleanLatest = latest.replace(/^[v^~>=<@]+/, '')
560+
561+
// For GitHub Actions, normalize incomplete versions like "4" to "4.0.0"
562+
// This is important for proper semver comparison
563+
const normalizeVersion = (version: string): string => {
564+
const parts = version.split('.')
565+
while (parts.length < 3) {
566+
parts.push('0')
567+
}
568+
return parts.join('.')
569+
}
570+
571+
cleanCurrent = normalizeVersion(cleanCurrent)
572+
cleanLatest = normalizeVersion(cleanLatest)
560573

561574
if (Bun.semver.order(cleanLatest, cleanCurrent) <= 0)
562575
return 'patch'
563576

564-
if (Bun.semver.satisfies(cleanLatest, `~${cleanCurrent}`))
565-
return 'patch'
577+
// Use manual comparison for more accurate update type determination
578+
const currentParts = cleanCurrent.split('.').map(Number)
579+
const latestParts = cleanLatest.split('.').map(Number)
566580

567-
if (Bun.semver.satisfies(cleanLatest, `^${cleanCurrent}`))
581+
// Major version change
582+
if (latestParts[0] > currentParts[0])
583+
return 'major'
584+
585+
// Minor version change
586+
if (latestParts[0] === currentParts[0] && latestParts[1] > currentParts[1])
568587
return 'minor'
569588

570-
return 'major'
589+
// Patch version change
590+
return 'patch'
571591
}
572592
catch {
573593
return 'patch'

0 commit comments

Comments
 (0)