ci: merge workflows and add makefile

This commit is contained in:
Steven Arcangeli 2023-09-02 08:57:46 -07:00
parent c7b035de7f
commit b1c7b70e1e
11 changed files with 173 additions and 148 deletions

11
.github/pre-push vendored Executable file
View File

@ -0,0 +1,11 @@
#!/bin/bash
set -e
IFS=' '
while read local_ref _local_sha _remote_ref _remote_sha; do
remote_main=$( (git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null || echo "///master") | cut -f 4 -d / | tr -d "[:space:]")
local_ref_short=$(echo "$local_ref" | cut -f 3 -d / | tr -d "[:space:]")
if [ "$local_ref_short" = "$remote_main" ]; then
make lint
make test
fi
done

View File

@ -1,92 +0,0 @@
#!/usr/bin/env python
import os
import os.path
import re
from typing import List
HERE = os.path.dirname(__file__)
ROOT = os.path.abspath(os.path.join(HERE, os.path.pardir))
README = os.path.join(ROOT, "README.md")
DOC = os.path.join(ROOT, "doc", "dressing.txt")
def indent(lines: List[str], amount: int) -> List[str]:
ret = []
for line in lines:
if amount >= 0:
ret.append(" " * amount + line)
else:
space = re.match(r"[ \t]+", line)
if space:
ret.append(line[min(abs(amount), space.span()[1]) :])
else:
ret.append(line)
return ret
def replace_section(file: str, start_pat: str, end_pat: str, lines: List[str]) -> None:
prefix_lines: List[str] = []
postfix_lines: List[str] = []
file_lines = prefix_lines
found_section = False
with open(file, "r", encoding="utf-8") as ifile:
inside_section = False
for line in ifile:
if inside_section:
if re.match(end_pat, line):
inside_section = False
file_lines = postfix_lines
file_lines.append(line)
else:
if not found_section and re.match(start_pat, line):
inside_section = True
found_section = True
file_lines.append(line)
if inside_section or not found_section:
raise Exception(f"could not find file section {start_pat}")
all_lines = prefix_lines + lines + postfix_lines
with open(file, "w", encoding="utf-8") as ofile:
ofile.write("".join(all_lines))
def read_section(filename: str, start_pat: str, end_pat: str) -> List[str]:
lines = []
with open(filename, "r", encoding="utf-8") as ifile:
inside_section = False
for line in ifile:
if inside_section:
if re.match(end_pat, line):
break
lines.append(line)
elif re.match(start_pat, line):
inside_section = True
return lines
def main() -> None:
"""Update the README"""
config_file = os.path.join(ROOT, "lua", "dressing", "config.lua")
opt_lines = read_section(config_file, r"^\s*local default_config =", r"^}$")
replace_section(README, r"^require\('dressing'\)\.setup", r"^}\)$", opt_lines)
replace_section(
DOC, r"^\s*require\('dressing'\)\.setup", r"^\s*}\)$", indent(opt_lines, 4)
)
get_config_lines = read_section(DOC, r"^dressing.get_config", "^===")
for i, line in enumerate(get_config_lines):
if re.match(r"^\s*>$", line):
get_config_lines[i] = "\n```lua\n"
break
get_config_lines.append("```\n\n")
replace_section(
README,
r"^## Advanced configuration",
r"^#",
["\n"] + indent(get_config_lines, -4),
)
if __name__ == "__main__":
main()

View File

@ -3,7 +3,7 @@ set -e
PLUGINS="$HOME/.local/share/nvim/site/pack/plugins/start"
mkdir -p "$PLUGINS"
wget https://github.com/neovim/neovim/releases/download/${NVIM_TAG}/nvim.appimage
wget https://github.com/neovim/neovim/releases/download/${NVIM_TAG-stable}/nvim.appimage
chmod +x nvim.appimage
./nvim.appimage --appimage-extract >/dev/null
rm -f nvim.appimage

View File

