-
Notifications
You must be signed in to change notification settings - Fork 0
feat(ci): add GitHub Actions workflow with code coverage #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,54 @@ | ||
| name: CI | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| pull_request: | ||
| branches: [main] | ||
|
|
||
| jobs: | ||
| test: | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| neovim: ['v0.11.0', 'nightly'] | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Neovim | ||
| uses: rhysd/action-setup-vim@v1 | ||
| with: | ||
| neovim: true | ||
| version: ${{ matrix.neovim }} | ||
|
|
||
| - name: Install LuaRocks | ||
| run: sudo apt-get install -y luarocks | ||
|
|
||
| - name: Install luacov | ||
| run: | | ||
| sudo luarocks install luacov | ||
| sudo luarocks install luacov-reporter-lcov | ||
|
|
||
| - name: Clone plenary.nvim | ||
| run: | | ||
| mkdir -p ~/.local/share/nvim/site/pack/vendor/start | ||
| git clone --depth 1 https://github.com/nvim-lua/plenary.nvim \ | ||
| ~/.local/share/nvim/site/pack/vendor/start/plenary.nvim | ||
|
|
||
| - name: Run tests | ||
| run: ./scripts/test.sh | ||
|
|
||
| - name: Run tests with coverage | ||
| if: matrix.neovim == 'v0.11.0' | ||
| env: | ||
| LUA_PATH: '/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/init.lua;;' | ||
| LUA_CPATH: '/usr/local/lib/lua/5.1/?.so;;' | ||
| run: ./scripts/test-coverage.sh | ||
|
|
||
| - name: Upload coverage to Codecov | ||
| if: matrix.neovim == 'v0.11.0' | ||
| uses: codecov/codecov-action@v5 | ||
| with: | ||
| files: ./lcov.info | ||
| fail_ci_if_error: false |
This file contains hidden or 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,9 @@ | ||
| return { | ||
| include = { | ||
| "lua/shelltime/.+%.lua$", | ||
| }, | ||
| exclude = { | ||
| "tests/", | ||
| "plugin/", | ||
| }, | ||
| } |
This file contains hidden or 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,29 @@ | ||
| #!/bin/bash | ||
| # Run tests with code coverage using luacov | ||
| # Requires: luacov, luacov-reporter-lcov installed via luarocks | ||
|
|
||
| set -e | ||
|
|
||
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| PROJECT_DIR="$(dirname "$SCRIPT_DIR")" | ||
|
|
||
| cd "$PROJECT_DIR" | ||
|
|
||
| # Clean previous coverage data | ||
| rm -f luacov.stats.out luacov.report.out lcov.info | ||
|
|
||
| # Run tests with coverage init (loads luacov before test code) | ||
| nvim --headless \ | ||
| -u "$PROJECT_DIR/tests/coverage_init.lua" \ | ||
| -c "PlenaryBustedDirectory tests/ {minimal_init = 'tests/coverage_init.lua'}" \ | ||
| 2>&1 || true | ||
|
|
||
| # Generate lcov report for Codecov | ||
| if [ -f luacov.stats.out ]; then | ||
| luacov -r lcov -o lcov.info | ||
| echo "Coverage report generated: lcov.info" | ||
| else | ||
| echo "Warning: No coverage stats generated (luacov may not be installed)" | ||
| # Don't fail CI if coverage isn't available | ||
| exit 0 | ||
| fi | ||
This file contains hidden or 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,23 @@ | ||
| -- Coverage init for running tests with luacov | ||
| -- This file wraps minimal_init.lua and adds luacov support | ||
|
|
||
| -- Initialize luacov BEFORE loading any other modules | ||
| local ok, luacov = pcall(require, 'luacov') | ||
| if not ok then | ||
| print('Warning: luacov not found, running tests without coverage') | ||
| end | ||
|
|
||
| -- Load the regular minimal init | ||
| local script_path = debug.getinfo(1, 'S').source:sub(2) | ||
| local tests_dir = vim.fn.fnamemodify(script_path, ':h') | ||
| dofile(tests_dir .. '/minimal_init.lua') | ||
|
|
||
| -- Save coverage stats on exit | ||
| vim.api.nvim_create_autocmd('VimLeavePre', { | ||
| callback = function() | ||
| if ok and luacov then | ||
| local runner = require('luacov.runner') | ||
| runner.save_stats() | ||
| end | ||
| end, | ||
| }) |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
For better script robustness, it's recommended to use
set -euo pipefailinstead of justset -e.This will make the script exit on unset variables (
-u) and on failures in pipelines (-o pipefail), which are common sources of bugs in shell scripts.