-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.lua
44 lines (35 loc) · 1.54 KB
/
version.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
local UPDATE_RESOURCE = '^3A new update is avaible for %s. %s';
local BASE_URL <const> = 'https://api.github.com/repos/monolith-vision/%s/releases/latest';
local RESOURCE_NAME <const> = GetCurrentResourceName();
local RELEASE_URL <const> = BASE_URL:format(RESOURCE_NAME);
local CURRENT_VERSION <const> = GetResourceMetadata(RESOURCE_NAME, 'version', 0);
if not CURRENT_VERSION then
return print('^1Could not find the version for ' .. RESOURCE_NAME .. '!^0');
end
---@param str string
---@return number[]
local function getVersionNumbers(str)
return { string.strsplit('.', str:match('%d+%.%d+%.%d+')) };
end
PerformHttpRequest(RELEASE_URL, function(status, body)
if status ~= 200 or not body then
return print('^1An error occured, while checking the version. You can ignore this error message.^0');
end
local release = json.decode(body);
if release.prelease then
return print('^3This is a prelease, expect errors to occur.^0');
end
local LATEST_VERSION <const> = release.tag_name;
local LATEST_VERSION_NUMBERS <const> = getVersionNumbers(LATEST_VERSION);
local CURRENT_VERSION_NUMBERS <const> = getVersionNumbers(CURRENT_VERSION);
for index, current in next, CURRENT_VERSION_NUMBERS do
local currentVersionNumber = tonumber(current);
local latestVersionNumber = tonumber(LATEST_VERSION_NUMBERS[index]);
if currentVersionNumber > latestVersionNumber then
return;
end
if currentVersionNumber < latestVersionNumber then
return print(UPDATE_RESOURCE:format(RESOURCE_NAME, release.html_url));
end
end
end);