Last active
April 30, 2023 14:13
-
-
Save Local9/207d04a03364c8b2fe529d59b2c5c43b to your computer and use it in GitHub Desktop.
A Lua script to check resource version against GitHub releases
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- add the following metadata to your fxmanifest.lua | |
version 'v1.0.0' | |
repository 'https://github.com/<USER or ORGANISATION>/<REPOSITORY NAME>' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- https://stackoverflow.com/a/19263313 | |
function string:split( inSplitPattern, outResults ) | |
if not outResults then | |
outResults = { } | |
end | |
local theStart = 1 | |
local theSplitStart, theSplitEnd = string.find( self, inSplitPattern, theStart ) | |
while theSplitStart do | |
table.insert( outResults, string.sub( self, theStart, theSplitStart-1 ) ) | |
theStart = theSplitEnd + 1 | |
theSplitStart, theSplitEnd = string.find( self, inSplitPattern, theStart ) | |
end | |
table.insert( outResults, string.sub( self, theStart ) ) | |
return outResults | |
end | |
Citizen.CreateThread(function() | |
local currentResourceName = GetCurrentResourceName(); | |
local gitRepository = GetResourceMetadata(currentResourceName, "repository", 0); | |
local stringArray = gitRepository:split("/") | |
local gitName = stringArray[#(stringArray) - 1] | |
local repoName = stringArray[#(stringArray)] | |
local resourceName = "Resource '" .. currentResourceName .. "'" | |
function checkVersion(err, responseText, headers) | |
local fxVersion = GetResourceMetadata(currentResourceName, "version", 0); | |
local gitLatest = json.decode(responseText); | |
if fxVersion ~= gitLatest.tag_name then | |
print("\n###############################") | |
print("\n" .. resourceName .. " is outdated;\nLatest Version: " .. gitLatest.tag_name .. "\nCurrent Resource: " .. fxVersion .. "\nPlease update it from " .. gitRepository .. "") | |
print("\n###############################") | |
else | |
print(resourceName .. " is up to date, have fun!") | |
end | |
end | |
PerformHttpRequest("https://api.github.com/repos/" .. gitName .. "/" .. repoName .. "/releases/latest", checkVersion, "GET") | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment