-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidate-rockspec
executable file
·106 lines (77 loc) · 1.86 KB
/
validate-rockspec
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env bash
set -euo pipefail
shopt -s nullglob
fail() {
echo "Failure: $@"
exit 1
}
lint() {
local spec=$1
echo "Linting (luarocks)..."
if ! luarocks lint "$spec"; then
fail "luarocks lint returned error"
fi
echo "Linting (luacheck)..."
# luacheck helps to point out some semantic issues (like duplicate
# table keys)
if ! luacheck \
--quiet \
--no-global \
-- - \
< "$spec";
then
fail "luacheck returned error"
fi
}
read_modules() {
local spec="$1"
resty -e '
local fn = loadstring(io.stdin:read("*a"))
local rock = {}
setfenv(fn, rock)
fn()
for mod, fname in pairs(rock.build.modules) do
print(fname .. "|" .. mod)
end
' < "$spec"
}
check_modules() {
local spec=$1
local -A files=()
echo "Checking modules..."
local failed=0
for line in $(read_modules "$spec"); do
fname=${line%|*}
module=${line#*|}
files[$fname]="$module"
if [[ ! -f $fname ]]; then
: $(( failed++ ))
echo "Module ($module) file ($fname) is missing"
fi
done
for fname in $(git ls-files 'kong/*.lua'); do
if [[ -z ${files[$fname]:-} ]]; then
: $(( failed++ ))
echo "File ($fname) not found in rockspec ($spec)"
fi
done
if (( failed > 0 )); then
fail "rockspec build.modules is invalid"
fi
}
main() {
local files=(kong-*.rockspec)
local spec
if (( ${#files[@]} == 0 )); then
fail "no rockspec file found"
elif (( ${#files[@]} > 1 )); then
fail "multiple rockspec files found: ${files[*]}"
else
spec=${files[0]}
fi
echo "Found rockspec file to validate: $spec"
lint "$spec"
check_modules "$spec"
echo "OK!"
}
main "$@"