Skip to content

Commit 0fd5684

Browse files
committed
build: Add smoke test to CI test action and added new release action
1 parent ec4a44c commit 0fd5684

File tree

14 files changed

+145
-46
lines changed

14 files changed

+145
-46
lines changed

.github/workflows/release.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Release Rock
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*' # Trigger for version tags
7+
8+
jobs:
9+
build_and_release:
10+
runs-on: ubuntu-24.04
11+
steps:
12+
- name: Check out code
13+
uses: actions/checkout@main
14+
- name: Set up Docker Buildx
15+
uses: docker/setup-buildx-action@v3
16+
- name: Check if rockspec files are present
17+
run: |
18+
VERSION="$(make release-info | grep -oP '^VERSION=\K.*')"
19+
ROCKSPEC_RELEASE_FILE="$(make release-info | grep -oP '^ROCKSPEC_RELEASE_FILE=\K.*')"
20+
if [ ! -f "${ROCKSPEC_RELEASE_FILE}" ]; then
21+
echo "No rockspec files found. Exiting."
22+
exit 1
23+
fi
24+
# Compare tag with version with VERSIOn
25+
if [ "${GITHUB_REF}" != "refs/tags/v${VERSION}" ]; then
26+
echo "Tag does not match version. Exiting."
27+
exit 1
28+
fi
29+
- name: Publish to LuaRocks
30+
env:
31+
LUAROCKS_API_KEY: ${{ secrets.LUAROCKS_API_KEY }}
32+
run: |
33+
ROCKSPEC_RELEASE_FILE="$(make release-info | grep -oP '^ROCKSPEC_RELEASE_FILE=\K.*')"
34+
luarocks upload --temp-key="${LUAROCKS_API_KEY}" "${ROCKSPEC_RELEASE_FILE}"

.github/workflows/sast.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
semgrep:
1414
timeout-minutes: ${{ fromJSON(vars.GHA_DEFAULT_TIMEOUT || 10) }}
1515
name: Semgrep SAST
16-
runs-on: ubuntu-latest
16+
runs-on: ubuntu-24.04
1717
permissions:
1818
# required for all workflows
1919
security-events: write

