Skip to content
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

build: rework ci actions #376

Merged
merged 1 commit into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 17 additions & 32 deletions .github/workflows/docgen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,29 @@ on:
- master

jobs:
build-sources:
docgen:
name: Generate docs
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- run: date +%F > todays-date
- name: Restore cache for today's nightly.
uses: actions/cache@v2
with:
path: build
key: ${{ runner.os }}-appimage-${{ hashFiles('todays-date') }}

- name: Prepare
run: |
test -d build || {
mkdir -p build
wget https://github.com/neovim/neovim/releases/download/nightly/nvim.appimage
chmod +x nvim.appimage
mv nvim.appimage ./build/nvim
}
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
git clone --depth 1 https://github.com/tjdevries/tree-sitter-lua ~/.local/share/nvim/site/pack/vendor/start/tree-sitter-lua
ln -s $(pwd) ~/.local/share/nvim/site/pack/vendor/start
- uses: rhysd/action-setup-vim@v1
with:
neovim: true
version: stable

- name: Build parser
run: |
# We have to build the parser every single time to keep up with parser changes
cd ~/.local/share/nvim/site/pack/vendor/start/tree-sitter-lua
make dist
cd -
- uses: actions/cache@v3
with:
path: deps
key: ${{ runner.os }}-deps-${{ matrix.version }}-${{ hashFiles('todays-date') }}
restore-keys: |
${{ runner.os }}-deps-${{ matrix.version }}-
- name: Generating docs
run: |
export PATH="${PWD}/build/:${PATH}"
make docgen
- name: Generating
run: make docgen

# inspired by nvim-lspconfigs
- name: Update documentation
- name: Commit changes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMMIT_MSG: |
Expand All @@ -61,3 +45,4 @@ jobs:
git add doc/
# Only commit and push if we have changes
git diff --quiet && git diff --staged --quiet || (git commit -m "${COMMIT_MSG}"; git push origin HEAD:${GITHUB_REF})
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
name: stylua
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: JohnnyMorganz/stylua-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Tests
on: [push]
jobs:
test:
name: unit tests
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
version: [v0.9.0, nightly]

steps:
- uses: actions/checkout@v4
- run: date +%F > todays-date

- uses: rhysd/action-setup-vim@v1
with:
neovim: true
version: ${{ matrix.version }}

- uses: actions/cache@v3
with:
path: deps
key: ${{ runner.os }}-deps-${{ matrix.version }}-${{ hashFiles('todays-date') }}
restore-keys: |
${{ runner.os }}-deps-${{ matrix.version }}-
- name: Run tests
run: |
nvim --version
make test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
doc/tags
deps/
37 changes: 36 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,37 @@
docgen:
.PHONY: docgen test clean

DEPS_DIR := deps
TS_DIR := $(DEPS_DIR)/tree-sitter-lua
PLENARY_DIR := $(DEPS_DIR)/plenary.nvim
TELESCOPE_DIR := $(DEPS_DIR)/telescope.nvim

define git_clone_or_pull
@mkdir -p $(dir $1)
@if [ ! -d "$1" ]; then \
git clone --depth 1 $2 $1; \
else \
git -C "$1" pull; \
fi
endef

$(DEPS_DIR):
@mkdir -p $@

