golangci-line exit code lost
Opened this issue · 5 comments
This repo uses the find
command to execute golangci-lint
in the top level directory. As a side affect of this I believe this swallows the exit code from the actual golangci-lint
command. This makes it impossible to use lint-install
in CI where a non-zero exit code should fail a build.
❯ make lint
find . -name go.mod -execdir "out/linters/golangci-lint-v1.46.2-x86_64" run -c "" \;
otel/otel.go:229:1: exported: exported method Encoder.EncodeFILE should have comment or be unexported (revive)
func (e *Encoder) EncodeFILE(d *dhcpv4.DHCPv4, namespace string) error {
^
❯ echo $?
0
Same golanglint-ci
command run on its own:
❯ out/linters/golangci-lint-v1.46.2-x86_64 run -c ""
otel/otel.go:229:1: exported: exported method Encoder.EncodeFILE should have comment or be unexported (revive)
func (e *Encoder) EncodeFILE(d *dhcpv4.DHCPv4, namespace string) error {
^
❯ echo $?
1
Expected Behaviour
Current Behaviour
Possible Solution
Steps to Reproduce (for bugs)
Context
Your Environment
-
Operating System and version (e.g. Linux, Windows, MacOS):
-
How are you running Tinkerbell? Using Vagrant & VirtualBox, Vagrant & Libvirt, on Packet using Terraform, or give details:
-
Link to your project or a code example to reproduce issue:
I'm able to reproduce this. Reading the find
docs on my linux box it states that using the +
form does not swallow the exit code. Can you modify lint-install.go and give that a try?
hmmm....i must be reading something different. https://man7.org/linux/man-pages/man1/find.1.html:
"-execdir command {} + always returns true,
while -execdir command {} ; returns true only if command
returns 0."
Also, I can't get the command to work when i use {}
and/or +
.
Also, it seems the way the find command is used is just to execute the golangci-lint
in a specific directory and not to actually find files. So using {}
wouldn't make sense.
Hmm I was going off of a couple sentences before that line:
If any invocation with the `+' form returns a non-zero value as exit status, then find returns a non-zero exit status.
And verified using the following experiment:
14:28 ~/go/src/github.com/tinkerbell/lint-install $ find . -name go.mod -execdir sh -c 'exit 1' '{}' '+'
14:28 ~/go/src/github.com/tinkerbell/lint-install $ echo $?
1
find is used to find the go.mod files (there may be many in a repo, in subdirs for e.g.) and then runs golangci-lint run from within that dir https://github.com/mistifyio/go-zfs/ is an example repo.