Skip to content

Commit 4fa8be1

Browse files
authored
Merge pull request #3 from shelltime/feat/add-github-actions-ci
feat(ci): add GitHub Actions workflow with code coverage
2 parents cd4094b + 83db2fd commit 4fa8be1

5 files changed

Lines changed: 120 additions & 1 deletion

File tree

.github/workflows/ci.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
neovim: ['v0.11.0', 'nightly']
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Setup Neovim
20+
uses: rhysd/action-setup-vim@v1
21+
with:
22+
neovim: true
23+
version: ${{ matrix.neovim }}
24+
25+
- name: Install LuaRocks
26+
run: sudo apt-get install -y luarocks
27+
28+
- name: Install luacov
29+
run: |
30+
sudo luarocks install luacov
31+
sudo luarocks install luacov-reporter-lcov
32+
33+
- name: Clone plenary.nvim
34+
run: |
35+
mkdir -p ~/.local/share/nvim/site/pack/vendor/start
36+
git clone --depth 1 https://github.com/nvim-lua/plenary.nvim \
37+
~/.local/share/nvim/site/pack/vendor/start/plenary.nvim
38+
39+
- name: Run tests
40+
run: ./scripts/test.sh
41+
42+
- name: Run tests with coverage
43+
if: matrix.neovim == 'v0.11.0'
44+
env:
45+
LUA_PATH: '/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/init.lua;;'
46+
LUA_CPATH: '/usr/local/lib/lua/5.1/?.so;;'
47+
run: ./scripts/test-coverage.sh
48+
49+
- name: Upload coverage to Codecov
50+
if: matrix.neovim == 'v0.11.0'
51+
uses: codecov/codecov-action@v5
52+
with:
53+
files: ./lcov.info
54+
fail_ci_if_error: false

.luacov

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
return {
2+
include = {
3+
"lua/shelltime/.+%.lua$",
4+
},
5+
exclude = {
6+
"tests/",
7+
"plugin/",
8+
},
9+
}

scripts/test-coverage.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
# Run tests with code coverage using luacov
3+
# Requires: luacov, luacov-reporter-lcov installed via luarocks
4+
5+
set -e
6+
7+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
8+
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
9+
10+
cd "$PROJECT_DIR"
11+
12+
# Clean previous coverage data
13+
rm -f luacov.stats.out luacov.report.out lcov.info
14+
15+
# Run tests with coverage init (loads luacov before test code)
16+
nvim --headless \
17+
-u "$PROJECT_DIR/tests/coverage_init.lua" \
18+
-c "PlenaryBustedDirectory tests/ {minimal_init = 'tests/coverage_init.lua'}" \
19+
2>&1 || true
20+
21+
# Generate lcov report for Codecov
22+
if [ -f luacov.stats.out ]; then
23+
luacov -r lcov -o lcov.info
24+
echo "Coverage report generated: lcov.info"
25+
else
26+
echo "Warning: No coverage stats generated (luacov may not be installed)"
27+
# Don't fail CI if coverage isn't available
28+
exit 0
29+
fi

tests/coverage_init.lua

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
-- Coverage init for running tests with luacov
2+
-- This file wraps minimal_init.lua and adds luacov support
3+
4+
-- Initialize luacov BEFORE loading any other modules
5+
local ok, luacov = pcall(require, 'luacov')
6+
if not ok then
7+
print('Warning: luacov not found, running tests without coverage')
8+
end
9+
10+
-- Load the regular minimal init
11+
local script_path = debug.getinfo(1, 'S').source:sub(2)
12+
local tests_dir = vim.fn.fnamemodify(script_path, ':h')
13+
dofile(tests_dir .. '/minimal_init.lua')
14+
15+
-- Save coverage stats on exit
16+
vim.api.nvim_create_autocmd('VimLeavePre', {
17+
callback = function()
18+
if ok and luacov then
19+
local runner = require('luacov.runner')
20+
runner.save_stats()
21+
end
22+
end,
23+
})

tests/minimal_init.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
local plugin_dir = vim.fn.fnamemodify(debug.getinfo(1, 'S').source:sub(2), ':h:h')
66
vim.opt.rtp:prepend(plugin_dir)
77

8-
-- Add tests directory to package path for helpers
8+
-- Add project root to package path for 'tests.helpers' requires
9+
package.path = plugin_dir .. '/?.lua;' .. package.path
10+
package.path = plugin_dir .. '/?/init.lua;' .. package.path
11+
12+
-- Add tests directory to package path for 'helpers' requires
913
package.path = plugin_dir .. '/tests/?.lua;' .. package.path
1014
package.path = plugin_dir .. '/tests/?/init.lua;' .. package.path
1115

0 commit comments

Comments
 (0)