@ -1,6 +1,12 @@
name: Run tests
on: [push, pull_request]
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
luacheck:
@ -17,7 +23,7 @@ jobs:
sudo luarocks install luacheck
- name: Run Luacheck
run: luacheck .
run: luacheck lua tests
stylua:
name: StyLua
@ -29,7 +35,7 @@ jobs:
with:
token: ${{ secrets.GITHUB_TOKEN }}
version: v0.15.2
args: --check .
args: --check lua tests
typecheck:
name: typecheck
@ -60,6 +66,35 @@ jobs:
run: |
bash ./run_tests.sh
update_docs:
name: Update docs
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- name: Install Neovim and dependencies
run: |
bash ./.github/workflows/install_nvim.sh
- name: Update docs
run: |
python -m pip install pyparsing==3.0.9
make doc
- name: Commit changes
if: ${{ github.ref == 'refs/heads/master' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMMIT_MSG: |
[docgen] Update docs
skip-checks: true
run: |
git config user.email "actions@github"
git config user.name "Github Actions"
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git
git add README.md 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})
release:
name: release
@ -69,6 +104,7 @@ jobs:
- stylua
- typecheck
- run_tests
- update_docs
runs-on: ubuntu-latest
steps:
- uses: google-github-actions/release-please-action@v3

View File

@ -1,25 +0,0 @@
name: Update README
on: push
jobs:
update-readme:
name: Update README
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- name: Update README
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMMIT_MSG: |
[docgen] Update README.md
skip-checks: true
run: |
git config user.email "actions@github"
git config user.name "Github Actions"
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git
python .github/update_readme.py
git add README.md doc/dressing.txt
# 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})

3
.gitignore vendored
View File

@ -39,5 +39,8 @@ luac.out
*.x86_64
*.hex
.direnv/
.testenv/
doc/tags
scripts/nvim_doc_tools
scripts/nvim-typecheck-action

27
Makefile Normal file
View File

@ -0,0 +1,27 @@
.PHONY: all doc test lint fastlint clean
all: doc lint test
doc: scripts/nvim_doc_tools
python scripts/main.py generate
python scripts/main.py lint
test:
./run_tests.sh
lint: scripts/nvim-typecheck-action fastlint
./scripts/nvim-typecheck-action/typecheck.sh --workdir scripts/nvim-typecheck-action lua
fastlint: scripts/nvim_doc_tools
python scripts/main.py lint
luacheck lua tests --formatter plain
stylua --check lua tests
scripts/nvim_doc_tools:
git clone https://github.com/stevearc/nvim_doc_tools scripts/nvim_doc_tools
scripts/nvim-typecheck-action:
git clone https://github.com/stevearc/nvim-typecheck-action scripts/nvim-typecheck-action
clean:
rm -rf scripts/nvim_doc_tools scripts/nvim-typecheck-action

View File

