Closed leighmcculloch closed 4 years ago
As we spoke about in #848, happy to work on a solution for this to make it a bit less manual.
An initial thought I had is to add a git commit hook for any code modifying the 'base' files to automatically (and correctly) run go generate
. That way, commits should automatically have up-to-date versions of the generated files.
Thoughts? @glesica , @leighmcculloch
I saw your message on the PR but I haven't had a chance to retry the process as you described.
I think part of the issue is the generate process being dependent on a GOPATH and with Go Modules disabled. Testify is widely used, but still only runs its CI tests on Go 1.11 as the latest release which is pretty old and no longer supported. Rather than adding a githook I think it probably needs:
go generate
and fails if there are any diffs.As far as I am aware, the travis file is set to use go modules (on and off) as well as the latest golang:
(from .travis.yml
)
include:
- go: "1.8.x"
- go: "1.9.x"
- go: "1.10.x"
- go: "1.11.x"
env: GO111MODULE=off
- go: "1.11.x"
env: GO111MODULE=on
- go: tip
The CI run does do a go generate./...
as part of it (.travis.gogenerate.sh
). The reason that succeeds is because the repo is cloned outside of the $GOPATH
in the travis run if I'm not mistaken.
I do completely agree that this is an issue though; it's very reasonable to expect the community to go get
this repo and work on it from where it is by default ($GOPATH/src
). It would only encourage more collaboration and contributions.
So I think it would make sense to update our tooling to allow a very easy and working 'default-case' experience.
Agreed, if someone can come up with something that works reliably I'd be excited to get it merged and released!
@leighmcculloch , more specifically, to get go generate ./...
working:
rm -rf ./vendor
unset GO111MODULE
go get ./...
Can we throw that in the README or something? If no one else gets to it I'll try to remember to add it.
I just put out a PR (#851), that would make the README.md instructions work correctly.
@boyan-soubachov I've tried to run your instructions with Go 1.13 but I'm hitting the same error. What version of Go are you running those commands on? Could you post a complete example running inside a clean container?
I don't think this is an issue with just my environment either. I'm able to replicate the error using the default Go Dockerfile's with Go 1.11 and Go 1.13:
I also don't think go generate is running on Travis CI. The ./.travis.gogenerate.sh
script that is included in .travis.yml
only runs on Go 1.4 and 1.5 because the script contains this guard:
https://github.com/stretchr/testify/blob/7009337cb5726e58a8444528a492b85d111bc1a5/.travis.gogenerate.sh#L3-L4
@leighmcculloch , good point. I missed that in the .go.generate.sh
script. I'll look into fixing that and make sure it runs on the latest go version.
As for the usual go generate ./...
errors, the cause is explained in more detail in (#851 ). Please let me know if that's not the case for you.
I think I have a fix actually that makes this works for modules, will open a PR if I can wrangle this.
Fix is open in #852. It was pretty gnarly!
The repository uses
go generate ./...
to generate the required and assertion formatter files, but when following the instructions in theREADME.md
and following the example in.travisci.gogenerate.sh
to generate the files with either Go 1.12.13 or 1.13.4, the following errors occur:It looks like this code in the generator that looks up where the code lives is finding the code path incorrectly in these newer versions of Go that support Go modules. The code is located on my system outside a GOPATH.
https://github.com/stretchr/testify/blob/e442a1631a73174a4afde5b4c41ba21cde6f6889/_codegen/main.go#L174-L184
If I try moving the project to my GOPATH, I get a new set of errors: