diff --git a/.github/workflows/default.yml b/.github/workflows/default.yml index 0593a00..db71802 100644 --- a/.github/workflows/default.yml +++ b/.github/workflows/default.yml @@ -1,22 +1,40 @@ -on: [push, pull_request] +on: [pull_request] name: default env: IMAGE_NAME: nvim-devcontainer-cli jobs: unit-tests: runs-on: ubuntu-latest + strategy: + matrix: + neovim-version: [ + # "v0.9.0", + # "v0.9.1", + # "v0.9.2", + # "v0.9.4", + # "v0.9.5", + # "v0.10.0", + # "v0.10.1", + # "v0.10.2", + # "v0.10.3", + "stable", + ] + fail-fast: false + + name: NEOVIM ${{ matrix.neovim-version }} steps: - name: Checkout - uses: actions/checkout@v3 - - name: Pre-build devcontainer image + uses: actions/checkout@v4 + - name: Pre-build devcontainer image for NEOVIM ${{ matrix.neovim-version }} uses: devcontainers/ci@v0.3 with: - imageName: ${{ env.IMAGE_NAME }} - cacheFrom: ${{ env.IMAGE_NAME }} + imageName: ${{ env.IMAGE_NAME }}-${{ matrix.neovim-version }} + cacheFrom: ${{ env.IMAGE_NAME }}-${{ matrix.neovim-version }} push: never + options: --build-args NEOVIM_VERSION=${{ matrix.neovim-version }} - name: Run tests inside the docker image uses: devcontainers/ci@v0.3 with: - cacheFrom: ${{ env.IMAGE_NAME }} + cacheFrom: ${{ env.IMAGE_NAME }}-${{ matrix.neovim-version }} push: never runCmd: make test diff --git a/Dockerfile b/Dockerfile index fe25a46..9504999 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,15 @@ # Copyright (c) 2024 Erich L Foster -# +# # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies # of the Software, and to permit persons to whom the Software is furnished to do # so, subject to the following conditions: -# +# # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. -# +# # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -18,8 +18,48 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. +ARG NEOVIM_VERSION="stable" FROM ubuntu:22.04 as builder +ARG NEOVIM_VERSION + +# Install dependencies needed for building devcontainers/cli and developing in neovim +RUN apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + apt-utils \ + build-essential \ + curl \ + wget \ + nodejs \ + npm \ + lua5.1 \ + luajit \ + luarocks \ + git \ + # apt clean-up + && apt-get autoremove -y \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /tmp + +# Install NEOVIM +RUN \ + if [ "$NEOVIM_VERSION" = "stable" ]; then \ + curl -fLO https://github.com/neovim/neovim/releases/download/${NEOVIM_VERSION}/nvim-linux-x86_64.tar.gz; \ + else \ + curl -fLO https://github.com/neovim/neovim/releases/download/${NEOVIM_VERSION}/nvim-linux64.tar.gz; \ + fi \ + && rm -rf /opt/nvim \ + && tar -C /opt -xzf nvim-*.tar.gz \ + && ln -s /opt/nvim-*/bin/nvim /usr/local/bin/nvim \ + && chmod u+x /usr/local/bin/nvim + +WORKDIR /app + +# Installing the devcontainers CLI and Lua Dependencies for testing LUA projects +RUN npm install -g @devcontainers/cli@0.49.0 \ + && luarocks install busted + ENV USER_NAME=my-app ARG GROUP_NAME=$USER_NAME ARG USER_ID=1000 @@ -31,37 +71,10 @@ RUN groupadd --gid $GROUP_ID $GROUP_NAME && \ && apt-get update \ && apt-get install -y --no-install-recommends sudo \ && echo $USER_NAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USER_NAME \ - && chmod 0440 /etc/sudoers.d/$USER_NAME + && chmod 0440 /etc/sudoers.d/$USER_NAME # Switch to user USER $USER_NAME -# Install dependencies needed for building devcontainers/cli and developing in neovim -RUN sudo apt-get update && \ - sudo DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ - apt-utils \ - build-essential \ - curl \ - wget \ - nodejs \ - npm \ - lua5.1 \ - luajit \ - luarocks \ - git \ - # apt clean-up - && sudo apt-get autoremove -y \ - && sudo rm -rf /var/lib/apt/lists/* - -ENV NPM_CONFIG_PREFIX=/home/$USER_NAME/.npm-global - -WORKDIR /app - -# Installing the devcontainers CLI -RUN npm install -g @devcontainers/cli@0.49.0 - -# Installing Lua Dependencies for testing LUA projects -RUN sudo luarocks install busted - # this will prevent the .local directory from being owned by root on bind mount RUN mkdir -p /home/$USER_NAME/.local/share/nvim/lazy diff --git a/README.md b/README.md index 8b76bcc..44a759a 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,7 @@ make assumptions about how you work. ## Dependencies +- NeoVim 0.9.0+ - [docker](https://docs.docker.com/get-docker/) - [devcontainer-cli](https://github.com/devcontainers/cli#npm-install) - [toggleterm](https://github.com/akinsho/toggleterm.nvim) @@ -148,12 +149,12 @@ make assumptions about how you work. dotfiles_branch = "devcontainer-cli", -- branch to clone from dotfiles_repository` dotfiles_targetPath = "~/dotfiles", -- location to install dotfiles -- script to run after dotfiles are cloned - dotfiles_intallCommand = "install.sh", + dotfiles_intallCommand = "install.sh", shell = "bash", -- shell to use when executing commands -- The particular binary to use for connecting to in the devcontainer -- Most likely this should remain nvim nvim_binary = "nvim", - -- Set the logging level for console (notifications) and file logging. + -- Set the logging level for console (notifications) and file logging. -- The available levels are trace, debug, info, warn, error, or fatal. -- Set the log level for file logging log_level = "debug", diff --git a/lua/devcontainer-cli/log.lua b/lua/devcontainer-cli/log.lua index cc0428f..cc1eb27 100644 --- a/lua/devcontainer-cli/log.lua +++ b/lua/devcontainer-cli/log.lua @@ -11,7 +11,7 @@ local global_config = require("devcontainer-cli.config") -- User configuration section local default_config = { -- Name of the plugin. Prepended to log messages - plugin = 'decontainer-cli', + plugin = "devcontainer-cli", -- Should print the output to neovim while running use_console = true, @@ -29,12 +29,12 @@ local default_config = { -- Level configuration modes = { - { name = "trace", hl = "Comment", }, - { name = "debug", hl = "Comment", }, - { name = "info", hl = "None", }, - { name = "warn", hl = "WarningMsg", }, - { name = "error", hl = "ErrorMsg", }, - { name = "fatal", hl = "ErrorMsg", }, + { name = "trace", hl = "Comment" }, + { name = "debug", hl = "Comment" }, + { name = "info", hl = "None" }, + { name = "warn", hl = "WarningMsg" }, + { name = "error", hl = "ErrorMsg" }, + { name = "fatal", hl = "ErrorMsg" }, }, -- Can limit the number of decimals displayed for floats @@ -49,7 +49,7 @@ local unpack = unpack or table.unpack log.new = function(config, standalone) config = vim.tbl_deep_extend("force", default_config, config) - local outfile = string.format('%s/%s.log', vim.fn.stdpath("cache"), config.plugin) + local outfile = string.format("%s/%s.log", vim.fn.stdpath("cache"), config.plugin) local obj if standalone then @@ -66,12 +66,12 @@ log.new = function(config, standalone) local round = function(x, increment) increment = increment or 1 x = x / increment - return (x > 0 and math.floor(x + .5) or math.ceil(x - .5)) * increment + return (x > 0 and math.floor(x + 0.5) or math.ceil(x - 0.5)) * increment end local make_string = function(...) local t = {} - for i = 1, select('#', ...) do + for i = 1, select("#", ...) do local x = select(i, ...) if type(x) == "number" and config.float_precision then @@ -87,7 +87,6 @@ log.new = function(config, standalone) return table.concat(t, " ") end - local log_at_level = function(level, level_config, message_maker, ...) local nameupper = level_config.name:upper() @@ -120,13 +119,15 @@ log.new = function(config, standalone) end -- Output to log file - if config.use_file and level >= levels[config.log_level] then - local fp = io.open(outfile, "a") - local str = string.format("[%-6s%s] %s: %s\n", - nameupper, os.date(), lineinfo, msg) - if fp ~= nil then + if config.use_file and level < levels[config.log_level] then + local ok, err = pcall(function() + local fp = assert(io.open(outfile, "a")) + local str = string.format("[%-6s%s] %s: %s\n", nameupper, os.date(), lineinfo, msg) fp:write(str) fp:close() + end) + if not ok then + vim.notify(string.format("Failed to write to log file: %s", err), vim.log.levels.ERROR) end end end @@ -136,9 +137,9 @@ log.new = function(config, standalone) return log_at_level(i, x, make_string, ...) end - obj[("fmt_%s" ):format(x.name)] = function() + obj[("fmt_%s"):format(x.name)] = function() return log_at_level(i, x, function(...) - local passed = {...} + local passed = { ... } local fmt = table.remove(passed, 1) local inspected = {} for _, v in ipairs(passed) do diff --git a/tests/minimal_init.lua b/tests/minimal_init.lua index 141b127..de04ec0 100644 --- a/tests/minimal_init.lua +++ b/tests/minimal_init.lua @@ -1,15 +1,15 @@ -- Copyright (c) 2024 Erich L Foster --- +-- -- Permission is hereby granted, free of charge, to any person obtaining a copy of -- this software and associated documentation files (the "Software"), to deal in -- the Software without restriction, including without limitation the rights to -- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -- of the Software, and to permit persons to whom the Software is furnished to do -- so, subject to the following conditions: --- +-- -- The above copyright notice and this permission notice shall be included in all -- copies or substantial portions of the Software. --- +-- -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -17,11 +17,13 @@ -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -- SOFTWARE. +vim.opt.runtimepath:prepend(vim.fn.stdpath("data") .. "/site") +vim.opt.packpath = vim.opt.runtimepath:get() +-- Your existing plenary setup local plenary_dir = os.getenv("PLENARY_DIR") or "/tmp/plenary.nvim" -local is_not_a_directory = vim.fn.isdirectory(plenary_dir) == 0 -if is_not_a_directory then - vim.fn.system({ "git", "clone", "https://github.com/nvim-lua/plenary.nvim", plenary_dir }) +if vim.fn.isdirectory(plenary_dir) == 0 then + vim.fn.system({ "git", "clone", "--depth=1", "https://github.com/nvim-lua/plenary.nvim", plenary_dir }) end vim.opt.rtp:append(".")