.github/workflows/tests.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,27 @@ jobs:
3434
artifact-name: code-coverage-report
3535
github-token: ${{ secrets.GITHUB_TOKEN }}
3636
update-comment: true
37+
smoke-tests:
38+
timeout-minutes: ${{ fromJSON(vars.GHA_DEFAULT_TIMEOUT || 10) }}
39+
name: Smoke Tests
40+
41+
runs-on: ubuntu-24.04
42+
43+
steps:
44+
- name: Checkout code
45+
uses: actions/checkout@v2
46+
- name: Set up Docker Buildx
47+
uses: docker/setup-buildx-action@v3
48+
- name: Create .env file
49+
run: |
50+
cp .env.tpl .env
51+
- name: Run the smoke test server
52+
run: |
53+
make smoke-test-run-server DOCKER_RUN_FLAGS_TTY='-d'
54+
- name: Wait for service to be ready
55+
run: |
56+
# Wait until kong is ready
57+
timeout 60s bash -c 'until docker exec kong-plugin-kong-authz-openfga-smoke-test curl -i http://localhost:8007/status/ready; do sleep 5; done'
58+
- name: Run smoke tests
59+
run: |
60+
make smoke-test-run-test DOCKER_RUN_FLAGS_TTY=''

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ luacov.stats.out
99
# exclude LuaCov report
1010
luacov.report.out
1111
# Exclude all rockspec files except the main one
12-
/*.rockspec
12+
/kong-plugin-*-dev-*.rockspec
1313
!/kong-plugin.rockspec
1414
# curl netrc
1515
/.netrc

BACKLOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010
- [ ] Add live tests to the OpenFGA server addition to the mock server.
1111
- [ ] Add an example that uses Consumer in conjunction with the Basic Authentication plugin.
12-
- [ ] Add build, test, and deploy pipeline (GitHub Actions) to the project
13-
- [ ] Add GitHub action to perform a smoke test
14-
- [ ] Add GitHub action to publish .rock when a version was tagged. Use LUAROCKS_API_KEY secret.
12+
- [x] Add build, test, and deploy pipeline (GitHub Actions) to the project
13+
- [x] Add GitHub action to perform a smoke test
14+
- [x] Add GitHub action to publish .rock when a version was tagged. Use LUAROCKS_API_KEY secret.
1515

1616
## Cleanup
1717

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515
- Added function to make FGA requests with retry logic
1616
- Added unit tests to mock HTTP requests and return different responses based on call count
1717
- Added support for EMMY Debugger with configurable host and port
18+
- Added smoke test to CI pipeline
19+
- Added GitHub action to publish the plugin to luarocks.org when a version is tagged
1820

1921
### Changed
2022

2123
- Extracted `kong.response.exit(500, "An unexpected error occurred")` to its own function
2224
- Extracted the code inside the `repeat ... until` loop into its own function
2325
- Modified `make_fga_request` to return a boolean indicating allow/deny
26+
- For local development, a kong-*dev-0.rockspec file is used to install the plugin. This helps segregate
27+
the testing from the release process.
28+
- Changed the rockspec license to MIT.
2429

2530
### Fixed
2631

Makefile

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ PLUGIN_FILES = $(shell find kong -type f -name '*.lua')
44

55
KONG_IMAGE_TAG := $(KONG_VERSION)-rhel@sha256:$(KONG_IMAGE_HASH)
66

7-
ROCKSPEC_FILE := kong-plugin-$(KONG_PLUGIN_NAME)-$(KONG_PLUGIN_VERSION)-$(KONG_PLUGIN_REVISION).rockspec
8-
ROCK_FILE := kong-plugin-$(KONG_PLUGIN_NAME)-$(KONG_PLUGIN_VERSION)-$(KONG_PLUGIN_REVISION).all.rock
7+
ROCKSPEC_DEV_FILE := kong-plugin-$(KONG_PLUGIN_NAME)-dev-0.rockspec
8+
ROCKSPEC_RELEASE_FILE := kong-plugin-$(KONG_PLUGIN_NAME)-$(KONG_PLUGIN_VERSION)-$(KONG_PLUGIN_REVISION).rockspec
9+
ROCK_RELEASE_FILE := kong-plugin-$(KONG_PLUGIN_NAME)-$(KONG_PLUGIN_VERSION)-$(KONG_PLUGIN_REVISION).all.rock
910

1011
SERVROOT_PATH := servroot
1112

@@ -129,8 +130,6 @@ CONTAINER_CI_KONG_TOOLING_BUILD = DOCKER_BUILDKIT=1 BUILDKIT_PROGRESS=$(BUILDKIT
129130
--build-arg KONG_IMAGE_TAG='$(KONG_IMAGE_TAG)' \
130131
--build-arg KONG_TARGET_VERSION='$(KONG_VERSION)' \
131132
--build-arg KONG_PLUGIN_NAME='$(KONG_PLUGIN_NAME)' \
132-
--build-arg KONG_PLUGIN_VERSION='$(KONG_PLUGIN_VERSION)' \
133-
--build-arg KONG_PLUGIN_REVISION='$(KONG_PLUGIN_REVISION)' \
134133
--build-arg PONGO_KONG_VERSION='$(PONGO_KONG_VERSION)' \
135134
--build-arg PONGO_ARCHIVE='$(PONGO_ARCHIVE)' \
136135
--build-arg STYLUA_VERSION='$(STYLUA_VERSION)' \
@@ -144,11 +143,13 @@ CONTAINER_CI_KONG_SMOKE_TEST_BUILD = DOCKER_BUILDKIT=1 BUILDKIT_PROGRESS=$(BUILD
144143
--build-arg KONG_IMAGE_NAME='$(KONG_IMAGE_NAME)' \
145144
--build-arg KONG_IMAGE_TAG='$(KONG_IMAGE_TAG)' \
146145
--build-arg KONG_PLUGIN_NAME='$(KONG_PLUGIN_NAME)' \
147-
--build-arg KONG_PLUGIN_VERSION='$(KONG_PLUGIN_VERSION)' \
148-
--build-arg KONG_PLUGIN_REVISION='$(KONG_PLUGIN_REVISION)' \
149-
--build-arg KONG_PLUGIN_ROCK_FILE='$(ROCK_FILE)' \
146+
--build-arg KONG_PLUGIN_ROCKSPEC_FILE='$(ROCKSPEC_DEV_FILE)' \
150147
.
151148

149+
CONTAINER_CI_KONG_RUN := MSYS_NO_PATHCONV=1 $(DOCKER) run $(DOCKER_RUN_FLAGS) \
150+
-v '$(PWD):$(DOCKER_MOUNT_IN_CONTAINER)' \
151+
'$(KONG_IMAGE_NAME):$(KONG_IMAGE_TAG)'
152+
152153
CONTAINER_CI_KONG_TOOLING_RUN := MSYS_NO_PATHCONV=1 $(DOCKER) run $(DOCKER_RUN_FLAGS) \
153154
-p 9966:9966 \
154155
-e KONG_SPEC_TEST_REDIS_HOST='$(CONTAINER_CI_REDIS_NAME)' \
@@ -205,12 +206,24 @@ TAG ?=
205206
.PHONY: all
206207
all: test
207208

208-
$(ROCKSPEC_FILE): kong-plugin.rockspec
209-
cp kong-plugin.rockspec $(ROCKSPEC_FILE)
209+
$(ROCKSPEC_DEV_FILE): kong-plugin.rockspec
210+
cp kong-plugin.rockspec $(ROCKSPEC_DEV_FILE)
211+
$(CONTAINER_CI_KONG_RUN) sh -c '(cd $(DOCKER_MOUNT_IN_CONTAINER); luarocks new_version $(ROCKSPEC_DEV_FILE) --tag=dev-0 --dir .)'
212+
213+
$(ROCKSPEC_RELEASE_FILE): $(ROCKSPEC_DEV_FILE)
214+
$(CONTAINER_CI_KONG_RUN) sh -c '(cd $(DOCKER_MOUNT_IN_CONTAINER); luarocks new_version $(ROCKSPEC_DEV_FILE) --tag=v$(KONG_PLUGIN_VERSION)-$(KONG_PLUGIN_REVISION) --dir .)'
215+
216+
.PHONY: release-rockspec
217+
release-rockspec: $(ROCKSPEC_RELEASE_FILE)
218+
219+
.PHONY: release-rockspec
220+
release-info:
221+
@echo "VERSION=v$(KONG_PLUGIN_VERSION)-$(KONG_PLUGIN_REVISION)"
222+
@echo "ROCKSPEC_RELEASE_FILE=$(ROCKSPEC_RELEASE_FILE)"
210223

211224
# Rebuild the rock file every time the rockspec or the kong/**/.lua files change
212-
$(ROCK_FILE): container-ci-kong-tooling $(ROCKSPEC_FILE) $(PLUGIN_FILES)
213-
$(CONTAINER_CI_KONG_TOOLING_RUN) sh -c '(cd $(DOCKER_MOUNT_IN_CONTAINER); luarocks make --pack-binary-rock --deps-mode none $(ROCKSPEC_FILE))'
225+
$(ROCK_RELEASE_FILE): container-ci-kong-tooling $(ROCKSPEC_RELEASE_FILE) $(PLUGIN_FILES)
226+
$(CONTAINER_CI_KONG_TOOLING_RUN) sh -c '(cd $(DOCKER_MOUNT_IN_CONTAINER); luarocks make --pack-binary-rock --deps-mode none $(ROCKSPEC_RELEASE_FILE))'
214227