@ -127,7 +127,7 @@ If you're fine with the defaults, you're good to go after installation. If you
want to tweak, call this function:
```lua
require('dressing').setup({
require("dressing").setup({
input = {
-- Set to false to disable the vim.ui.input implementation
enabled = true,

View File

@ -4,29 +4,29 @@
CONFIGURATION *dressing-configuration*
Configure dressing.nvim by calling the setup() function.
>
>lua
require('dressing').setup({
input = {
-- Set to false to disable the vim.ui.input implementation
enabled = true,
-- Default prompt string
default_prompt = "Input:",
-- Can be 'left', 'right', or 'center'
title_pos = "left",
-- When true, <Esc> will close the modal
insert_only = true,
-- When true, input will start in insert mode.
start_in_insert = true,
-- These are passed to nvim_open_win
border = "rounded",
-- 'editor' and 'win' will default to being centered
relative = "cursor",
-- These can be integers or a float between 0 and 1 (e.g. 0.4 for 40%)
prefer_width = 40,
width = nil,
@ -34,7 +34,7 @@ Configure dressing.nvim by calling the setup() function.
-- min_width = {20, 0.2} means "the greater of 20 columns or 20% of total"
max_width = { 140, 0.9 },
min_width = { 20, 0.2 },
buf_options = {},
win_options = {
-- Window transparency (0-100)
@ -47,7 +47,7 @@ Configure dressing.nvim by calling the setup() function.
-- Increase this for more context when text scrolls off the window
sidescrolloff = 0,
},
-- Set to `false` to disable
mappings = {
n = {
@ -61,31 +61,31 @@ Configure dressing.nvim by calling the setup() function.
["<Down>"] = "HistoryNext",
},
},
override = function(conf)
-- This is the config that will be passed to nvim_open_win.
-- Change values here to customize the layout
return conf
end,
-- see :help dressing_get_config
get_config = nil,
},
select = {
-- Set to false to disable the vim.ui.select implementation
enabled = true,
-- Priority list of preferred vim.select implementations
backend = { "telescope", "fzf_lua", "fzf", "builtin", "nui" },
-- Trim trailing `:` from prompt
trim_prompt = true,
-- Options for telescope selector
-- These are passed into the telescope picker directly. Can be used like:
-- telescope = require('telescope.themes').get_ivy({...})
telescope = nil,
-- Options for fzf selector
fzf = {
window = {
@ -93,7 +93,7 @@ Configure dressing.nvim by calling the setup() function.
height = 0.4,
},
},
-- Options for fzf-lua
fzf_lua = {
-- winopts = {
@ -101,7 +101,7 @@ Configure dressing.nvim by calling the setup() function.
-- width = 0.5,
-- },
},
-- Options for nui Menu
nui = {
position = "50%",
@ -122,14 +122,14 @@ Configure dressing.nvim by calling the setup() function.
min_width = 40,
min_height = 10,
},
-- Options for built-in selector
builtin = {
-- These are passed to nvim_open_win
border = "rounded",
-- 'editor' and 'win' will default to being centered
relative = "editor",
buf_options = {},
win_options = {
-- Window transparency (0-100)
@ -137,7 +137,7 @@ Configure dressing.nvim by calling the setup() function.
cursorline = true,
cursorlineopt = "both",
},
-- These can be integers or a float between 0 and 1 (e.g. 0.4 for 40%)
-- the min_ and max_ options can be a list of mixed types.
-- max_width = {140, 0.8} means "the lesser of 140 columns or 80% of total"
@ -147,24 +147,24 @@ Configure dressing.nvim by calling the setup() function.
height = nil,
max_height = 0.9,
min_height = { 10, 0.2 },
-- Set to `false` to disable
mappings = {
["<Esc>"] = "Close",
["<C-c>"] = "Close",
["<CR>"] = "Confirm",
},
override = function(conf)
-- This is the config that will be passed to nvim_open_win.
-- Change values here to customize the layout
return conf
end,
},
-- Used to override format_item. See :help dressing-format
format_item_override = {},
-- see :help dressing_get_config
get_config = nil,
},
@ -178,7 +178,7 @@ dressing.get_config() *dressing_get_config()
module.
For example, if you want to use a specific configuration for code actions:
>
>lua
require('dressing').setup({
select = {
get_config = function(opts)
@ -204,7 +204,7 @@ use kind="codeaction"). You can, in turn, specify an override for the
"format_item" function when selecting for that kind. For example, this
configuration will display the name of the language server next to code
actions:
>
>lua
format_item_override = {
codeaction = function(action_tuple)
local title = action_tuple[2].title:gsub("\r\n", "\\r\\n")

34
scripts/generate.py Executable file
View File

@ -0,0 +1,34 @@
#!/usr/bin/env python
import os
import os.path
import re
from nvim_doc_tools import indent, read_section, replace_section
HERE = os.path.dirname(__file__)
ROOT = os.path.abspath(os.path.join(HERE, os.path.pardir))
README = os.path.join(ROOT, "README.md")
DOC = os.path.join(ROOT, "doc", "dressing.txt")
CONFIG = os.path.join(ROOT, "lua", "dressing", "config.lua")
def main() -> None:
"""Update the README"""
opt_lines = read_section(CONFIG, r"^\s*local default_config =", r"^}$")
replace_section(README, r"^require\(\"dressing\"\)\.setup", r"^}\)$", opt_lines)
replace_section(
DOC, r"^\s*require\('dressing'\)\.setup", r"^\s*}\)$", indent(opt_lines, 4)
)
get_config_lines = read_section(DOC, r"^dressing.get_config", "^===")
for i, line in enumerate(get_config_lines):
if re.match(r"^\s*>lua$", line):
get_config_lines[i] = "\n```lua\n"
break
get_config_lines.append("```\n\n")
replace_section(
README,
r"^## Advanced configuration",
r"^#",
["\n"] + indent(get_config_lines, -4),
)

31
scripts/main.py Executable file
View File

@ -0,0 +1,31 @@
#!/usr/bin/env python
import argparse
import os
import sys
HERE = os.path.dirname(__file__)
ROOT = os.path.abspath(os.path.join(HERE, os.path.pardir))
DOC = os.path.join(ROOT, "doc")
def main() -> None:
"""Generate docs"""
sys.path.append(HERE)
parser = argparse.ArgumentParser(description=main.__doc__)
parser.add_argument("command", choices=["generate", "lint"])
args = parser.parse_args()
if args.command == "generate":
import generate
generate.main()
elif args.command == "lint":
from nvim_doc_tools import lint_md_links
files = [os.path.join(ROOT, "README.md")] + [
os.path.join(DOC, file) for file in os.listdir(DOC) if file.endswith(".md")
]
lint_md_links.main(ROOT, files)
if __name__ == "__main__":
main()