Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

golangci-line exit code lost #46

Open
jacobweinstock opened this issue Jun 27, 2022 · 5 comments
Open

golangci-line exit code lost #46

jacobweinstock opened this issue Jun 27, 2022 · 5 comments

Comments

@jacobweinstock
Copy link
Member

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:

@mmlb
Copy link
Contributor

mmlb commented Jun 27, 2022

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?

@jacobweinstock
Copy link
Member Author

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 +.

@jacobweinstock
Copy link
Member Author

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.

@mmlb
Copy link
Contributor

mmlb commented Jun 27, 2022

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

@mmlb
Copy link
Contributor

mmlb commented Jun 27, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants