Update WireLib.GetVersion (#3032)

Add WIREVERSION and WIREVESRION_STR E2 constants
This commit is contained in:
Denneisk 2024-04-10 16:22:22 -04:00 committed by GitHub
parent 4178d2ee37
commit bc746679a6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 53 additions and 25 deletions

View File

@ -14,7 +14,7 @@ jobs:
- name: Embed version
run: |
echo -e "\ncachedversion = \"Canary ${GITHUB_SHA:0:7}\"" >> lua/wire/server/wirelib.lua
echo -e "\nversion = $(date +%y%m%d)\nversion_string = \"Canary $(date +%Y.%m.%d) (${GITHUB_SHA:0:7})\"" >> lua/wire/server/wirelib.lua
- uses: wiremod/gmod-upload@master
with:

View File

@ -12,7 +12,7 @@ jobs:
- name: Embed version
run: |
echo -e "\ncachedversion = \"Workshop ${GITHUB_SHA:0:7}\"" >> lua/wire/server/wirelib.lua
echo -e "\nversion = $(date +%y%m%d)\nversion_string = \"Workshop $(date +%Y.%m.%d) (${GITHUB_SHA:0:7})\"" >> lua/wire/server/wirelib.lua
- uses: wiremod/gmod-upload@master
with:

View File

@ -4,6 +4,12 @@
local isOwner = E2Lib.isOwner
do
local v1, v2 = WireLib.GetVersion()
E2Lib.registerConstant("WIREVERSION", v1)
E2Lib.registerConstant("WIREVERSION_STR", v2)
end
__e2setcost(1) -- temporary
[nodiscard]
@ -244,7 +250,6 @@ e2function number getExtensionStatus(string extension)
return getExtensionStatus(extension) and 1 or 0
end
--[[******************************************************************************]]--
registerCallback("construct", function(self)

View File

@ -1202,17 +1202,19 @@ function WireLib.CalcElasticConsts(Ent1, Ent2)
end
-- Returns a string like "Git f3a4ac3" or "SVN 2703" or "Workshop" or "Extracted"
-- The partial git hash can be plugged into https://github.com/wiremod/wire/commit/f3a4ac3 to show the actual commit
local cachedversion
local version
local version_string
--- Returns the current Wiremod version
---@return number version The version as a number formatted YYMMDD
---@return string version_string A verbose version for printing
function WireLib.GetVersion()
-- If we've already found our version just return that again
if cachedversion then return cachedversion end
if version then return version, version_string end
-- Find what our legacy folder is called
local wirefolder = "addons/wire"
-- Brute force find the wire folder if it's not named wire
if not file.Exists(wirefolder, "GAME") then
for k, folder in pairs(({file.Find("addons/*", "GAME")})[2]) do
for _, folder in pairs(({file.Find("addons/*", "GAME")})[2]) do
if folder:find("wire") and not folder:find("extra") then
wirefolder = "addons/"..folder
break
@ -1221,28 +1223,49 @@ function WireLib.GetVersion()
end
if file.Exists(wirefolder, "GAME") then
if file.Exists(wirefolder.."/.git", "GAME") then
cachedversion = "Git "..(file.Read(wirefolder.."/.git/refs/heads/master", "GAME") or "Unknown"):sub(1,7)
elseif file.Exists(wirefolder.."/.svn", "GAME") then
-- Note: This method will likely only detect TortoiseSVN installs
local wcdb = file.Read(wirefolder.."/.svn/wc.db", "GAME") or ""
local start = wcdb:find("/wiremod/wire/!svn/ver/%d+/branches%)")
if start then
cachedversion = "SVN "..wcdb:sub(start+23, start+26)
else
cachedversion = "SVN Unknown"
wirefolder = wirefolder .. "/.git"
if file.Exists(wirefolder, "GAME") then
-- Find where git HEAD is
local head = file.Open(wirefolder .. "/HEAD", "r", "GAME")
if head then
local ref
while not head:EndOfFile() do
local line = head:ReadLine()
if line:StartsWith("ref: ") then
ref = line:sub(6, -2)
end
end
head:Close()
if ref then
-- Generate version string
local path = wirefolder .. "/" .. ref
local name = ref:StartsWith("refs/heads/") and ref:sub(12) or ref
local time = -1
local time_str = "Unknown"
local hash = ""
if file.Exists(path, "GAME") then
local t = file.Time(path, "GAME")
time = tonumber(os.date("%y%m%d", t))
time_str = os.date("%Y.%m.%d", t)
hash = file.Read(path, "GAME"):sub(1, 7)
end
version_string = string.format("Local %s (%s:%s)", time_str, name, hash)
version = time
end
end
else
cachedversion = "Extracted"
end
end
if not cachedversion then cachedversion = "Unknown" end
if not version then
version = -1
version_string = "Unknown"
end
return cachedversion
return version, version_string
end
concommand.Add("wireversion", function(ply,cmd,args)
local text = "Wiremod's version: '"..WireLib.GetVersion().."'"
concommand.Add("wireversion", function(ply)
local text = "Wiremod version: " .. select(2, WireLib.GetVersion())
if IsValid(ply) then
ply:ChatPrint(text)
else