-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew_version.lua
executable file
·64 lines (50 loc) · 1.27 KB
/
new_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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env nxlua
local t = sys.argv[2]
local upgrade_types = {
'major',
'minor',
'patch',
}
local function usage( ... )
print(string.format("Usage: %s major/minor/patch", sys.argv[1]))
os.exit(1)
end
if not table.exist(upgrade_types, t) then
print(sys.argv[1], "invalid arguments")
usage()
end
local function readfile( pathname )
local f = io.open(pathname)
local v = f:read('*all')
f:close()
return v
end
local function writefile( pathname, content )
local f = io.open(pathname, 'wb')
f:write(content)
f:close()
end
local mydir = path_utils:dirname(sys.launcher)
local version_file = path_utils:join(mydir, 'VERSION')
local current_version = readfile(version_file):trim()
local fields = current_version:split('.')
assert(#fields == 3, "version format invalid")
local major = tonumber(fields[1])
local minor = tonumber(fields[2])
local patch = tonumber(fields[3])
if t == 'major' then
major = major + 1
minor = 0
patch = 0
end
if t == 'minor' then
minor = minor + 1
patch = 0
end
if t == 'patch' then
patch = patch + 1
end
local version = string.format('%d.%d.%d', major, minor, patch)
writefile(version_file, version .. '\n')
os.execute(F[[git commit VERSION -m "update version to {version}"]])
os.execute(F[[git tag -a "v{version}" -m "create tag v{version}" -s]])