mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 11:28:22 +00:00
ci(lintcommit): fix error output
Using print() alone doesn't work properly, toggling the verbose option is still required.
This commit is contained in:
2
.github/workflows/lintcommit.yml
vendored
2
.github/workflows/lintcommit.yml
vendored
@@ -16,4 +16,4 @@ jobs:
|
|||||||
- uses: rhysd/action-setup-vim@v1
|
- uses: rhysd/action-setup-vim@v1
|
||||||
with:
|
with:
|
||||||
neovim: true
|
neovim: true
|
||||||
- run: nvim --clean -l scripts/lintcommit.lua main --notrace
|
- run: nvim --clean -l scripts/lintcommit.lua main
|
||||||
|
@@ -259,9 +259,7 @@ add_glob_target(
|
|||||||
TOUCH_STRATEGY SINGLE)
|
TOUCH_STRATEGY SINGLE)
|
||||||
|
|
||||||
add_custom_target(lintcommit
|
add_custom_target(lintcommit
|
||||||
COMMAND ${PROJECT_BINARY_DIR}/bin/nvim -u NONE -l scripts/lintcommit.lua main --notrace
|
COMMAND $<TARGET_FILE:nvim> -u NONE -l ${PROJECT_SOURCE_DIR}/scripts/lintcommit.lua main)
|
||||||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
|
||||||
VERBATIM)
|
|
||||||
add_dependencies(lintcommit nvim)
|
add_dependencies(lintcommit nvim)
|
||||||
|
|
||||||
add_custom_target(lint)
|
add_custom_target(lint)
|
||||||
|
@@ -1,9 +1,9 @@
|
|||||||
-- Usage:
|
-- Usage:
|
||||||
-- # verbose
|
-- # verbose
|
||||||
-- nvim -l scripts/lintcommit.lua main
|
-- nvim -l scripts/lintcommit.lua main --trace
|
||||||
--
|
--
|
||||||
-- # silent
|
-- # silent
|
||||||
-- nvim -l scripts/lintcommit.lua main --notrace
|
-- nvim -l scripts/lintcommit.lua main
|
||||||
--
|
--
|
||||||
-- # self-test
|
-- # self-test
|
||||||
-- nvim -l scripts/lintcommit.lua _test
|
-- nvim -l scripts/lintcommit.lua _test
|
||||||
@@ -13,17 +13,24 @@ local M = {}
|
|||||||
|
|
||||||
local _trace = false
|
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.
|
-- Executes and returns the output of `cmd`, or nil on failure.
|
||||||
--
|
--
|
||||||
-- Prints `cmd` if `trace` is enabled.
|
-- Prints `cmd` if `trace` is enabled.
|
||||||
local function run(cmd, or_die)
|
local function run(cmd, or_die)
|
||||||
if _trace then
|
if _trace then
|
||||||
print('run: '..vim.inspect(cmd))
|
p('run: '..vim.inspect(cmd))
|
||||||
end
|
end
|
||||||
local rv = vim.trim(vim.fn.system(cmd)) or ''
|
local rv = vim.trim(vim.fn.system(cmd)) or ''
|
||||||
if vim.v.shell_error ~= 0 then
|
if vim.v.shell_error ~= 0 then
|
||||||
if or_die then
|
if or_die then
|
||||||
print(rv)
|
p(rv)
|
||||||
os.exit(1)
|
os.exit(1)
|
||||||
end
|
end
|
||||||
return nil
|
return nil
|
||||||
@@ -161,7 +168,7 @@ function M.main(opt)
|
|||||||
for _, commit_id in ipairs(commits) do
|
for _, commit_id in ipairs(commits) do
|
||||||
local msg = run({'git', 'show', '-s', '--format=%s' , commit_id})
|
local msg = run({'git', 'show', '-s', '--format=%s' , commit_id})
|
||||||
if vim.v.shell_error ~= 0 then
|
if vim.v.shell_error ~= 0 then
|
||||||
print('Invalid commit-id: '..commit_id..'"')
|
p('Invalid commit-id: '..commit_id..'"')
|
||||||
else
|
else
|
||||||
local invalid_msg = validate_commit(msg)
|
local invalid_msg = validate_commit(msg)
|
||||||
if invalid_msg then
|
if invalid_msg then
|
||||||
@@ -169,10 +176,10 @@ function M.main(opt)
|
|||||||
|
|
||||||
-- Some breathing room
|
-- Some breathing room
|
||||||
if failed == 1 then
|
if failed == 1 then
|
||||||
print('\n')
|
p('\n')
|
||||||
end
|
end
|
||||||
|
|
||||||
print(string.format([[
|
p(string.format([[
|
||||||
Invalid commit message: "%s"
|
Invalid commit message: "%s"
|
||||||
Commit: %s
|
Commit: %s
|
||||||
%s
|
%s
|
||||||
@@ -185,13 +192,14 @@ Invalid commit message: "%s"
|
|||||||
end
|
end
|
||||||
|
|
||||||
if failed > 0 then
|
if failed > 0 then
|
||||||
print([[
|
p([[
|
||||||
See also:
|
See also:
|
||||||
https://github.com/neovim/neovim/blob/master/CONTRIBUTING.md#commit-messages
|
https://github.com/neovim/neovim/blob/master/CONTRIBUTING.md#commit-messages
|
||||||
|
|
||||||
]])
|
]])
|
||||||
os.exit(1)
|
os.exit(1)
|
||||||
else
|
else
|
||||||
print('')
|
p('')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -252,7 +260,7 @@ function M._test()
|
|||||||
local is_valid = (nil == validate_commit(message))
|
local is_valid = (nil == validate_commit(message))
|
||||||
if is_valid ~= expected then
|
if is_valid ~= expected then
|
||||||
failed = failed + 1
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user