diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4e69163..b56db48 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,8 +28,13 @@ jobs: ca-certificates \ cpanminus \ git \ + lua5.1 \ + luarocks \ wget + - name: Validate rockspec + run: luarocks make rockspec/api7-lua-resty-websocket-local-0.rockspec --local --tree /tmp/rockspec-check + - name: Build and test env: CC: gcc diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..9386b2e --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,69 @@ +name: Release + +on: + push: + branches: + - master + paths: + - 'rockspec/**' + +permissions: + contents: write + +jobs: + release: + name: Release + runs-on: ubuntu-latest + # only run for a commit whose message starts with "feat: release vX.Y.Z"; + # anything else touching rockspec/** (typo fixes, this workflow itself, + # etc.) should not show up as a failed run + if: "startsWith(github.event.head_commit.message, 'feat: release v')" + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install Lua + uses: leafo/gh-actions-lua@v8 + + - name: Install Luarocks + uses: leafo/gh-actions-luarocks@v4 + + - name: Extract release version + id: release_env + shell: bash + env: + # route the commit message through the environment instead of + # interpolating it into the script source: it's attacker-controlled + # (anyone who can push a commit controls its message) and directly + # templating it into `run:` would let shell metacharacters in the + # message execute arbitrary commands in this job, which also holds + # GITHUB_TOKEN and LUAROCKS_TOKEN + TITLE: ${{ github.event.head_commit.message }} + run: | + # keep the captured version to a safe character set (this is still + # attacker-controlled input up to this point) before it's used in + # later steps' `run:` blocks + re="^feat: release v?([0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.]+)?)" + if [[ "$TITLE" =~ $re ]]; then + echo "version=v${BASH_REMATCH[1]}" >> "$GITHUB_OUTPUT" + echo "version_without_v=${BASH_REMATCH[1]}" >> "$GITHUB_OUTPUT" + else + echo "head commit message does not match 'feat: release vX.Y.Z'" >&2 + exit 1 + fi + + - name: Create GitHub release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + VERSION: ${{ steps.release_env.outputs.version }} + run: | + gh release create "$VERSION" --title "$VERSION" --notes "Release $VERSION" + + - name: Upload to LuaRocks + env: + LUAROCKS_TOKEN: ${{ secrets.LUAROCKS_TOKEN }} + VERSION_WITHOUT_V: ${{ steps.release_env.outputs.version_without_v }} + run: | + luarocks install dkjson + luarocks upload "rockspec/api7-lua-resty-websocket-${VERSION_WITHOUT_V}-0.rockspec" --api-key="$LUAROCKS_TOKEN" diff --git a/Makefile b/Makefile index 8a4a9ea..b651eba 100644 --- a/Makefile +++ b/Makefile @@ -1,18 +1,16 @@ -OPENRESTY_PREFIX=/usr/local/openresty +### dev: Install runtime dependencies locally +.PHONY: dev +dev: + luarocks install rockspec/api7-lua-resty-websocket-master-0.rockspec --only-deps --local -PREFIX ?= /usr/local -LUA_INCLUDE_DIR ?= $(PREFIX)/include -LUA_LIB_DIR ?= $(PREFIX)/lib/lua/$(LUA_VERSION) -INSTALL ?= install - -.PHONY: all test install - -all: ; - -install: all - $(INSTALL) -d $(DESTDIR)/$(LUA_LIB_DIR)/resty/websocket - $(INSTALL) lib/resty/websocket/*.lua $(DESTDIR)/$(LUA_LIB_DIR)/resty/websocket/ - -test: all - PATH=$(OPENRESTY_PREFIX)/nginx/sbin:$$PATH prove -I../test-nginx/lib -r t +### test: Run the test suite +.PHONY: test +test: + PATH="$(PWD)/work/nginx/sbin:$$PATH" prove -I. -r t/ +### help: Show Makefile rules +.PHONY: help +help: + @echo Makefile rules: + @echo + @grep -E '^### [-A-Za-z0-9_]+:' Makefile | sed 's/###/ /' diff --git a/README.markdown b/README.markdown index 5fc6ee8..d899a28 100644 --- a/README.markdown +++ b/README.markdown @@ -629,6 +629,12 @@ each request. Installation ============ +This fork is published to LuaRocks as `api7-lua-resty-websocket` (the `lua-resty-websocket` package name is already held by an unrelated LuaRocks account, hence the different name): + +```shell +luarocks install api7-lua-resty-websocket +``` + It is recommended to use the latest [OpenResty bundle](http://openresty.org) directly where this library is bundled and enabled by default. At least OpenResty 1.4.2.9 is required. And you need to enable LuaJIT when building your OpenResty bundle by passing the `--with-luajit` option to its `./configure` script. No extra Nginx configuration is required. diff --git a/rockspec/api7-lua-resty-websocket-local-0.rockspec b/rockspec/api7-lua-resty-websocket-local-0.rockspec new file mode 100644 index 0000000..59be2ac --- /dev/null +++ b/rockspec/api7-lua-resty-websocket-local-0.rockspec @@ -0,0 +1,30 @@ +package = "api7-lua-resty-websocket" +version = "local-0" +source = { + url = "file://." +} + +description = { + summary = "Lua WebSocket implementation for the ngx_lua module", + detailed = [[ + api7-lua-resty-websocket is api7's fork of the OpenResty WebSocket + library. It implements WebSocket server and client libraries based + on the ngx_lua module, taking advantage of ngx_lua's cosocket API + for fully nonblocking behavior. It also carries a WebSocket reverse + proxy module ported from Kong/lua-resty-websocket-proxy. + ]], + homepage = "https://github.com/api7/lua-resty-websocket", + license = "2-clause BSD", +} + +dependencies = {} + +build = { + type = "builtin", + modules = { + ["resty.websocket.client"] = "lib/resty/websocket/client.lua", + ["resty.websocket.server"] = "lib/resty/websocket/server.lua", + ["resty.websocket.protocol"] = "lib/resty/websocket/protocol.lua", + ["resty.websocket.proxy"] = "lib/resty/websocket/proxy.lua", + } +} diff --git a/rockspec/api7-lua-resty-websocket-master-0.rockspec b/rockspec/api7-lua-resty-websocket-master-0.rockspec new file mode 100644 index 0000000..97478f9 --- /dev/null +++ b/rockspec/api7-lua-resty-websocket-master-0.rockspec @@ -0,0 +1,31 @@ +package = "api7-lua-resty-websocket" +version = "master-0" +source = { + url = "git+https://github.com/api7/lua-resty-websocket", + branch = "master", +} + +description = { + summary = "Lua WebSocket implementation for the ngx_lua module", + detailed = [[ + api7-lua-resty-websocket is api7's fork of the OpenResty WebSocket + library. It implements WebSocket server and client libraries based + on the ngx_lua module, taking advantage of ngx_lua's cosocket API + for fully nonblocking behavior. It also carries a WebSocket reverse + proxy module ported from Kong/lua-resty-websocket-proxy. + ]], + homepage = "https://github.com/api7/lua-resty-websocket", + license = "2-clause BSD", +} + +dependencies = {} + +build = { + type = "builtin", + modules = { + ["resty.websocket.client"] = "lib/resty/websocket/client.lua", + ["resty.websocket.server"] = "lib/resty/websocket/server.lua", + ["resty.websocket.protocol"] = "lib/resty/websocket/protocol.lua", + ["resty.websocket.proxy"] = "lib/resty/websocket/proxy.lua", + } +}