Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests(unit): add coverage for spec/01-unit (#10754)
* tests(unit): add coverage workflow run tests with luacov once a week aggregate the results and print it * tests(unit): parametrize build path + dispatchable make build path parametric enable dispatchable workflow in build & coverage
- Loading branch information
Showing
7 changed files
with
227 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
-- Aggregates stats from multiple luacov stat files. | ||
-- If different stats files contain coverage information of common | ||
-- source files, it assumes the provided stats refer to the same | ||
-- version of the source files. | ||
|
||
-- Example stats for a 12 lines file `my/file.lua` | ||
-- that received hits on lines 3, 4, 9: | ||
-- | ||
-- ["my/file.lua"] = { | ||
-- [3] = 1, | ||
-- [4] = 3, | ||
-- [9] = 2, | ||
-- max = 12, | ||
-- max_hits = 3 | ||
-- } | ||
-- | ||
|
||
local luacov_stats = require "luacov.stats" | ||
local luacov_reporter = require "luacov.reporter" | ||
|
||
local all_stats = {} | ||
|
||
|
||
-- load parameters | ||
local params = {...} | ||
local base_path = params[1] or "./luacov-stats-out-" | ||
local file_name = params[2] or "luacov.stats.out" | ||
local output = params[3] or file_name | ||
|
||
|
||
-- load stats - appends incremental index to base_path to load all the artifacts | ||
local loaded_stats = {} | ||
local index = 0 | ||
repeat | ||
index = index + 1 | ||
local stats_file = base_path .. index .. "/" .. file_name | ||
local loaded = luacov_stats.load(stats_file) | ||
if loaded then | ||
loaded_stats[#loaded_stats + 1] = loaded | ||
print("loading file: " .. stats_file) | ||
end | ||
until not loaded | ||
|
||
|
||
-- aggregate stats by file name | ||
for _, stat_data in ipairs(loaded_stats) do | ||
for f_name, f_data in pairs(stat_data) do | ||
if all_stats[f_name] then | ||
assert( | ||
all_stats[f_name].max == f_data.max, | ||
"number of lines in file " .. f_name .. " is inconsistent" | ||
) | ||
-- combine stats (add line hits) | ||
for i = 1, all_stats[f_name].max do | ||
if all_stats[f_name][i] or f_data[i] then | ||
all_stats[f_name][i] = (all_stats[f_name][i] or 0) + (f_data[i] or 0) | ||
end | ||
end | ||
all_stats[f_name].max_hits = math.max(all_stats[f_name].max_hits, f_data.max_hits) | ||
|
||
else | ||
all_stats[f_name] = f_data | ||
end | ||
end | ||
end | ||
luacov_stats.save(output, all_stats) | ||
|
||
-- generate report | ||
luacov_reporter.report() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
name: Build | ||
on: | ||
workflow_call: | ||
inputs: | ||
build-root-suffix: | ||
required: true | ||
type: string | ||
|
||
env: | ||
BUILD_ROOT: ${{ github.workspace }}${{ inputs.build-root-suffix }} | ||
|
||
jobs: | ||
build: | ||
name: Build dependencies | ||
runs-on: ubuntu-22.04 | ||
|
||
steps: | ||
- name: Checkout Kong source code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Lookup build cache | ||
id: cache-deps | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
${{ env.BUILD_ROOT }} | ||
key: ${{ hashFiles('.requirements', 'kong-*.rockspec', '.bazelversion', '.bazelrc', 'build/**', 'BUILD.bazel', 'WORKSPACE', '.github/workflows/build_and_test.yml') }} | ||
|
||
- name: Install packages | ||
if: steps.cache-deps.outputs.cache-hit != 'true' | ||
run: sudo apt update && sudo apt install libyaml-dev valgrind libprotobuf-dev | ||
|
||
- name: Build Kong | ||
if: steps.cache-deps.outputs.cache-hit != 'true' | ||
run: | | ||
make build-kong | ||
BUILD_PREFIX=$BUILD_ROOT/kong-dev | ||
export PATH="$BUILD_PREFIX/bin:$BUILD_PREFIX/openresty/nginx/sbin:$BUILD_PREFIX/openresty/bin:$PATH" | ||
chmod +rw -R $BUILD_PREFIX | ||
nginx -V | ||
ldd $(which nginx) | ||
luarocks | ||
- name: Bazel Outputs | ||
uses: actions/upload-artifact@v3 | ||
if: failure() | ||
with: | ||
name: bazel-outputs | ||
path: | | ||
bazel-out/_tmp/actions | ||
- name: Build Dev Kong dependencies | ||
if: steps.cache-deps.outputs.cache-hit != 'true' | ||
run: | | ||
make install-dev-rocks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
name: Build & Test Coverage | ||
on: | ||
schedule: | ||
- cron: "15 0 * * 0" | ||
workflow_dispatch: | ||
|
||
env: | ||
BUILD_ROOT: ${{ github.workspace }}/bazel-bin/build | ||
|
||
jobs: | ||
build: | ||
uses: ./.github/workflows/build.yml | ||
with: | ||
build-root-suffix: /bazel-bin/build | ||
|
||
unit-tests: | ||
name: Unit tests | ||
runs-on: ubuntu-22.04 | ||
needs: build | ||
|
||
services: | ||
postgres: | ||
image: postgres:13 | ||
env: | ||
POSTGRES_USER: kong | ||
POSTGRES_DB: kong | ||
POSTGRES_HOST_AUTH_METHOD: trust | ||
ports: | ||
- 5432:5432 | ||
options: --health-cmd pg_isready --health-interval 5s --health-timeout 5s --health-retries 8 | ||
|
||
steps: | ||
- name: Checkout Kong source code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Lookup build cache | ||
id: cache-deps | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
${{ env.BUILD_ROOT }} | ||
key: ${{ hashFiles('.requirements', 'kong-*.rockspec', '.bazelversion', '.bazelrc', 'build/**', 'BUILD.bazel', 'WORKSPACE', '.github/workflows/build_and_test.yml') }} | ||
|
||
- name: Unit tests | ||
env: | ||
KONG_TEST_PG_DATABASE: kong | ||
KONG_TEST_PG_USER: kong | ||
run: | | ||
source ${{ env.BUILD_ROOT }}/kong-dev-venv.sh | ||
bin/busted spec/01-unit --coverage | ||
- name: Archive coverage stats file | ||
uses: actions/upload-artifact@v3 | ||
if: success() | ||
with: | ||
name: luacov-stats-out-1 | ||
retention-days: 1 | ||
path: | | ||
luacov.stats.out | ||
# TODO: run jobs with the remaining tests (with coverage enabled) and archive each artifact as luacov-stats-out-{i} | ||
|
||
aggregator: | ||
needs: [unit-tests] # add dependencies for all the test jobs | ||
name: Luacov stats aggregator | ||
runs-on: ubuntu-22.04 | ||
|
||
steps: | ||
- name: Checkout source code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install requirements | ||
run: | | ||
sudo apt-get update && sudo apt-get install -y luarocks | ||
sudo luarocks install luacov | ||
# Download all archived coverage stats files | ||
- uses: actions/download-artifact@v3 | ||
|
||
- name: Stats aggregation | ||
shell: bash | ||
run: | | ||
lua .ci/luacov-stats-aggregator.lua "luacov-stats-out-" "luacov.stats.out" | ||
awk '/Summary/,0' luacov.report.out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
return { | ||
|
||
runreport = true, | ||
|
||
include = { | ||
"kong$", | ||
"kong%/.+$", | ||
}, | ||
|
||
exclude = { | ||
"bazel%-bin/build", | ||
"^spec/" | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62bcbcb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bazel Build
Docker image available
kong/kong:62bcbcb657f10b8226dfded19a12eee988b19424
Artifacts available https://github.com/Kong/kong/actions/runs/4882195700