Skip to content

Commit af2c090

Browse files
committed
build: Added basic CI support
1 parent 85426ae commit af2c090

File tree

9 files changed

+146
-10
lines changed

9 files changed

+146
-10
lines changed

.busted

+20
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,30 @@
1+
-- luacheck: ignore 631
2+
local current_folder = debug.getinfo(1).source:match("@?(.*/)"):sub(1, -2)
3+
14
return {
25
_all = {
6+
ROOT = {current_folder .. "/spec"},
37
verbose = false,
8+
["coverage-config-file"] = current_folder .. "/.luacov",
9+
},
10+
default = {
411
coverage = false,
512
output = "gtest",
13+
["exclude-tags"] = "postgres",
614
},
715
ci = {
16+
coverage = true,
17+
output = "junit",
818
["exclude-tags"] = "postgres",
19+
-- First argument is the path to the output file
20+
-- https://github.com/lunarmodules/busted/blob/a144124839f027a2d0a95791936c478d047126fc/busted/outputHandlers/junit.lua#L34C34-L34C43
21+
Xoutput = current_folder .. "/test-results/busted-junit.xml",
22+
},
23+
ci_postgresql = {
24+
output = "junit",
25+
coverage = true,
26+
-- First argument is the path to the output file
27+
-- https://github.com/lunarmodules/busted/blob/a144124839f027a2d0a95791936c478d047126fc/busted/outputHandlers/junit.lua#L34C34-L34C43
28+
Xoutput = current_folder .. "/test-results/busted-junit.xml",
929
},
1030
}

.github/workflows/lint.yml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Lint
2+
3+
on: [push, pull_request]
4+
5+
concurrency:
6+
group: ${{ github.workflow }}-${{ github.ref }}
7+
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
8+
9+
jobs:
10+
lua-check:
11+
timeout-minutes: ${{ fromJSON(vars.GHA_DEFAULT_TIMEOUT || 10) }}
12+
name: Lua Check
13+
runs-on: ubuntu-24.04
14+
permissions:
15+
contents: read
16+
issues: read
17+
checks: write
18+
pull-requests: write
19+
if: (github.actor != 'dependabot[bot]')
20+
21+
steps:
22+
- name: Checkout source code
23+
uses: actions/checkout@v3
24+
25+
- name: Lua Check
26+
uses: Kong/public-shared-actions/code-check-actions/lua-lint@0ccacffed804d85da3f938a1b78c12831935f992 # v2.8.0
27+
with:
28+
additional_args: '--no-default-config --config .luacheckrc'
29+
action_fail: true
30+
print_results: true

.github/workflows/sast.yml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: SAST
2+
3+
on:
4+
pull_request: {}
5+
push:
6+
branches:
7+
- master
8+
- main
9+
workflow_dispatch: {}
10+
11+
12+
jobs:
13+
semgrep:
14+
timeout-minutes: ${{ fromJSON(vars.GHA_DEFAULT_TIMEOUT || 10) }}
15+
name: Semgrep SAST
16+
runs-on: ubuntu-latest
17+
permissions:
18+
# required for all workflows
19+
security-events: write
20+
# only required for workflows in private repositories
21+
actions: read
22+
contents: read
23+
24+
if: (github.actor != 'dependabot[bot]')
25+
26+
steps:
27+
- uses: actions/checkout@v3
28+
- uses: Kong/public-shared-actions/security-actions/semgrep@33449c46c6766a3d3c8f167cc383381225862b36

.github/workflows/tests.yml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Test
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
tests:
7+
timeout-minutes: ${{ fromJSON(vars.GHA_DEFAULT_TIMEOUT || 10) }}
8+
name: Busted Tests
9+
10+
runs-on: ubuntu-24.04
11+
permissions:
12+
checks: write
13+
pull-requests: write
14+
15+
steps:
16+
- name: Checkout source code
17+
uses: actions/checkout@main
18+
- name: Set up Docker Buildx
19+
uses: docker/setup-buildx-action@v3
20+
- name: Run tests
21+
run: make test-unit-ci DOCKER_RUN_FLAGS_TTY=''
22+
- name: Publish Test Results
23+
uses: EnricoMi/publish-unit-test-result-action@v2
24+
if: always()
25+
with:
26+
files: |
27+
test-results/**/*.xml
28+
- name: Setup LCOV
29+
uses: hrishikesh-kadam/setup-lcov@v1
30+
- name: Report code coverage
31+
uses: zgosalvez/github-actions-report-lcov@v3
32+
with:
33+
coverage-files: test-results/luacov.report.out
34+
artifact-name: code-coverage-report
35+
github-token: ${{ secrets.GITHUB_TOKEN }}
36+
update-comment: true

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ luacov.report.out
2424
/lua_modules/
2525
/.luarocks
2626

27+
# LuaCov and Busted test results
28+
/test-results/
29+
2730
/.docker/
2831

2932
# Local folder for scratch files

