Skip to content

Commit

Permalink
Add release workflow
Browse files Browse the repository at this point in the history
- adjust test and makefile
- replace deprecated lua nvim calls
  • Loading branch information
frankroeder committed Aug 5, 2024
1 parent 252822b commit 9abe312
Show file tree
Hide file tree
Showing 13 changed files with 77 additions and 44 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Release

on:
push:
tags:
- "v*"

jobs:
github-release:
name: GitHub release
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Release
uses: softprops/action-gh-release@v1
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ jobs:
export PATH="${PWD}/_neovim/bin:${PATH}"
export VIM="${PWD}/_neovim/share/nvim/runtime"
nvim --version
bash run_tests.sh
make test
20 changes: 20 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.PHONY: test testlocal lint format

TESTS_INIT=tests/minimal_init.lua
TESTS_DIR := tests/
PLUGIN_DIR := lua/

MINIMAL_INIT := ./scripts/minimal_init.vim

test:
@nvim \
--headless \
--noplugin \
-u ${TESTS_INIT} \
-c "PlenaryBustedDirectory ${TESTS_DIR} { minimal_init = '${TESTS_INIT}' }"

lint:
luacheck ${PLUGIN_DIR}

format:
stylua -v -f .stylua.toml $$(find $(PWD) -type f -name '*.lua')
1 change: 0 additions & 1 deletion format.sh

This file was deleted.

4 changes: 2 additions & 2 deletions lua/parrot/chat_handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ function ChatHandler:stop(signal)

for _, process_info in self.pool:ipairs() do
if process_info.job.handle ~= nil and not process_info.job.handle:is_closing() then
vim.loop.kill(process_info.job.pid, signal or 15)
vim.uv.kill(process_info.job.pid, signal or 15)
end
end

Expand Down Expand Up @@ -428,7 +428,7 @@ function ChatHandler:_new_chat(params, toggle, chat_prompt)

-- prepare filename
local time = os.date("%Y-%m-%d.%H-%M-%S")
local stamp = tostring(math.floor(vim.loop.hrtime() / 1000000) % 1000)
local stamp = tostring(math.floor(vim.uv.hrtime() / 1000000) % 1000)
local cbuf = vim.api.nvim_get_current_buf()
-- make sure stamp is 3 digits
while #stamp < 3 do
Expand Down
4 changes: 2 additions & 2 deletions lua/parrot/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,11 @@ function M.setup(opts)
M.options.hooks = nil

-- resolve symlinks
local stat = vim.loop.fs_lstat(M.options.chat_dir)
local stat = vim.uv.fs_lstat(M.options.chat_dir)
if stat and stat.type == "link" then
M.options.chat_dir = vim.fn.resolve(M.options.chat_dir)
end
local stat = vim.loop.fs_lstat(M.options.state_dir)
local stat = vim.uv.fs_lstat(M.options.state_dir)
if stat and stat.type == "link" then
M.options.state_dir = vim.fn.resolve(M.options.state_dir)
end
Expand Down
2 changes: 1 addition & 1 deletion lua/parrot/spinner.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function Spinner:start(message)
return
end
self.message = message or ""
self.timer = vim.loop.new_timer()
self.timer = vim.uv.new_timer()
self.timer:start(
0,
self.interval,
Expand Down
36 changes: 21 additions & 15 deletions lua/parrot/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -101,23 +101,29 @@ M.create_popup = function(buf, title, size_func, opts, style)
local pgid = opts.gid or utils.create_augroup("PrtPopup", { clear = true })

-- cleanup on exit
local close = utils.once(function()
vim.schedule(function()
-- delete only internal augroups
if not opts.gid then
vim.api.nvim_del_augroup_by_id(pgid)
end
if win and vim.api.nvim_win_is_valid(win) then
vim.api.nvim_win_close(win, true)
end
if opts.keep_buf then
local close = (function()
local called = false
return function()
if called then
return
end
if vim.api.nvim_buf_is_valid(buf) then
vim.api.nvim_buf_delete(buf, { force = true })
end
end)
end)
called = true
vim.schedule(function()
if not opts.gid then
vim.api.nvim_del_augroup_by_id(pgid)
end
if win and vim.api.nvim_win_is_valid(win) then
vim.api.nvim_win_close(win, true)
end
if opts.keep_buf then
return
end
if vim.api.nvim_buf_is_valid(buf) then
vim.api.nvim_buf_delete(buf, { force = true })
end
end)
end
end)()

-- resize on vim resize
utils.autocmd("VimResized", { buf }, resize, pgid)
Expand Down
3 changes: 1 addition & 2 deletions plugin/parrot.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
for _, name in ipairs({ "curl", "grep", "rg", "ln" }) do
if vim.fn.executable(name) == 0 then
M.logger.error()
return vim.notify(name .. " is not installed, run :checkhealth parrot", vim.log.levels.ERROR)
end
end

local timer = (vim.uv or vim.loop).new_timer()
local timer = vim.uv.new_timer()
timer:start(
500,
0,
Expand Down
2 changes: 0 additions & 2 deletions run_tests.sh

This file was deleted.

5 changes: 0 additions & 5 deletions scripts/minimal_init.vim

This file was deleted.

11 changes: 11 additions & 0 deletions tests/minimal_init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
local plenary_dir = os.getenv("PLENARY_DIR") or "/tmp/plenary.nvim"
local is_not_a_directory = vim.fn.isdirectory(plenary_dir) == 0
if is_not_a_directory then
vim.fn.system({ "git", "clone", "https://github.com/nvim-lua/plenary.nvim", plenary_dir })
end

vim.opt.rtp:append(".")
vim.opt.rtp:append(plenary_dir)

vim.cmd("runtime plugin/plenary.vim")
require("plenary.busted")
13 changes: 0 additions & 13 deletions tests/parrot/utils_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,6 @@ describe("utils", function()
end)
end)

describe("once", function()
it("should only call the function once", function()
local count = 0
local increment = utils.once(function()
count = count + 1
end)
increment()
increment()
increment()
assert.are.equal(1, count)
end)
end)

describe("feedkeys", function()
it("should call vim.api.nvim_feedkeys with correct arguments", function()
local original_nvim_feedkeys = vim.api.nvim_feedkeys
Expand Down

0 comments on commit 9abe312

Please sign in to comment.