mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-19 07:56:02 +01:00
fix(version): properly compare minor/patch semver
Comparing "2.7.4" to "2.10.1" would compare each number, i.e. 2 = 2, 7 < 10, 4 > 1 Instead compare the major (2 v 2), then minor.patch (7.4 v 10.1). where doka to do my math
This commit is contained in:
@@ -19,13 +19,11 @@ function lib.versionCheck(repository)
|
|||||||
local latestVersion = response.tag_name:match('%d%.%d+%.%d+')
|
local latestVersion = response.tag_name:match('%d%.%d+%.%d+')
|
||||||
if not latestVersion or latestVersion == currentVersion then return end
|
if not latestVersion or latestVersion == currentVersion then return end
|
||||||
|
|
||||||
local cv = { string.strsplit('.', currentVersion) }
|
local cMajor, cMinor = string.strsplit('.', currentVersion, 2)
|
||||||
local lv = { string.strsplit('.', latestVersion) }
|
local lMajor, lMinor = string.strsplit('.', latestVersion, 2)
|
||||||
|
|
||||||
for i = 1, #cv do
|
if tonumber(cMajor) < tonumber(lMajor) or tonumber(cMinor) < tonumber(lMinor) then
|
||||||
if tonumber(cv[i]) < tonumber(lv[i]) then
|
return print(('^3An update is available for %s (current version: %s)\r\n%s^0'):format(resource, currentVersion, response.html_url))
|
||||||
return print(('^3An update is available for %s (current version: %s)\r\n%s^0'):format(resource, currentVersion, response.html_url))
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end, 'GET')
|
end, 'GET')
|
||||||
end)
|
end)
|
||||||
|
|||||||
@@ -2,18 +2,16 @@ function lib.checkDependency(resource, minimumVersion, printMessage)
|
|||||||
local currentVersion = GetResourceMetadata(resource, 'version', 0):match('%d%.%d+%.%d+')
|
local currentVersion = GetResourceMetadata(resource, 'version', 0):match('%d%.%d+%.%d+')
|
||||||
|
|
||||||
if currentVersion ~= minimumVersion then
|
if currentVersion ~= minimumVersion then
|
||||||
local cv = { string.strsplit('.', currentVersion) }
|
local cMajor, cMinor = string.strsplit('.', currentVersion, 2)
|
||||||
local mv = { string.strsplit('.', minimumVersion) }
|
local mMajor, mMinor = string.strsplit('.', minimumVersion, 2)
|
||||||
|
|
||||||
local msg = ("^1%s requires version '%s' of '%s' (current version: %s)^0"):format(GetInvokingResource() or GetCurrentResourceName(), minimumVersion, resource, currentVersion)
|
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
|
||||||
for i = 1, #cv do
|
if printMessage then
|
||||||
if tonumber(cv[i]) < tonumber(mv[i]) then
|
return print(msg)
|
||||||
if printMessage then
|
|
||||||
return print(msg)
|
|
||||||
end
|
|
||||||
|
|
||||||
return false, msg
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return false, msg
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user