Skip to content

Commit 50a1c6f

Browse files
authored
Merge pull request #27 from erichlf/logger_fixes
- **Bug Fixes** - Enhanced logging behavior with improved error notifications and refined log entry conditions. - **New Features** - Introduced a configurable Neovim version for a more efficient build and dependency installation process. - Added NeoVim 0.9.0 as a new dependency. - **Tests** - Updated the automated workflow to run tests with a single Neovim version and trigger on pull requests only. - **Documentation** - Minor formatting adjustments in comments for clarity in the README.
2 parents bee227c + d94478e commit 50a1c6f

File tree

5 files changed

+98
-63
lines changed

5 files changed

+98
-63
lines changed

.github/workflows/default.yml

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,40 @@
1-
on: [push, pull_request]
1+
on: [pull_request]
22
name: default
33
env:
44
IMAGE_NAME: nvim-devcontainer-cli
55
jobs:
66
unit-tests:
77
runs-on: ubuntu-latest
8+
strategy:
9+
matrix:
10+
neovim-version: [
11+
# "v0.9.0",
12+
# "v0.9.1",
13+
# "v0.9.2",
14+
# "v0.9.4",
15+
# "v0.9.5",
16+
# "v0.10.0",
17+
# "v0.10.1",
18+
# "v0.10.2",
19+
# "v0.10.3",
20+
"stable",
21+
]
22+
fail-fast: false
23+
24+
name: NEOVIM ${{ matrix.neovim-version }}
825
steps:
926
- name: Checkout
10-
uses: actions/checkout@v3
11-
- name: Pre-build devcontainer image
27+
uses: actions/checkout@v4
28+
- name: Pre-build devcontainer image for NEOVIM ${{ matrix.neovim-version }}
1229
uses: devcontainers/ci@v0.3
1330
with:
14-
imageName: ${{ env.IMAGE_NAME }}
15-
cacheFrom: ${{ env.IMAGE_NAME }}
31+
imageName: ${{ env.IMAGE_NAME }}-${{ matrix.neovim-version }}
32+
cacheFrom: ${{ env.IMAGE_NAME }}-${{ matrix.neovim-version }}
1633
push: never
34+
options: --build-args NEOVIM_VERSION=${{ matrix.neovim-version }}
1735
- name: Run tests inside the docker image
1836
uses: devcontainers/ci@v0.3
1937
with:
20-
cacheFrom: ${{ env.IMAGE_NAME }}
38+
cacheFrom: ${{ env.IMAGE_NAME }}-${{ matrix.neovim-version }}
2139
push: never
2240
runCmd: make test

Dockerfile

Lines changed: 44 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# Copyright (c) 2024 Erich L Foster
2-
#
2+
#
33
# Permission is hereby granted, free of charge, to any person obtaining a copy of
44
# this software and associated documentation files (the "Software"), to deal in
55
# the Software without restriction, including without limitation the rights to
66
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
77
# of the Software, and to permit persons to whom the Software is furnished to do
88
# so, subject to the following conditions:
9-
#
9+
#
1010
# The above copyright notice and this permission notice shall be included in all
1111
# copies or substantial portions of the Software.
12-
#
12+
#
1313
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1414
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1515
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -18,8 +18,48 @@
1818
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
# SOFTWARE.
2020

21+
ARG NEOVIM_VERSION="stable"
2122
FROM ubuntu:22.04 as builder
2223

24+
ARG NEOVIM_VERSION
25+
26+
# Install dependencies needed for building devcontainers/cli and developing in neovim
27+
RUN apt-get update && \
28+
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
29+
apt-utils \
30+
build-essential \
31+
curl \
32+
wget \
33+
nodejs \
34+
npm \
35+
lua5.1 \
36+
luajit \
37+
luarocks \
38+
git \
39+
# apt clean-up
40+
&& apt-get autoremove -y \
41+
&& rm -rf /var/lib/apt/lists/*
42+
43+
WORKDIR /tmp
44+
45+
# Install NEOVIM
46+
RUN \
47+
if [ "$NEOVIM_VERSION" = "stable" ]; then \
48+
curl -fLO https://github.com/neovim/neovim/releases/download/${NEOVIM_VERSION}/nvim-linux-x86_64.tar.gz; \
49+
else \
50+
curl -fLO https://github.com/neovim/neovim/releases/download/${NEOVIM_VERSION}/nvim-linux64.tar.gz; \
51+
fi \
52+
&& rm -rf /opt/nvim \
53+
&& tar -C /opt -xzf nvim-*.tar.gz \
54+
&& ln -s /opt/nvim-*/bin/nvim /usr/local/bin/nvim \
55+
&& chmod u+x /usr/local/bin/nvim
56+
57+
WORKDIR /app
58+
59+
# Installing the devcontainers CLI and Lua Dependencies for testing LUA projects
60+
RUN npm install -g @devcontainers/cli@0.49.0 \
61+
&& luarocks install busted
62+
2363
ENV USER_NAME=my-app
2464
ARG GROUP_NAME=$USER_NAME
2565
ARG USER_ID=1000
@@ -31,37 +71,10 @@ RUN groupadd --gid $GROUP_ID $GROUP_NAME && \
3171
&& apt-get update \
3272
&& apt-get install -y --no-install-recommends sudo \
3373
&& echo $USER_NAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USER_NAME \
34-
&& chmod 0440 /etc/sudoers.d/$USER_NAME
74+
&& chmod 0440 /etc/sudoers.d/$USER_NAME
3575

