Files
ox_lib/resource/version/server.lua
Linden bdb88e74c5 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
2022-08-23 19:29:45 +10:00

33 lines
1.2 KiB
Lua

function lib.versionCheck(repository)
local resource = GetInvokingResource() or GetCurrentResourceName()
local currentVersion = GetResourceMetadata(resource, 'version', 0)
if currentVersion then
currentVersion = currentVersion:match('%d%.%d+%.%d+')
end
if not currentVersion then return print(("^1Unable to determine current resource version for '%s' ^0"):format(resource)) end
SetTimeout(1000, function()
PerformHttpRequest(('https://api.github.com/repos/%s/releases/latest'):format(repository), function(status, response)
if status ~= 200 then return end
response = json.decode(response)
if response.prerelease then return end
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
end, 'GET')
end)
end
lib.versionCheck('overextended/ox_lib')