215228
test-results:
216229
mkdir -p $(TEST_RESULTS_PATH)
@@ -223,10 +236,10 @@ tail-logs:
223236
test: lint test-unit
224237

225238
.PHONY: pack
226-
pack: $(ROCK_FILE)
239+
pack: $(ROCK_RELEASE_FILE)
227240

228241
.PHONY: container-ci-kong-tooling
229-
container-ci-kong-tooling: $(ROCKSPEC_FILE) container-network-ci
242+
container-ci-kong-tooling: $(ROCKSPEC_DEV_FILE) container-network-ci
230243
$(CONTAINER_CI_KONG_TOOLING_BUILD)
231244

232245
.PHONY: container-ci-kong-tooling-debug
@@ -235,7 +248,7 @@ container-ci-kong-tooling-debug: DOCKER_NO_CACHE = '--no-cache'
235248
container-ci-kong-tooling-debug: container-ci-kong-tooling
236249

237250
.PHONY: container-ci-kong-smoke-test
238-
container-ci-kong-smoke-test: $(ROCK_FILE) container-network-ci
251+
container-ci-kong-smoke-test: $(ROCKSPEC_DEV_FILE) container-network-ci
239252
$(CONTAINER_CI_KONG_SMOKE_TEST_BUILD)
240253

241254
.PHONY: container-ci-kong-smoke-test-debug
@@ -340,6 +353,7 @@ clean-servroot:
340353
.PHONY: clean-rockspec
341354
clean-rockspec:
342355
-$(RMDIR) kong-plugin-*.rockspec
356+
#-git ls-files --others --exclude-standard --ignored -- | grep 'kong-plugin-.*\.rockspec' | xargs $(RM) || true
343357