plenary: | $(DEPS_DIR)
$(call git_clone_or_pull,$(PLENARY_DIR),https://github.com/nvim-lua/plenary.nvim)

docgen-deps: plenary | $(DEPS_DIR)
$(call git_clone_or_pull,$(TS_DIR),https://github.com/tjdevries/tree-sitter-lua)
cd "$(TS_DIR)" && make dist

test-deps: plenary | $(DEPS_DIR)
$(call git_clone_or_pull,$(TELESCOPE_DIR),https://github.com/nvim-telescope/telescope.nvim)

docgen: docgen-deps
nvim --headless --noplugin -u scripts/minimal_init.vim -c "luafile ./scripts/gendocs.lua" -c 'qa'

test: test-deps
nvim --headless --noplugin -u scripts/minimal_init.vim -c "PlenaryBustedDirectory lua/tests/ { minimal_init = './scripts/minimal_init.vim' }"

clean:
@rm -rf $(DEPS_DIR)
2 changes: 1 addition & 1 deletion lua/telescope/_extensions/file_browser/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ local truncate = require("plenary.strings").truncate

local fb_utils = {}

local iswin = vim.loop.os_uname().sysname == "Windows_NT"
fb_utils.iswin = vim.loop.os_uname().sysname == "Windows_NT"

fb_utils.is_dir = function(path)
if Path.is_path(path) then
Expand Down
65 changes: 60 additions & 5 deletions lua/tests/fb_git_spec.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
local fb_git = require "telescope._extensions.file_browser.git"
local git = require "telescope._extensions.file_browser.git"
local utils = require "telescope._extensions.file_browser.utils"

describe("parse_status_output", function()
describe("parse_status_output unix", function()
if utils.iswin then
return
end
local cwd = "/project/root/dir"
it("works in the root dir", function()
local git_status = {
Expand All @@ -15,7 +19,7 @@ describe("parse_status_output", function()
[cwd .. "/lua/telescope/_extensions/file_browser/finders.lua"] = " M",
[cwd .. "/lua/tests/"] = "??",
}
local actual = fb_git.parse_status_output(git_status, cwd)
local actual = git.parse_status_output(git_status, cwd)
assert.are.same(expect, actual)
end)

Expand All @@ -28,7 +32,7 @@ describe("parse_status_output", function()
[cwd .. "/lua/telescope/_extensions/file_browser/finders.lua"] = " M",
[cwd .. "/lua/tests/"] = "??",
}
local actual = fb_git.parse_status_output(git_status, cwd)
local actual = git.parse_status_output(git_status, cwd)
assert.are.same(expect, actual)
end)

Expand All @@ -43,7 +47,58 @@ describe("parse_status_output", function()
[cwd .. "/lua/telescope/_extensions/file_browser/fs_stat.lua"] = "C ",
[cwd .. "/lua/telescope/_extensions/file_browser/make_entry.lua"] = " M",
}
local actual = fb_git.parse_status_output(git_status, cwd)
local actual = git.parse_status_output(git_status, cwd)
assert.are.same(expect, actual)
end)
end)

describe("parse_status_output windows", function()
if not utils.iswin then
return
end
local cwd = "C:\\project\\root\\dir"
it("works in the root dir", function()
local git_status = {
"M .gitignore",
" M README.md",
" M lua\\telescope\\_extensions\\file_browser\\finders.lua",
"?? lua\\tests\\",
}
local expect = {
[cwd .. "\\.gitignore"] = "M ",
[cwd .. "\\README.md"] = " M",
[cwd .. "\\lua\\telescope\\_extensions\\file_browser\\finders.lua"] = " M",
[cwd .. "\\lua\\tests\\"] = "??",
}
local actual = git.parse_status_output(git_status, cwd)
assert.are.same(expect, actual)
end)

it("works in a sub dir", function()
local git_status = {
" M lua\\telescope\\_extensions\\file_browser\\finders.lua",
"?? lua\\tests\\",
}
local expect = {
[cwd .. "\\lua\\telescope\\_extensions\\file_browser\\finders.lua"] = " M",
[cwd .. "\\lua\\tests\\"] = "??",
}
local actual = git.parse_status_output(git_status, cwd)
assert.are.same(expect, actual)
end)

it("parses renamed and copied status", function()
local git_status = {
"R lua\\telescope\\_extensions\\file_browser\\stats.lua -> lua\\telescope\\_extensions\\file_browser\\fs_stat.lua",
"C lua\\telescope\\_extensions\\file_browser\\stats.lua -> lua\\telescope\\_extensions\\file_browser\\fs_stat.lua",
" M lua\\telescope\\_extensions\\file_browser\\make_entry.lua",
}
local expect = {
[cwd .. "\\lua\\telescope\\_extensions\\file_browser\\fs_stat.lua"] = "R ",
[cwd .. "\\lua\\telescope\\_extensions\\file_browser\\fs_stat.lua"] = "C ",
[cwd .. "\\lua\\telescope\\_extensions\\file_browser\\make_entry.lua"] = " M",
}
local actual = git.parse_status_output(git_status, cwd)
assert.are.same(expect, actual)
end)
end)
10 changes: 9 additions & 1 deletion lua/tests/make_entry_spec.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local utils = require "telescope._extensions.file_browser.utils"
local me_utils = require "telescope._extensions.file_browser.make_entry_utils"

describe("get_ordinal_path", function()
Expand All @@ -19,6 +20,13 @@ describe("get_ordinal_path", function()
end)

it("handles duplicate os_sep", function()
assert.are.same("file.txt", me_utils.get_ordinal_path("/home/a/b/c//file.txt", "/home/a/b/c", "/home/a/b"))
if utils.iswin then
assert.are.same(
"file.txt",
me_utils.get_ordinal_path([[C:\\Users\a\b\c\\file.txt]], [[C:\Users\a\b\c]], [[C:\Users\a\b\]])
)
else
assert.are.same("file.txt", me_utils.get_ordinal_path("/home/a/b/c//file.txt", "/home/a/b/c", "/home/a/b"))
end
end)
end)
6 changes: 3 additions & 3 deletions scripts/minimal_init.vim
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
set rtp+=.
set rtp+=../plenary.nvim/
set rtp+=../popup.nvim/
set rtp+=../tree-sitter-lua/
set rtp+=deps/plenary.nvim/
set rtp+=deps/telescope.nvim/
set rtp+=deps/tree-sitter-lua/

runtime! plugin/plenary.vim
Loading