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

How to run go generate before the action? #81

Closed
steebchen opened this issue Sep 2, 2020 · 13 comments
Closed

How to run go generate before the action? #81

steebchen opened this issue Sep 2, 2020 · 13 comments
Labels
duplicate This issue or pull request already exists

Comments

@steebchen
Copy link

steebchen commented Sep 2, 2020

I need to run some code generation before executing the action (go generate ./...). How can I do that? It seems it's not possible to do this right now because the action is expected to run without any previous go commands:

/bin/tar: ../../../go/pkg/mod/github.com/takuoki/gocase@v1.0.0/.circleci/config.yml: Cannot open: File exists
61
##[error]/bin/tar: ../../../go/pkg/mod/github.com/takuoki/gocase@v1.0.0/gocase_test.go: Cannot open: File exists
62
/bin/tar: ../../../go/pkg/mod/github.com/takuoki/gocase@v1.0.0/LICENSE: Cannot open: File exists
63
/bin/tar: ../../../go/pkg/mod/github.com/takuoki/gocase@v1.0.0/README.md: Cannot open: File exists
64
##[error]/bin/tar: ../../../go/pkg/mod/github.com/takuoki/gocase@v1.0.0/gocase.go: Cannot open: File exists
65
##[error]/bin/tar: ../../../go/pkg/mod/github.com/takuoki/gocase@v1.0.0/example_test.go: Cannot open: File exists
66
/bin/tar: ../../../go/pkg/mod/github.com/takuoki/gocase@v1.0.0/go.mod: Cannot open: File exists
67
##[error]/bin/tar: ../../../go/pkg/mod/github.com/iancoleman/strcase@v0.0.0-20190422225806-e506e3ef7365/doc.go: Cannot open: File exists
68
##[error]/bin/tar: ../../../go/pkg/mod/github.com/iancoleman/strcase@v0.0.0-20190422225806-e506e3ef7365/camel_test.go: Cannot open: File exists
69
##[error]/bin/tar: ../../../go/pkg/mod/github.com/iancoleman/strcase@v0.0.0-20190422225806-e506e3ef7365/snake_test.go: Cannot open: File exists
70
##[error]/bin/tar: ../../../go/pkg/mod/github.com/iancoleman/strcase@v0.0.0-20190422225806-e506e3ef7365/camel.go: Cannot open: File exists
71
##[error]/bin/tar: ../../../go/pkg/mod/github.com/iancoleman/strcase@v0.0.0-20190422225806-e506e3ef7365/snake.go: Cannot open: File exists
72
/bin/tar: ../../../go/pkg/mod/github.com/iancoleman/strcase@v0.0.0-20190422225806-e506e3ef7365/LICENSE: Cannot open: File exists
73
/bin/tar: ../../../go/pkg/mod/github.com/iancoleman/strcase@v0.0.0-20190422225806-e506e3ef7365/README.md: Cannot open: File exists
74
/bin/tar: ../../../go/pkg/mod/github.com/iancoleman/strcase@v0.0.0-20190422225806-e506e3ef7365/.travis.yml: Cannot open: File exists
75
##[error]/bin/tar: ../../../go/pkg/mod/github.com/iancoleman/strcase@v0.0.0-20190422225806-e506e3ef7365/numbers.go: Cannot open: File exists

It seems the action itself works, but the errors don't look very good

@sayboras
Copy link
Member

@steebchen without going much to details, but I think you can just simply run go generate as part of github action job before running golangci-lint-action. If I am not wrong, golangci-lint expects the compilable codebase to execute properly.

@sayboras sayboras added the question Further information is requested label Oct 18, 2020
@steebchen
Copy link
Author

steebchen commented Oct 18, 2020

Yeah, if I recall correctly, I think that worked – but as I said above, you get bombarded with those error messages. And if you have a lot of dependencies it will spam your logs. I've see a few tens of thousands of lines just filled with those errors since it logs one line per file. So something is wrong with the cache restoration, even though it works in general. Which makes sense, since it probably doesn't expect something modified when restoring the cache. So I would personally classify this more as a bug report or feature request to make go generator work without running into this stream of errors and making the cache restoration work.

@sayboras
Copy link
Member

sayboras commented Oct 18, 2020

I've see a few tens of thousands of lines just filled with those errors since it logs one line per file

So I would personally classify this more as a bug report or feature request to make go generator work without running into this stream of errors and making the cache restoration work.

I still feel this is the result of un-compilable codebase, but not the issue with caching or golangci-lint. Maybe related to golangci/golangci-lint#1043 🤔

Personally, I follow alternative approach, which checks in generated file and verifies in github action with go generate again + git diff --exit-code. One benefit is that codebase is compilable right after clone. It's just style thingy I think.

@steebchen
Copy link
Author

steebchen commented Oct 18, 2020

I still feel this is the result of un-compilable codebase

I'm not sure if I follow. Everything works as intended, the code complies (after go generate is run) and it properly detects errors and fails if there are any, just the cache restoration does not work and results in these errors.

I do need to run go generate on each checkout since I don't commit generated code into VCS, but I think that's a perfectly valid workflow.

@sayboras
Copy link
Member

sayboras commented Oct 19, 2020

hi, what I mean is just fresh clone + go build directly. Thinking about this, I feel like I might have pre-mature assumption, sorry about this. Let me try with your repo some time this week to understand the flow properly 🤔

PS: Seem like the original error messages might not have repo name, can you share or confirm if it's public repo ?

@steebchen
Copy link
Author

You can use the repo https://github.com/prisma/prisma-client-go. I'm currently using the raw golangci-lint binary instead of this action and use the github cache action myself.

However, I have created steebchen/prisma-client-go#276 to re-create the error; you should be able to inspect the logs from the action there. You can see that the latest test run logs are spammed with error logs since the log restoration didn't work.

It's maybe not the best repo to create a reproduction since it does quite a lot of things. In theory any repo which changes the code on go generate should reproduce the error.

@torbjornvatn
Copy link

@sayboras I get the same type of error when I try to use actions/cache before the linting action, so does this guy #135
I took at stab at fixing this by adding a disable-caching parameter over in my fork here, but it didn't work. To me it looks like it's the calls that this action makes to setup-go that causes the /bin/tar errors, but I couldn't really figure out what it was.

@andig
Copy link

andig commented Dec 4, 2020

Would be great to fix the /bin/tar errors. Even if they don't hurt the functionality it makes finding the actual lint output in the GHA ui hard.

@bailejl
Copy link

bailejl commented Dec 24, 2020

I had the same error using Bazel to generate protobufs. By moving this generation work to another job in the same action file and making golangci-lint job dependent on it with the needs tag, I was able to get around the issue. Hope this helps someone.

@steebchen
Copy link
Author

steebchen commented Jan 19, 2021

yeah I guess this is a duplicate of #81 #135, except that the other issue describes the actual problem more clearly

@andig
Copy link

andig commented Jan 19, 2021

This is #81?

@steebchen
Copy link
Author

whoops, thanks. I meant #135

@ldez
Copy link
Member

ldez commented Jun 24, 2023

duplicated of #135

@ldez ldez closed this as completed Jun 24, 2023
@ldez ldez added duplicate This issue or pull request already exists and removed question Further information is requested labels Jun 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

6 participants