344358
.PHONY: clean-rock
345359
clean-rock:

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -286,21 +286,22 @@ The project bundles a mock server for OpenFGA.
286286

287287
- <https://marketplace.visualstudio.com/items?itemName=sumneko.lua>
288288
- <https://marketplace.visualstudio.com/items?itemName=dwenegar.vscode-luacheck>
289+
- <https://marketplace.visualstudio.com/items?itemName=tangzx.emmylua>
289290

290291
# Release a new version
291292

292293
1. Checkout the main branch
293294
1. `git checkout main`
294295
2. Update the version number in [plugin.properties](plugin.properties)
295-
3. Update the version number in [kong-plugin.rockspec](kong-plugin.rockspec)
296-
4. Update the version number in [README.md](README.md)
296+
3. Update the version number in [README.md](README.md)
297+
4. Generate the release rockspec file
298+
1. `make release-rockspec`
297299
5. Update the version number in [kong/plugins/kong-authz-openfga/handler.lua](kong/plugins/kong-authz-openfga/handler.lua)
298300
6. Add a new section to [CHANGELOG.md](CHANGELOG.md) with the release highlights
299301
7. Commit the changes, create a tag and push changes and tag to the remote repository
300-
1. `git add plugin.properties kong-plugin.rockspec README.md kong/plugins/*/handler.lua CHANGELOG.md`
302+
1. `git add plugin.properties *.rockspec README.md kong/plugins/*/handler.lua CHANGELOG.md`
301303
2. `git commit -m "Release x.y.z-r"`
302304
3. `git tag x.y.z-r`
303305
4. `git push`
304306
5. `git push --tags`
305-
8. @TODO: Add step to publish the \*.rock file to LuaRocks
306-
9. @TODO: Add step to perform a release in GitHub
307+
8. @TODO: Add step to perform a release in GitHub

_build/images/kong-smoke-test/Dockerfile

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,23 @@ FROM ${KONG_IMAGE_NAME}:${KONG_IMAGE_TAG} AS builder
55
USER root
66

77
ARG KONG_PLUGIN_NAME
8-
ARG KONG_PLUGIN_VERSION
9-
ARG KONG_PLUGIN_REVISION
10-
ARG KONG_PLUGIN_ROCK_FILE
8+
ARG KONG_PLUGIN_ROCKSPEC_FILE
119

1210
RUN dnf install -y gcc m4 --setopt=install_weak_deps=False \
1311
&& dnf clean all
1412

15-
COPY ${KONG_PLUGIN_ROCK_FILE} /${KONG_PLUGIN_ROCK_FILE}
13+
WORKDIR /plugin
14+
COPY . .
1615

17-
RUN luarocks install /${KONG_PLUGIN_ROCK_FILE}
16+
# Install from .rockspec
17+
RUN find && luarocks make ${KONG_PLUGIN_ROCKSPEC_FILE}
1818

1919
FROM ${KONG_IMAGE_NAME}:${KONG_IMAGE_TAG}
2020

2121
ENV KONG_LOG_LEVEL=debug
2222

23+
ENV KONG_NGINX_WORKER_PROCESSES=1
24+
2325
# Add the Lua files (.lua)
2426
COPY --from=builder /usr/local/share/lua/5.1 /usr/local/share/lua/5.1
2527

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Ignore all files
2+
*
3+
4+
# Exclude the following files
5+
!/kong/
6+
!/README.md
7+
!/LICENSE
8+
!/kong-plugin-*-dev-0.rockspec

0 commit comments

Comments
 (0)