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" PLUGINS="$HOME/.local/share/nvim/site/pack/plugins/start"
mkdir -p "$PLUGINS" 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 chmod +x nvim.appimage
./nvim.appimage --appimage-extract >/dev/null ./nvim.appimage --appimage-extract >/dev/null
rm -f nvim.appimage rm -f nvim.appimage

View File

@ -1,6 +1,12 @@
name: Run tests name: Run tests
on: [push, pull_request] on:
push:
branches:
- master
pull_request:
branches:
- master
jobs: jobs:
luacheck: luacheck:
@ -17,7 +23,7 @@ jobs:
sudo luarocks install luacheck sudo luarocks install luacheck
- name: Run Luacheck - name: Run Luacheck
run: luacheck . run: luacheck lua tests
stylua: stylua:
name: StyLua name: StyLua
@ -29,7 +35,7 @@ jobs:
with: with:
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.GITHUB_TOKEN }}
version: v0.15.2 version: v0.15.2
args: --check . args: --check lua tests
typecheck: typecheck:
name: typecheck name: typecheck
@ -60,6 +66,35 @@ jobs:
run: | run: |
bash ./run_tests.sh 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: release:
name: release name: release
@ -69,6 +104,7 @@ jobs:
- stylua - stylua
- typecheck - typecheck
- run_tests - run_tests
- update_docs
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: google-github-actions/release-please-action@v3 - 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 *.x86_64
*.hex *.hex
.direnv/
.testenv/ .testenv/
doc/tags 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: want to tweak, call this function:
```lua ```lua
require('dressing').setup({ require("dressing").setup({
input = { input = {
-- Set to false to disable the vim.ui.input implementation -- Set to false to disable the vim.ui.input implementation
enabled = true, enabled = true,

View File

@ -4,7 +4,7 @@
CONFIGURATION *dressing-configuration* CONFIGURATION *dressing-configuration*
Configure dressing.nvim by calling the setup() function. Configure dressing.nvim by calling the setup() function.
> >lua
require('dressing').setup({ require('dressing').setup({
input = { input = {
-- Set to false to disable the vim.ui.input implementation -- Set to false to disable the vim.ui.input implementation
@ -178,7 +178,7 @@ dressing.get_config() *dressing_get_config()
module. module.
For example, if you want to use a specific configuration for code actions: For example, if you want to use a specific configuration for code actions:
> >lua
require('dressing').setup({ require('dressing').setup({
select = { select = {
get_config = function(opts) 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 "format_item" function when selecting for that kind. For example, this
configuration will display the name of the language server next to code configuration will display the name of the language server next to code
actions: actions:
> >lua
format_item_override = { format_item_override = {
codeaction = function(action_tuple) codeaction = function(action_tuple)
local title = action_tuple[2].title:gsub("\r\n", "\\r\\n") 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()