.luacov

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
include = {
2-
"%/kong%-plugin%/kong%/.+$",
1+
return {
2+
reporter = "lcov",
3+
statsfile = "/kong-plugin/test-results/luacov.stats.out",
4+
reportfile = "/kong-plugin/test-results/luacov.report.out",
5+
runreport = true,
6+
include = {
7+
"%/kong%-plugin%/kong%/.+$",
8+
}
39
}
4-
5-
statsfile = "/kong-plugin/luacov.stats.out"
6-
reportfile = "/kong-plugin/luacov.report.out"
7-
runreport = true

BACKLOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@
1414
## Cleanup
1515

1616
- [ ] The OpenFGA store id in the sqlite database is fixed. Make it dynamic when loading the data.
17+
- [ ] Test with PostgreSQL as database backend.

Makefile

+19-4
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,17 @@ _docker_is_podman = $(shell $(DOCKER) --version | grep podman 2>/dev/null)
2020
# - set username/UID to executor
2121
DOCKER_USER ?= $$(id -u)
2222
DOCKER_USER_OPT = $(if $(_docker_is_podman),--userns keep-id,--user $(DOCKER_USER))
23-
DOCKER_RUN_FLAGS ?= --rm --interactive --tty $(DOCKER_USER_OPT)
23+
DOCKER_RUN_FLAGS_TTY ?= --tty
24+
DOCKER_RUN_FLAGS ?= --rm --interactive $(DOCKER_RUN_FLAGS_TTY) $(DOCKER_USER_OPT)
2425

2526
DOCKER_NO_CACHE :=
2627

2728
BUILDKIT_PROGRESS :=
2829

30+
BUSTED_RUN_PROFILE := default
2931
BUSTED_FILTER :=
3032

31-
BUSTED_ARGS = --config-file /kong-plugin/.busted --run ci --filter '$(BUSTED_FILTER)'
33+
BUSTED_ARGS = --config-file /kong-plugin/.busted --run '$(BUSTED_RUN_PROFILE)' --filter '$(BUSTED_FILTER)'
3234
ifdef BUSTED_NO_KEEP_GOING
3335
BUSTED_ARGS += --no-keep-going
3436
endif
@@ -180,6 +182,9 @@ $(ROCKSPEC_FILE): kong-plugin.rockspec
180182
$(ROCK_FILE): container-ci-kong-tooling $(ROCKSPEC_FILE) $(PLUGIN_FILES)
181183
$(CONTAINER_CI_KONG_TOOLING_RUN) sh -c '(cd /kong-plugin; luarocks make --pack-binary-rock --deps-mode none $(ROCKSPEC_FILE))'
182184

185+
test-results:
186+
mkdir -p test-results
187+
183188
.PHONY: tail-logs
184189
tail-logs:
185190
tail -F servroot/logs/*.log | grep --line-buffered --color '\[\($(KONG_PLUGIN_NAME)\|dns-client\|kong\)\]\|$$'
@@ -254,15 +259,20 @@ stop-services: stop-service-redis stop-service-openfga stop-service-postgres
254259

255260
.PHONY: lint
256261
lint: container-ci-kong-tooling
257-
$(CONTAINER_CI_KONG_TOOLING_RUN) sh -c '(cd /kong-plugin; luacheck .)'
262+
$(CONTAINER_CI_KONG_TOOLING_RUN) sh -c '(cd /kong-plugin; luacheck --no-default-config --config .luacheckrc .)'
258263

259264
.PHONY: format-code
260265
format-code: container-ci-kong-tooling
261266
$(CONTAINER_CI_KONG_TOOLING_RUN) sh -c '(cd /kong-plugin; stylua --check . || stylua --verify .)'
262267

263268
.PHONY: test-unit
264269
test-unit: container-ci-kong-tooling clean-servroot service-openfga
265-
$(CONTAINER_CI_KONG_TOOLING_RUN) busted $(BUSTED_ARGS) /kong-plugin/spec
270+
$(CONTAINER_CI_KONG_TOOLING_RUN) busted $(BUSTED_ARGS)
271+
272+
.PHONY: test-unit-ci
273+
test-unit-ci: BUSTED_RUN_PROFILE = 'ci'
274+
test-unit-ci: clean-test-results test-results container-ci-kong-tooling clean-servroot service-openfga
275+
$(CONTAINER_CI_KONG_TOOLING_RUN) sh -c "(busted $(BUSTED_ARGS))"
266276

267277
.PHONY: tooling-shell
268278
tooling-shell: container-ci-kong-tooling
@@ -287,6 +297,10 @@ lua-language-server-add-kong: container-ci-kong-tooling
287297
$(CONTAINER_CI_KONG_TOOLING_RUN) cp -r /usr/local/share/lua/5.1/. /kong-plugin/.luarocks
288298
$(CONTAINER_CI_KONG_TOOLING_RUN) cp -r /kong /kong-plugin/.luarocks
289299

300+
.PHONY: clean-test-results
301+
clean-test-results:
302+
-$(RMDIR) test-results
303+
290304
.PHONY: clean-servroot
291305
clean-servroot:
292306
-$(RMDIR) $(SERVROOT_PATH)
@@ -328,6 +342,7 @@ clean-container-smoke-test-network:
328342
-$(DOCKER) network rm '$(CONTAINER_CI_NETWORK_NAME)'
329343

330344
.PHONY: clean
345+
clean: clean-test-results
331346
clean: clean-rock clean-rockspec
332347
clean: clean-servroot
333348
clean: clean-container-ci-kong-tooling clean-container-ci-kong-smoke-test clean-container-smoke-test-network

_build/images/kong-plugin-testing-0.1.0-0.rockspec

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ dependencies = {
1414
"busted-hjtest = 0.0.5",
1515
"luacheck = 1.2.0",
1616
"luacov = 0.16.0",
17+
"luacov-reporter-lcov = 0.2",
1718
"lua-llthreads2 = 0.1.6",
1819
"http = 0.4",
1920
}

0 commit comments

Comments
 (0)