-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathcheck_mirror_urls.lua
More file actions
63 lines (56 loc) · 2.14 KB
/
Copy pathcheck_mirror_urls.lua
File metadata and controls
63 lines (56 loc) · 2.14 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
-- Lint the GLOBAL/CN mirror tables in a package descriptor.
--
-- Rules (only applied to `url` fields written in table form — plain-string
-- urls remain valid and are left to the author):
-- * a url table must define BOTH `GLOBAL` and `CN`
-- * both values must be non-empty strings
-- * `CN` must be a gitcode.com/mcpp-res/<repo>/releases/download/... URL
-- * `GLOBAL` must not itself point at the mcpp-res CN mirror
--
-- Usage: lua5.4 tests/check_mirror_urls.lua <file.lua>
-- Exit non-zero (and print ::error lines) on the first violation in the file.
function import(...)
return setmetatable({}, {__index = function() return function() end end})
end
local path = assert(arg[1], "usage: check_mirror_urls.lua <file>")
package = nil
local chunk = assert(loadfile(path, "t"))
chunk()
local p = package
if type(p) ~= "table" then os.exit(0) end
local fail = 0
local function err(msg)
io.stderr:write(string.format("::error file=%s::%s\n", path, msg))
fail = 1
end
local function check_url(ctx, u)
if type(u) == "string" then return end -- plain url: fine
if type(u) ~= "table" then
err(ctx .. ": url must be a string or { GLOBAL=..., CN=... } table")
return
end
local g, c = u.GLOBAL, u.CN
if type(g) ~= "string" or g == "" then
err(ctx .. ": url table missing non-empty GLOBAL")
end
if type(c) ~= "string" or c == "" then
err(ctx .. ": url table missing non-empty CN")
end
if type(c) == "string" and not c:match("^https://gitcode%.com/mcpp%-res/") then
err(ctx .. ": CN url must be under https://gitcode.com/mcpp-res/ (got " .. tostring(c) .. ")")
end
if type(g) == "string" and g:match("^https://gitcode%.com/mcpp%-res/") then
err(ctx .. ": GLOBAL url must not point at the CN mirror")
end
end
local xpm = p.xpm or {}
for plat, vt in pairs(xpm) do
if type(vt) == "table" then
for ver, entry in pairs(vt) do
if type(entry) == "table" and entry.url ~= nil then
check_url(string.format("%s/%s/%s", p.name or "?", tostring(plat), tostring(ver)), entry.url)
end
end
end
end
os.exit(fail)