Skip to content

Commit b502b72

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

File tree

8 files changed

+123
-6
lines changed

8 files changed

+123
-6
lines changed

.busted

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
1+
local current_folder = debug.getinfo(1).source:match("@?(.*/)"):sub(1, -2)
2+
13
return {
24
_all = {
5+
ROOT = {current_folder .. "/spec"},
36
verbose = false,
7+
["coverage-config-file"] = current_folder .. "/.luacov",
8+
},
9+
default = {
410
coverage = false,
511
output = "gtest",
12+
["exclude-tags"] = "postgres",
613
},
714
ci = {
15+
coverage = true,
16+
output = "junit",
817
["exclude-tags"] = "postgres",
918
},
19+
ci_postgresql = {
20+
output = "junit",
21+
coverage = true,
22+
},
1023
}

.github/workflows/lint.yml

Lines changed: 30 additions & 0 deletions
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

Lines changed: 28 additions & 0 deletions
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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
12+
steps:
13+
- name: Checkout source code
14+
uses: actions/checkout@main
15+
- name: Set up Docker Buildx
16+
uses: docker/setup-buildx-action@v3
17+
- name: Run tests
18+
run: make test-unit-ci DOCKER_RUN_FLAGS_TTY=''
19+
- name: Publish Test Results
20+
uses: EnricoMi/publish-unit-test-result-action@v2
21+
if: always()
22+
with:
23+
files: |
24+
test-results/**/*.xml
25+
test-results/**/*.trx
26+
test-results/**/*.json

.gitignore

Lines changed: 3 additions & 0 deletions
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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ include = {
22
"%/kong%-plugin%/kong%/.+$",
33
}
44

5-
statsfile = "/kong-plugin/luacov.stats.out"
6-
reportfile = "/kong-plugin/luacov.report.out"
5+
statsfile = "/kong-plugin/test-results/luacov.stats.out"
6+
reportfile = "/kong-plugin/test-results/luacov.report.out"
77
runreport = true

BACKLOG.md

Lines changed: 1 addition & 0 deletions
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

Lines changed: 20 additions & 4 deletions
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,21 @@ 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) | awk '/<testsuites/{flag=1}flag' | tee /kong-plugin/test-results/busted.junit.xml)"
276+
266277

267278
.PHONY: tooling-shell
268279
tooling-shell: container-ci-kong-tooling
@@ -287,6 +298,10 @@ lua-language-server-add-kong: container-ci-kong-tooling
287298
$(CONTAINER_CI_KONG_TOOLING_RUN) cp -r /usr/local/share/lua/5.1/. /kong-plugin/.luarocks
288299
$(CONTAINER_CI_KONG_TOOLING_RUN) cp -r /kong /kong-plugin/.luarocks
289300

301+
.PHONY: clean-test-results
302+
clean-test-results:
303+
-$(RMDIR) test-results
304+
290305
.PHONY: clean-servroot
291306
clean-servroot:
292307
-$(RMDIR) $(SERVROOT_PATH)
@@ -328,6 +343,7 @@ clean-container-smoke-test-network:
328343
-$(DOCKER) network rm '$(CONTAINER_CI_NETWORK_NAME)'
329344

330345
.PHONY: clean
346+
clean: clean-test-results
331347
clean: clean-rock clean-rockspec
332348
clean: clean-servroot
333349
clean: clean-container-ci-kong-tooling clean-container-ci-kong-smoke-test clean-container-smoke-test-network

0 commit comments

Comments
 (0)