diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d310cc6..20294e5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,6 +9,8 @@ jobs: test: name: Lua ${{ matrix.lua }} runs-on: ubuntu-latest + env: + LUAROCKS_TREE: ${{ github.workspace }}/.luarocks strategy: fail-fast: false matrix: @@ -19,26 +21,32 @@ jobs: uses: actions/checkout@v4 - name: Set up Lua - uses: leafo/gh-actions-lua@v11 + uses: leafo/gh-actions-lua@v13 with: luaVersion: ${{ matrix.lua }} - name: Set up LuaRocks - uses: leafo/gh-actions-luarocks@v5 + uses: leafo/gh-actions-luarocks@v6 + with: + withLuaPath: ${{ github.workspace }}/.lua - name: Install dependencies run: | - luarocks install luasocket - luarocks install lua-cjson - luarocks install dkjson - luarocks install luasec + luarocks --tree="$LUAROCKS_TREE" install luasocket + luarocks --tree="$LUAROCKS_TREE" install lua-cjson + luarocks --tree="$LUAROCKS_TREE" install dkjson + luarocks --tree="$LUAROCKS_TREE" install luasec - - name: Verify JSON dependencies + - name: Verify dependencies run: | + eval "$(luarocks --tree="$LUAROCKS_TREE" path)" + luarocks --tree="$LUAROCKS_TREE" show luasocket + lua -e "assert(require('socket.http'))" lua -e "assert(require('dkjson'))" lua -e "assert(require('cjson.safe'))" - name: Run tests run: | + eval "$(luarocks --tree="$LUAROCKS_TREE" path)" make test make integration diff --git a/Makefile b/Makefile index 864999b..406dbe1 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,10 @@ LUA ?= lua -LUA_PATH := ./lua/?.lua;./lua/?/init.lua;; +# Keep the project sources first, then expose pure-Lua dependencies from the +# active LuaRocks tree. This is evaluated by make because its exported +# LUA_PATH overrides any value set by a calling shell. +LUAROCKS_PATH_ARGS := $(if $(strip $(LUAROCKS_TREE)),--tree="$(LUAROCKS_TREE)") +LUAROCKS_LUA_PATH := $(shell luarocks $(LUAROCKS_PATH_ARGS) path --lr-path 2>/dev/null) +LUA_PATH := ./lua/?.lua;./lua/?/init.lua;$(LUAROCKS_LUA_PATH);; export LUA_PATH .PHONY: test examples examples-local integration check zip servers server-http server-sse server-streamable server-tcp server-udp server-graphql server-mcp \ diff --git a/lua/utcp/transports/http.lua b/lua/utcp/transports/http.lua index b4e8d48..fcc8871 100644 --- a/lua/utcp/transports/http.lua +++ b/lua/utcp/transports/http.lua @@ -8,7 +8,10 @@ local function socket_http() if cached_http then return cached_http, cached_ltn12 end if socket_error then return nil, socket_error end local ok, http = pcall(require, 'socket.http') - if not ok then socket_error = 'lua-socket is required'; return nil, socket_error end + if not ok then + socket_error = 'lua-socket is required: ' .. tostring(http) + return nil, socket_error + end local ok2, ltn12 = pcall(require, 'ltn12') if not ok2 then socket_error = 'ltn12 is required'; return nil, socket_error end cached_http, cached_ltn12 = http, ltn12