3676
# Switch to user
3777
USER $USER_NAME
3878

39-
# Install dependencies needed for building devcontainers/cli and developing in neovim
40-
RUN sudo apt-get update && \
41-
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
42-
apt-utils \
43-
build-essential \
44-
curl \
45-
wget \
46-
nodejs \
47-
npm \
48-
lua5.1 \
49-
luajit \
50-
luarocks \
51-
git \
52-
# apt clean-up
53-
&& sudo apt-get autoremove -y \
54-
&& sudo rm -rf /var/lib/apt/lists/*
55-
56-
ENV NPM_CONFIG_PREFIX=/home/$USER_NAME/.npm-global
57-
58-
WORKDIR /app
59-
60-
# Installing the devcontainers CLI
61-
RUN npm install -g @devcontainers/cli@0.49.0
62-
63-
# Installing Lua Dependencies for testing LUA projects
64-
RUN sudo luarocks install busted
65-
6679
# this will prevent the .local directory from being owned by root on bind mount
6780
RUN mkdir -p /home/$USER_NAME/.local/share/nvim/lazy

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ make assumptions about how you work.
8080

8181
## Dependencies
8282

83+
- NeoVim 0.9.0+
8384
- [docker](https://docs.docker.com/get-docker/)
8485
- [devcontainer-cli](https://github.com/devcontainers/cli#npm-install)
8586
- [toggleterm](https://github.com/akinsho/toggleterm.nvim)
@@ -148,12 +149,12 @@ make assumptions about how you work.
148149
dotfiles_branch = "devcontainer-cli", -- branch to clone from dotfiles_repository`
149150
dotfiles_targetPath = "~/dotfiles", -- location to install dotfiles
150151
-- script to run after dotfiles are cloned
151-
dotfiles_intallCommand = "install.sh",
152+
dotfiles_intallCommand = "install.sh",
152153
shell = "bash", -- shell to use when executing commands
153154
-- The particular binary to use for connecting to in the devcontainer
154155
-- Most likely this should remain nvim
155156
nvim_binary = "nvim",
156-
-- Set the logging level for console (notifications) and file logging.
157+
-- Set the logging level for console (notifications) and file logging.
157158
-- The available levels are trace, debug, info, warn, error, or fatal.
158159
-- Set the log level for file logging
159160
log_level = "debug",

lua/devcontainer-cli/log.lua

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ local global_config = require("devcontainer-cli.config")
1111
-- User configuration section
1212
local default_config = {
1313
-- Name of the plugin. Prepended to log messages
14-
plugin = 'decontainer-cli',
14+
plugin = "devcontainer-cli",
1515

1616
-- Should print the output to neovim while running
1717
use_console = true,
@@ -29,12 +29,12 @@ local default_config = {
2929

3030
-- Level configuration
3131
modes = {
32-
{ name = "trace", hl = "Comment", },
33-
{ name = "debug", hl = "Comment", },
34-
{ name = "info", hl = "None", },
35-
{ name = "warn", hl = "WarningMsg", },
36-
{ name = "error", hl = "ErrorMsg", },
37-
{ name = "fatal", hl = "ErrorMsg", },
32+
{ name = "trace", hl = "Comment" },
33+
{ name = "debug", hl = "Comment" },
34+
{ name = "info", hl = "None" },
35+
{ name = "warn", hl = "WarningMsg" },
36+
{ name = "error", hl = "ErrorMsg" },
37+
{ name = "fatal", hl = "ErrorMsg" },
3838
},
3939

4040
-- Can limit the number of decimals displayed for floats
@@ -49,7 +49,7 @@ local unpack = unpack or table.unpack
4949
log.new = function(config, standalone)
5050
config = vim.tbl_deep_extend("force", default_config, config)
5151

52-
local outfile = string.format('%s/%s.log', vim.fn.stdpath("cache"), config.plugin)
52+
local outfile = string.format("%s/%s.log", vim.fn.stdpath("cache"), config.plugin)
5353

5454
local obj
5555
if standalone then
@@ -66,12 +66,12 @@ log.new = function(config, standalone)
6666
local round = function(x, increment)
6767
increment = increment or 1
6868
x = x / increment
69-
return (x > 0 and math.floor(x + .5) or math.ceil(x - .5)) * increment
69+
return (x > 0 and math.floor(x + 0.5) or math.ceil(x - 0.5)) * increment
7070
end
7171

7272
local make_string = function(...)
7373
local t = {}
74-
for i = 1, select('#', ...) do
74+
for i = 1, select("#", ...) do
7575
local x = select(i, ...)
7676

7777
if type(x) == "number" and config.float_precision then
@@ -87,7 +87,6 @@ log.new = function(config, standalone)
8787
return table.concat(t, " ")
8888
end
8989

90-
9190
local log_at_level = function(level, level_config, message_maker, ...)
9291
local nameupper = level_config.name:upper()
9392

@@ -120,13 +119,15 @@ log.new = function(config, standalone)
120119
end
121120

122121
-- Output to log file
123-
if config.use_file and level >= levels[config.log_level] then
124-
local fp = io.open(outfile, "a")
125-
local str = string.format("[%-6s%s] %s: %s\n",
126-
nameupper, os.date(), lineinfo, msg)
127-
if fp ~= nil then
122+
if config.use_file and level < levels[config.log_level] then
123+
local ok, err = pcall(function()
124+
local fp = assert(io.open(outfile, "a"))
125+
local str = string.format("[%-6s%s] %s: %s\n", nameupper, os.date(), lineinfo, msg)
128126
fp:write(str)
129127
fp:close()
128+
end)
129+
if not ok then
130+
vim.notify(string.format("Failed to write to log file: %s", err), vim.log.levels.ERROR)
130131
end
131132
end
132133
end
@@ -136,9 +137,9 @@ log.new = function(config, standalone)
136137
return log_at_level(i, x, make_string, ...)
137138
end
138139

139-
obj[("fmt_%s" ):format(x.name)] = function()
140+
obj[("fmt_%s"):format(x.name)] = function()
140141
return log_at_level(i, x, function(...)
141-
local passed = {...}
142+
local passed = { ... }
142143
local fmt = table.remove(passed, 1)
143144
local inspected = {}
144145
for _, v in ipairs(passed) do

tests/minimal_init.lua

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
11
-- Copyright (c) 2024 Erich L Foster
2-
--
2+
--
33
-- Permission is hereby granted, free of charge, to any person obtaining a copy of
44
-- this software and associated documentation files (the "Software"), to deal in
55
-- the Software without restriction, including without limitation the rights to
66
-- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
77
-- of the Software, and to permit persons to whom the Software is furnished to do
88
-- so, subject to the following conditions:
9-
--
9+
--
1010
-- The above copyright notice and this permission notice shall be included in all
1111
-- copies or substantial portions of the Software.
12-
--
12+
--
1313
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1414
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1515
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1616
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1717
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1818
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
-- SOFTWARE.
20+
vim.opt.runtimepath:prepend(vim.fn.stdpath("data") .. "/site")
21+
vim.opt.packpath = vim.opt.runtimepath:get()
2022

23+
-- Your existing plenary setup
2124
local plenary_dir = os.getenv("PLENARY_DIR") or "/tmp/plenary.nvim"
22-
local is_not_a_directory = vim.fn.isdirectory(plenary_dir) == 0
23-
if is_not_a_directory then
24-
vim.fn.system({ "git", "clone", "https://github.com/nvim-lua/plenary.nvim", plenary_dir })
25+
if vim.fn.isdirectory(plenary_dir) == 0 then
26+
vim.fn.system({ "git", "clone", "--depth=1", "https://github.com/nvim-lua/plenary.nvim", plenary_dir })
2527
end
2628

2729
vim.opt.rtp:append(".")

0 commit comments

Comments
 (0)