ci(lintcommit): fix error output

Using print() alone doesn't work properly, toggling the verbose option
is still required.
This commit is contained in:
dundargoc 2023-04-22 17:37:45 +02:00 committed by GitHub
parent 732cb9e1e0
commit ccce200cde
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 14 deletions

View File

@ -16,4 +16,4 @@ jobs:
- uses: rhysd/action-setup-vim@v1
with:
neovim: true
- run: nvim --clean -l scripts/lintcommit.lua main --notrace
- run: nvim --clean -l scripts/lintcommit.lua main

View File

@ -259,9 +259,7 @@ add_glob_target(
TOUCH_STRATEGY SINGLE)
add_custom_target(lintcommit
COMMAND ${PROJECT_BINARY_DIR}/bin/nvim -u NONE -l scripts/lintcommit.lua main --notrace
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
VERBATIM)
COMMAND $<TARGET_FILE:nvim> -u NONE -l ${PROJECT_SOURCE_DIR}/scripts/lintcommit.lua main)
add_dependencies(lintcommit nvim)
add_custom_target(lint)

View File

@ -1,9 +1,9 @@
-- Usage:
-- # verbose
-- nvim -l scripts/lintcommit.lua main
-- nvim -l scripts/lintcommit.lua main --trace
--
-- # silent
-- nvim -l scripts/lintcommit.lua main --notrace
-- nvim -l scripts/lintcommit.lua main
--
-- # self-test
-- nvim -l scripts/lintcommit.lua _test
@ -13,17 +13,24 @@ local M = {}
local _trace = false
-- Print message
local function p(s)
vim.cmd('set verbose=1')
vim.api.nvim_echo({{s, ''}}, false, {})
vim.cmd('set verbose=0')
end
-- Executes and returns the output of `cmd`, or nil on failure.
--
-- Prints `cmd` if `trace` is enabled.
local function run(cmd, or_die)
if _trace then
print('run: '..vim.inspect(cmd))
p('run: '..vim.inspect(cmd))
end
local rv = vim.trim(vim.fn.system(cmd)) or ''
if vim.v.shell_error ~= 0 then
if or_die then
print(rv)
p(rv)
os.exit(1)
end
return nil
@ -161,7 +168,7 @@ function M.main(opt)
for _, commit_id in ipairs(commits) do
local msg = run({'git', 'show', '-s', '--format=%s' , commit_id})
if vim.v.shell_error ~= 0 then
print('Invalid commit-id: '..commit_id..'"')
p('Invalid commit-id: '..commit_id..'"')
else
local invalid_msg = validate_commit(msg)
if invalid_msg then
@ -169,10 +176,10 @@ function M.main(opt)
-- Some breathing room
if failed == 1 then
print('\n')
p('\n')
end
print(string.format([[
p(string.format([[
Invalid commit message: "%s"
Commit: %s
%s
@ -185,13 +192,14 @@ Invalid commit message: "%s"
end
if failed > 0 then
print([[
p([[
See also:
https://github.com/neovim/neovim/blob/master/CONTRIBUTING.md#commit-messages
]])
os.exit(1)
else
print('')
p('')
end
end
@ -252,7 +260,7 @@ function M._test()
local is_valid = (nil == validate_commit(message))
if is_valid ~= expected then
failed = failed + 1
print(string.format('[ FAIL ]: expected=%s, got=%s\n input: "%s"', expected, is_valid, message))
p(string.format('[ FAIL ]: expected=%s, got=%s\n input: "%s"', expected, is_valid, message))
end
end