Skip to content

Commit

Permalink
tests(rockspec) add a script to validate rockspec file
Browse files Browse the repository at this point in the history
  • Loading branch information
flrgh authored and dndx committed May 11, 2022
1 parent d569af6 commit 78fa687
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 1 deletion.
7 changes: 6 additions & 1 deletion .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ jobs:
eval `luarocks path`
luacheck -q .
- name: Validate rockspec file
run: |
eval `luarocks path`
scripts/validate-rockspec
- name: Unit tests
run: |
eval `luarocks path`
Expand Down Expand Up @@ -318,7 +323,7 @@ jobs:
run: |
echo "127.0.0.1 grpcs_1.test" | sudo tee -a /etc/hosts
echo "127.0.0.1 grpcs_2.test" | sudo tee -a /etc/hosts
- name: Enable SSL for Redis
run: |
docker cp ${{ github.workspace }} kong_redis:/workspace
Expand Down
82 changes: 82 additions & 0 deletions scripts/validate-rockspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/usr/bin/env bash

set -euo pipefail

shopt -s nullglob

fail() {
echo "Failure: $@"
exit 1
}

lint() {
echo "Linting..."

luarocks lint "$1"
}

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..."

for line in $(read_modules "$spec"); do
fname=${line%|*}
module=${line#*|}
files[$fname]="$module"

if [[ ! -f $fname ]]; then
fail "module ($module) file ($fname) is missing"
fi
done

for fname in $(git ls-files 'kong/*.lua'); do
mod="${files[$fname]:-}"

if [[ -z ${mod:-} ]]; then
fail "file ($fname) not found in rockspec ($spec)"
fi
done
}


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 "$@"

0 comments on commit 78fa687

Please sign in to comment.