-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: better git tag -> version fetching (#40)
- Loading branch information
Showing
8 changed files
with
287 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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 @@ | ||
use flake . -Lv |
This file contains 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
This file contains 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 |
---|---|---|
@@ -1 +1,3 @@ | ||
chunks.json | ||
.luarc.json | ||
.direnv |
This file contains 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,12 @@ | ||
globals = { | ||
"_", | ||
"vim", | ||
"describe", | ||
"it", | ||
"assert", | ||
"stub", | ||
} | ||
|
||
ignore = { | ||
"631", -- max_line_length | ||
} |
This file contains 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 @@ | ||
/nix/store/d7najw0l2kxnh56ki6myk5yvqdjj5cml-luarc.json |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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,57 @@ | ||
{ | ||
description = "devShell for Neovim Lua plugins"; | ||
|
||
inputs = { | ||
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; | ||
flake-parts.url = "github:hercules-ci/flake-parts"; | ||
gen-luarc.url = "github:mrcjkb/nix-gen-luarc-json"; | ||
}; | ||
|
||
outputs = inputs @ { | ||
self, | ||
nixpkgs, | ||
flake-parts, | ||
... | ||
}: | ||
flake-parts.lib.mkFlake {inherit inputs;} { | ||
systems = [ | ||
"x86_64-linux" | ||
"x86_64-darwin" | ||
"aarch64-darwin" | ||
]; | ||
perSystem = { | ||
config, | ||
self', | ||
inputs', | ||
pkgs, | ||
system, | ||
... | ||
}: let | ||
pkgs = import nixpkgs { | ||
inherit system; | ||
overlays = [ | ||
inputs.gen-luarc.overlays.default | ||
]; | ||
}; | ||
luarc = pkgs.mk-luarc { | ||
nvim = pkgs.neovim-nightly; | ||
}; | ||
in { | ||
devShells.default = pkgs.mkShell { | ||
name = "NURR devShell"; | ||
shellHook = '' | ||
ln -fs ${pkgs.luarc-to-json luarc} .luarc.json | ||
''; | ||
buildInputs = with pkgs; [ | ||
lua-language-server | ||
stylua | ||
(lua5_1.withPackages (luaPkgs: | ||
with luaPkgs; [ | ||
luarocks | ||
luacheck | ||
])) | ||
]; | ||
}; | ||
}; | ||
}; | ||
} |
This file contains 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,89 @@ | ||
#!/usr/bin/env -S nvim -u NONE -U NONE -N -i NONE -l | ||
|
||
-- Copied over from rocks-git.nvim | ||
|
||
---@param rev string? | ||
---@return boolean | ||
local function is_version(rev) | ||
if not rev then | ||
return false | ||
end | ||
if tonumber(rev) then | ||
return true | ||
end | ||
local version_str = rev:gsub("v", "") | ||
return vim.iter(vim.gsplit(version_str, ".", { plain = true })):all(function(str) | ||
return tonumber(str) ~= nil | ||
end) | ||
end | ||
|
||
---@param rev string? | ||
---@return vim.Version? | ||
local function get_version(rev) | ||
if not is_version(rev) then | ||
return | ||
end | ||
local ok, version = pcall(vim.version.parse, rev) | ||
return ok and version or nil | ||
end | ||
|
||
---@param stdout string | ||
---@return string | nil | ||
local function parse_git_latest_semver_tag(stdout) | ||
local latest_tag = nil | ||
local latest_version = nil | ||
for tag in stdout:gmatch("refs/tags/([^\n]+)") do | ||
local version = get_version(tag) | ||
if version and latest_version then | ||
if version > latest_version then | ||
latest_tag = tag | ||
latest_version = version | ||
end | ||
elseif version then | ||
latest_tag = tag | ||
latest_version = version | ||
end | ||
end | ||
return latest_tag | ||
end | ||
|
||
---@param args string[] git CLI arguments | ||
---@param on_exit fun(sc: vim.SystemCompleted)|nil Called asynchronously when the git command exits. | ||
---@param opts? vim.SystemOpts | ||
---@return vim.SystemObj | nil | ||
---@see vim.system | ||
local function git_cli(args, on_exit, opts) | ||
opts = opts or {} | ||
local git_cmd = vim.list_extend({ | ||
"git", | ||
}, args) | ||
---@type boolean, vim.SystemObj | string | ||
local ok, so_or_err = pcall(vim.system, git_cmd, opts, on_exit) | ||
if ok then | ||
---@cast so_or_err vim.SystemObj | ||
return so_or_err | ||
else | ||
---@cast so_or_err string | ||
---@type vim.SystemCompleted | ||
local sc = { | ||
code = 1, | ||
signal = 0, | ||
stderr = ("Failed to invoke git: %s"):format(so_or_err), | ||
} | ||
if on_exit then | ||
on_exit(sc) | ||
end | ||
end | ||
end | ||
|
||
local function echo_latest_git_tag() | ||
local sc = git_cli({ "for-each-ref", "--format", "%(refname)", "refs/tags" }):wait() | ||
if sc.code == 0 and sc.stdout then | ||
local latest_tag, _ = parse_git_latest_semver_tag(sc.stdout or "") | ||
if latest_tag then | ||
io.write(latest_tag) | ||
end | ||
end | ||
end | ||
|
||
echo_latest_git_tag() |