Skip to content

Commit

Permalink
fix(version): split and compare semver in 3 parts
Browse files Browse the repository at this point in the history
'11.10' is equal to '11.1' cause maths.
  • Loading branch information
thelindat committed Sep 29, 2022
1 parent 19a08f6 commit e624aa2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
18 changes: 12 additions & 6 deletions resource/version/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,18 @@ function lib.versionCheck(repository)
local latestVersion = response.tag_name:match('%d%.%d+%.%d+')
if not latestVersion or latestVersion == currentVersion then return end

local cMajor, cMinor = string.strsplit('.', currentVersion, 2)
local lMajor, lMinor = string.strsplit('.', latestVersion, 2)

if tonumber(cMajor) < tonumber(lMajor) or tonumber(cMinor) < tonumber(lMinor) then
return print(('^3An update is available for %s (current version: %s)\r\n%s^0'):format(resource, currentVersion, response.html_url))
end
local cv = { string.strsplit('.', currentVersion) }
local lv = { string.strsplit('.', latestVersion) }

for i = 1, #cv do
local current, minimum = tonumber(cv[i]), tonumber(lv[i])

if current ~= minimum then
if current < minimum then
return print(('^3An update is available for %s (current version: %s)\r\n%s^0'):format(resource, currentVersion, response.html_url))
else break end
end
end
end, 'GET')
end)
end
Expand Down
22 changes: 14 additions & 8 deletions resource/version/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,22 @@ function lib.checkDependency(resource, minimumVersion, printMessage)
local currentVersion = GetResourceMetadata(resource, 'version', 0):match('%d%.%d+%.%d+')

if currentVersion ~= minimumVersion then
local cMajor, cMinor = string.strsplit('.', currentVersion, 2)
local mMajor, mMinor = string.strsplit('.', minimumVersion, 2)

local cv = { string.strsplit('.', currentVersion) }
local mv = { string.strsplit('.', minimumVersion) }
local msg = ("^1%s requires version '%s' of '%s' (current version: %s)^0"):format(GetInvokingResource() or GetCurrentResourceName(), minimumVersion, resource, currentVersion)
if tonumber(cMajor) < tonumber(mMajor) or tonumber(cMinor) < tonumber(mMinor) then
if printMessage then
return print(msg)
end

return false, msg
for i = 1, #cv do
local current, minimum = tonumber(cv[i]), tonumber(mv[i])

if current ~= minimum then
if current < minimum then
if printMessage then
return print(msg)
end

return false, msg
else break end
end
end
end

Expand Down

0 comments on commit e624aa2

Please sign in to comment.