From fc26d39d0550ff50fd890184709ceb490c4c09d5 Mon Sep 17 00:00:00 2001 From: Liam Woodleigh-Hardinge Date: Thu, 4 Jul 2024 14:10:32 +0200 Subject: [PATCH] ci: Improve nvim & treesitter setup in CI --- .config/nvim/init.lua | 51 ++++++++++++++++++++++++++++++++ .github/workflows/queries-ci.yml | 16 ++++++---- scripts/ci-install.sh | 26 ++++++++++++++++ 3 files changed, 88 insertions(+), 5 deletions(-) create mode 100644 .config/nvim/init.lua create mode 100644 scripts/ci-install.sh diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua new file mode 100644 index 0000000..b5547aa --- /dev/null +++ b/.config/nvim/init.lua @@ -0,0 +1,51 @@ +-- Bootstrap lazy.nvim +local lazypath = vim.fn.stdpath "data" .. "/lazy/lazy.nvim" +if not (vim.uv or vim.loop).fs_stat(lazypath) then + local lazyrepo = "https://github.com/folke/lazy.nvim.git" + local out = vim.fn.system { "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath } + if vim.v.shell_error ~= 0 then + vim.api.nvim_echo({ + { "Failed to clone lazy.nvim:\n", "ErrorMsg" }, + { out, "WarningMsg" }, + { "\nPress any key to exit..." }, + }, true, {}) + vim.fn.getchar() + os.exit(1) + end +end +vim.opt.rtp:prepend(lazypath) + +-- Make sure to setup `mapleader` and `maplocalleader` before +-- loading lazy.nvim so that mappings are correct. +-- This is also a good place to setup other settings (vim.opt) +vim.g.mapleader = " " +vim.g.maplocalleader = "\\" + +-- Setup lazy.nvim +require("lazy").setup { + spec = { + -- add your plugins here + }, + -- Configure any other settings here. See the documentation for more details. + -- colorscheme that will be used when installing plugins. + install = { colorscheme = { "habamax" } }, + -- automatically check for plugin updates + checker = { enabled = true }, +} + +require("lazy").setup { + { + "nvim-treesitter/nvim-treesitter", + build = ":TSUpdate", + config = function() + local configs = require "nvim-treesitter.configs" + + configs.setup { + ensure_installed = { "c", "lua", "vim", "vimdoc", "query", "elixir", "heex", "javascript", "html" }, + sync_install = false, + highlight = { enable = true }, + indent = { enable = true }, + } + end, + }, +} diff --git a/.github/workflows/queries-ci.yml b/.github/workflows/queries-ci.yml index 08af3b0..9f44859 100644 --- a/.github/workflows/queries-ci.yml +++ b/.github/workflows/queries-ci.yml @@ -45,15 +45,21 @@ jobs: format-queries: name: Lint queries runs-on: ubuntu-latest + env: + NVIM_TAG: stable steps: - uses: actions/checkout@v4 - - name: Prepare + + - name: Setup nvim and Treesitter + run: | + bash ./scripts/ci-install.sh + + - name: Copy nvim config to ensure nvim-treesitter is installed run: | - wget https://github.com/neovim/neovim/releases/download/nightly/nvim-linux64.tar.gz - tar -zxf nvim-linux64.tar.gz - sudo ln -s "$PWD"/nvim-linux64/bin/nvim /usr/local/bin + cp -r ./.config/nvim ~/.config/nvim - - name: Lint Queries + - name: Lint run: | + nvim --headless -c "TSInstallSync query" -c "q" nvim -l scripts/format-queries.lua git diff --exit-code diff --git a/scripts/ci-install.sh b/scripts/ci-install.sh new file mode 100644 index 0000000..d1b565e --- /dev/null +++ b/scripts/ci-install.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +set -e + +os=$(uname -s) +if [[ $os == Linux ]]; then + wget https://github.com/neovim/neovim/releases/download/${NVIM_TAG}/nvim-linux64.tar.gz + tar -zxf nvim-linux64.tar.gz + sudo ln -s "$PWD"/nvim-linux64/bin/nvim /usr/local/bin + rm -rf "$PWD"/nvim-linux64/lib/nvim/parser + mkdir -p ~/.local/share/nvim/site/pack/nvim-treesitter/start + ln -s "$PWD" ~/.local/share/nvim/site/pack/nvim-treesitter/start +elif [[ $os == Darwin ]]; then + RELEASE_NAME="nvim-macos-$(uname -m)" + curl -L "https://github.com/neovim/neovim/releases/download/${NVIM_TAG}/$RELEASE_NAME.tar.gz" | tar -xz + sudo ln -s "$PWD/$RELEASE_NAME/bin/nvim" /usr/local/bin + rm -rf "$PWD/$RELEASE_NAME/lib/nvim/parser" + mkdir -p ~/.local/share/nvim/site/pack/nvim-treesitter/start + ln -s "$PWD" ~/.local/share/nvim/site/pack/nvim-treesitter/start +else + curl -L https://github.com/neovim/neovim/releases/download/${NVIM_TAG}/nvim-win64.zip -o nvim-win64.zip + unzip nvim-win64 + mkdir -p ~/AppData/Local/nvim/pack/nvim-treesitter/start + mkdir -p ~/AppData/Local/nvim-data + cp -r "$PWD" ~/AppData/Local/nvim/pack/nvim-treesitter/start +fi