-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautoversion.lua
More file actions
executable file
·65 lines (59 loc) · 1.69 KB
/
autoversion.lua
File metadata and controls
executable file
·65 lines (59 loc) · 1.69 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env luajit
-- Autoversion
-- https://github.com/fuxoft/autoversion
local VERSION = ([[*<= Version '2.1.2+D20241210T123623' =>*]]):match("'(.+)'")
local function main()
local fname = arg[1]
local optstr = "-v3"
if fname == "-v" then
print(VERSION)
os.exit()
end
if arg[2] then
fname = arg[2]
optstr = arg[1]
end
assert(fname, "No file name supplied.")
local fd = io.open(fname)
assert (fd, "Cannot open file: "..fname)
local txt = assert(fd:read("*a"))
assert(fd:close())
local found = false
local newversion, oldversion
txt = txt:gsub("%[%[%*<= Version '(.-)' =>%*%]%]", function(str)
found = true
oldversion = str
if optstr == "--show-only" then
print(oldversion)
os.exit()
end
local x,y,z,build = str:match '(%d+)%.(%d+)%.(%d+)%+(.+)'
x,y,z = tonumber(x), tonumber(y), tonumber(z)
if not (x and y and z and build) then
found = false
return
end
local newbuild = os.date("D%Y%m%dT%H%M%S")
assert(x >= 0 and y >=0 and z >= 0, "Patch # is negative")
if optstr == "-v1" then
x = x + 1
y = 0
z = 0
elseif optstr == "-v2" then
y = y + 1
z = 0
else
z = z + 1
end
newversion = x.."."..y.."."..z.."+"..newbuild
return "[[*<= Version '"..newversion.."' =>*]]"
end, 1)
if not found then
error("Didn't find the magic version string in the file. The magic string example is: [[*<= Version '1.2.345+D20201231T235959' =>*]]")
end
local fd = assert(io.open(fname, "w"))
assert(fd:write(txt))
assert(fd:close())
print("Succesfully updated file ".. fname .. " from version " .. oldversion .. " to "..newversion)
end
main()