feat: implement health checks
This commit is contained in:
@@ -0,0 +1,35 @@
|
|||||||
|
name: Pull Request Checks
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
branches: [main]
|
||||||
|
jobs:
|
||||||
|
checks:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v7
|
||||||
|
- name: Install stylua
|
||||||
|
run: |
|
||||||
|
curl -L -o stylua.zip https://github.com/JohnnyMorganz/StyLua/releases/latest/download/stylua-linux-x86_64.zip
|
||||||
|
unzip -o stylua.zip
|
||||||
|
chmod +x stylua
|
||||||
|
mv stylua /usr/local/bin/
|
||||||
|
- name: Install lua-language-server
|
||||||
|
run: |
|
||||||
|
LUA_LS_URL=$(curl -s https://api.github.com/repos/LuaLS/lua-language-server/releases/latest \
|
||||||
|
| grep '"browser_download_url".*linux-x64' \
|
||||||
|
| sed 's/.*"\(.*\)".*/\1/')
|
||||||
|
curl -L -o /tmp/lua-ls.tar.gz "$LUA_LS_URL"
|
||||||
|
mkdir -p /usr/local/lib/lua-language-server
|
||||||
|
tar -xzf /tmp/lua-ls.tar.gz -C /usr/local/lib/lua-language-server
|
||||||
|
ln -s /usr/local/lib/lua-language-server/bin/lua-language-server /usr/local/bin/lua-language-server
|
||||||
|
- name: Install neovim
|
||||||
|
run: |
|
||||||
|
curl -L -o /tmp/nvim.tar.gz https://github.com/neovim/neovim/releases/latest/download/nvim-linux-x86_64.tar.gz
|
||||||
|
tar -xzf /tmp/nvim.tar.gz -C /usr/local --strip-components=1
|
||||||
|
- name: Format check
|
||||||
|
run: stylua --check .
|
||||||
|
- name: Lint
|
||||||
|
run: lua-language-server --check=.
|
||||||
|
- name: Test
|
||||||
|
run: nvim --headless -c "PlenaryBustedDirectory tests/watchexec/ {minimal_init = 'tests/minimal_init.lua'}" -c "q"
|
||||||
+16
-2
@@ -1,13 +1,27 @@
|
|||||||
{
|
{
|
||||||
|
"$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json",
|
||||||
"compiler": {
|
"compiler": {
|
||||||
"verbosity": "Information"
|
"verbosity": "Information"
|
||||||
},
|
},
|
||||||
|
"diagnostics": {
|
||||||
|
"globals": [
|
||||||
|
"vim",
|
||||||
|
"describe",
|
||||||
|
"it",
|
||||||
|
"before_each",
|
||||||
|
"after_each",
|
||||||
|
"assert"
|
||||||
|
]
|
||||||
|
},
|
||||||
"workspace": {
|
"workspace": {
|
||||||
|
"checkThirdParty": false,
|
||||||
"library": [
|
"library": [
|
||||||
"$VIMRUNTIME/lua",
|
"$VIMRUNTIME/lua",
|
||||||
"${3rd}/luv/library",
|
"${3rd}/luv/library",
|
||||||
"./.tests/vendor/plenary.nvim"
|
"./.tests/vendor/plenary.nvim"
|
||||||
]
|
]
|
||||||
}
|
},
|
||||||
|
"diagnostics.disable": [
|
||||||
|
"undefined-field"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
indent_type = "Spaces"
|
||||||
|
indent_width = 2
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
local M = {}
|
||||||
|
|
||||||
|
function M.check()
|
||||||
|
if vim.fn.has("nvim-0.10") == 0 then
|
||||||
|
vim.health.error("Neovim 0.10 or higher is required", { "Please upgrade your Neovim installation to v0.10+" })
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
vim.health.start("watchexec.nvim diagnostics")
|
||||||
|
vim.health.ok("Neovim 0.10+ is installed")
|
||||||
|
|
||||||
|
local bin_path = "watchexec"
|
||||||
|
|
||||||
|
if vim.fn.executable(bin_path) == 1 then
|
||||||
|
vim.health.ok(string.format("Binary '%s' is installed and executable", bin_path))
|
||||||
|
else
|
||||||
|
vim.health.error(string.format("Binary '%s' was not found in PATH", bin_path), {
|
||||||
|
"Install watchexec",
|
||||||
|
"Or verify your plugin configuration if using a custom binary path.",
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
M.config = {
|
M.config = {
|
||||||
greeting = "Hello from my plugin"
|
greeting = "Hello from my plugin",
|
||||||
}
|
}
|
||||||
|
|
||||||
function M.setup(opts)
|
function M.setup(opts)
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
$ErrorActionPreference = "Stop"
|
||||||
|
|
||||||
|
Write-Host "=== Format check ==="
|
||||||
|
stylua --check .
|
||||||
|
|
||||||
|
if ($LASTEXITCODE -ne 0) {
|
||||||
|
Write-Host "FAIL: Format check failed. Run 'stylua .' to fix." -ForegroundColor Red
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "PASS" -ForegroundColor Green
|
||||||
|
|
||||||
|
Write-Host "`n=== Lint ==="
|
||||||
|
|
||||||
|
lua-language-server --check=.
|
||||||
|
|
||||||
|
if ($LASTEXITCODE -ne 0) {
|
||||||
|
Write-Host "FAIL: Lint found issues." -ForegroundColor Red
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "PASS" -ForegroundColor Green
|
||||||
|
|
||||||
|
Write-Host "`n=== Test ==="
|
||||||
|
|
||||||
|
nvim --headless -c "PlenaryBustedDirectory tests/watchexec/ {minimal_init = 'tests/minimal_init.lua'}"
|
||||||
|
|
||||||
|
if ($LASTEXITCODE -ne 0) {
|
||||||
|
Write-Host "FAIL: Tests failed." -ForegroundColor Red
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "PASS" -ForegroundColor Green
|
||||||
|
|
||||||
|
Write-Host "`nAll checks passed!" -ForegroundColor Green
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
local health = require("watchexec.health")
|
||||||
|
local stub = require("luassert.stub")
|
||||||
|
|
||||||
|
describe("watchexec healthcheck", function()
|
||||||
|
local start_stub, ok_stub, error_stub
|
||||||
|
local has_stub, exec_stub
|
||||||
|
|
||||||
|
before_each(function()
|
||||||
|
start_stub = stub(vim.health, "start")
|
||||||
|
ok_stub = stub(vim.health, "ok")
|
||||||
|
error_stub = stub(vim.health, "error")
|
||||||
|
end)
|
||||||
|
|
||||||
|
after_each(function()
|
||||||
|
start_stub:revert()
|
||||||
|
ok_stub:revert()
|
||||||
|
error_stub:revert()
|
||||||
|
|
||||||
|
if has_stub then
|
||||||
|
has_stub:revert()
|
||||||
|
end
|
||||||
|
|
||||||
|
if exec_stub then
|
||||||
|
exec_stub:revert()
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
it("reports all checks as OK when environment is valid", function()
|
||||||
|
has_stub = stub(vim.fn, "has", function()
|
||||||
|
return 1
|
||||||
|
end)
|
||||||
|
exec_stub = stub(vim.fn, "executable", function()
|
||||||
|
return 1
|
||||||
|
end)
|
||||||
|
|
||||||
|
health.check()
|
||||||
|
|
||||||
|
assert.stub(start_stub).was_called_with("watchexec.nvim diagnostics")
|
||||||
|
assert.stub(ok_stub).was_called(2)
|
||||||
|
assert.stub(error_stub).was_called(0)
|
||||||
|
end)
|
||||||
|
|
||||||
|
it("reports an error when watchexec is missing from PATH", function()
|
||||||
|
has_stub = stub(vim.fn, "has", function()
|
||||||
|
return 1
|
||||||
|
end)
|
||||||
|
exec_stub = stub(vim.fn, "executable", function()
|
||||||
|
return 0
|
||||||
|
end)
|
||||||
|
|
||||||
|
health.check()
|
||||||
|
|
||||||
|
assert.stub(ok_stub).was_called(1)
|
||||||
|
assert.stub(error_stub).was_called(1)
|
||||||
|
|
||||||
|
assert.stub(error_stub).was_called_with(
|
||||||
|
"Binary 'watchexec' was not found in PATH",
|
||||||
|
{ "Install watchexec", "Or verify your plugin configuration if using a custom binary path." }
|
||||||
|
)
|
||||||
|
end)
|
||||||
|
|
||||||
|
it("reports an error when using an outdated Neovim version", function()
|
||||||
|
has_stub = stub(vim.fn, "has", function()
|
||||||
|
return 0
|
||||||
|
end)
|
||||||
|
|
||||||
|
health.check()
|
||||||
|
|
||||||
|
assert.stub(start_stub).was_called(0)
|
||||||
|
assert.stub(ok_stub).was_called(0)
|
||||||
|
assert.stub(error_stub).was_called(1)
|
||||||
|
end)
|
||||||
|
end)
|
||||||
@@ -1,17 +1,17 @@
|
|||||||
local plugin = require("watchexec")
|
local plugin = require("watchexec")
|
||||||
|
|
||||||
describe("watchexec logic", function()
|
describe("watchexec logic", function()
|
||||||
before_each(function()
|
before_each(function()
|
||||||
plugin.setup({
|
plugin.setup({
|
||||||
greeting = "Hello Test!"
|
greeting = "Hello Test!",
|
||||||
})
|
})
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("can be required without errors", function()
|
it("can be required without errors", function()
|
||||||
assert.not_nil(plugin)
|
assert.not_nil(plugin)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("correctly applies user configuration", function()
|
it("correctly applies user configuration", function()
|
||||||
assert.equals("Hello Test!", plugin.config.greeting)
|
assert.equals("Hello Test!", plugin.config.greeting)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|||||||
Reference in New Issue
Block a user