-
Notifications
You must be signed in to change notification settings - Fork 31
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
Add support for Go 1.16 #74
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
started with a typo pass
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Thanks for help. Do you mind if I propose a PR to your PR or send commit? I am playing with it to fix the skipped tests 🤗
Totally! Whatever works best to get Go 1.16 supported. I'm not the most versed in how Go modules work internally, so the approach in this PR may not be the best. Any help is very welcome! |
Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
Small fixes.
Thanks for merging, let's iterate, I will get back to this tomorrow (focusing on book writing today) |
Ok, so now the only test that seems to be failing is the We could try the go mod download as json to resolve the $ go mod download -json github.com/envoyproxy/protoc-gen-validate@d6164de4910977d3c3c8dbd9299b5064ea9e7c2b
{
"Path": "github.com/envoyproxy/protoc-gen-validate",
"Version": "v0.0.15-0.20190405222122-d6164de49109",
"Info": "/Users/nacx/src/go/pkg/mod/cache/download/github.com/envoyproxy/protoc-gen-validate/@v/v0.0.15-0.20190405222122-d6164de49109.info",
"GoMod": "/Users/nacx/src/go/pkg/mod/cache/download/github.com/envoyproxy/protoc-gen-validate/@v/v0.0.15-0.20190405222122-d6164de49109.mod",
"Zip": "/Users/nacx/src/go/pkg/mod/cache/download/github.com/envoyproxy/protoc-gen-validate/@v/v0.0.15-0.20190405222122-d6164de49109.zip",
"Dir": "/Users/nacx/src/go/pkg/mod/github.com/envoyproxy/protoc-gen-validate@v0.0.15-0.20190405222122-d6164de49109",
"Sum": "h1:U1RyeEwqO++6RvIA7bY98AcYIFPQMwrOeWNmw+dvq9w=",
"GoModSum": "h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c="
} For the Thanos one, though, since it is using $ go mod download -json github.com/thanos-io/thanos/cmd/thanos@f85e4003ba51f0592e42c48fdfdf0b800a23ba74
{
"Path": "github.com/thanos-io/thanos/cmd/thanos",
"Version": "f85e4003ba51f0592e42c48fdfdf0b800a23ba74",
"Error": "github.com/thanos-io/thanos/cmd/thanos@v0.0.0-20210108102609-f85e4003ba51: invalid version: missing github.com/thanos-io/thanos/cmd/thanos/go.mod at revision f85e4003ba51"
} Is this something we could use when handling these errors? I haven't found a direct way to get the modules |
Thanks, that sounds like some solution, I can look on it only in few hours. Ideally we don't need to extra calls that's my only worry 🤗 |
I've been playing around with this a bit, and added a commit with an idea. Basically, when the error does not contain any hint about the module version, we can try find it in the local module cache and resolve that version. |
Thanks so much, I got out from meetings so looking on this. I wonder if we can do that by default (: Wil push commit in second. |
I think the fix might be easier then we thought, trying here: #75 (: |
Pushed potential "fix". |
Nope, not yet done (: |
Last standing error is this: https://github.com/golang/go/blob/master/src/cmd/go/internal/modload/query.go#L849 |
Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
Wow. it's so unreliable at this point:
Time for |
Would it be more efficient to walk the local cache as in the latter attempt instead of doing a go mod download? That could save some network calls and be potentially faster? One caveat there is that with that approach, it failed on the |
Yes, that was my worry is that this kind of works, but then we don't know which version "would be" actually chosen by go get, if you have many dirs cached. The only way to know is to... call go mod download again. This is so funky, I wished the internal Go code was not under |
And I think extra network call is not that bad solution - better than nothing 🙃 |
If you are worried by network calls, check -x and what go get is doing ((: (dozen of calls) |
Hmmm Looking at the {
"Path": "github.com/thanos-io/thanos/cmd/thanos",
"Version": "f85e4003ba51f0592e42c48fdfdf0b800a23ba74",
"Error": "github.com/thanos-io/thanos/cmd/thanos@v0.0.0-20210108102609-f85e4003ba51: invalid version: missing github.com/thanos-io/thanos/cmd/thanos/go.mod at revision f85e4003ba51"
} Note that the error message (and the path) refer to the given input (/cmd/thanos) and not to the directory that contains the actual |
Yea I would do the same as I did now: // Since we don't know which part of full path is package, which part is module, start from longest and go until we find one.
for i := len(strings.Split(target.Path(), "/")); i > 3; i-- {
modulePath = filepath.Dir(modulePath)
attempted = append(attempted, fmt.Sprintf(`go: downloading (%v) (\S*)`, modulePath))
re, err = regexp.Compile(attempted[len(attempted)-1])
if err != nil {
return errors.Wrapf(err, "regexp compile %v", attempted[len(attempted)-1])
}
if re.MatchString(gerr.Error()) {
break
}
}
if !re.MatchString(gerr.Error()) {
attempted = append(attempted, `go: (\S*) upgrade => (\S*)`)
re = regexp.MustCompile(attempted[len(attempted)-1])
}
} Just with go mod download. WDYT? |
But then again, this solution is short on one more thing: When you don't specify any version, and if go-get fails then we don't know updated version too sooooo, we need something else. ): |
Thinking out loud now: |
I think that is a solid workaround. Sorry for killing your gomodcache try out - you can recover it from 4cccf28 🤗 |
I think it might not match the go get update logic 1:1 but we can have something very simplified - we could even try to remove |
It's 11pm and I have been working from 9am, so time for me to stop - I will fix this tomorrow if you will not do that earlier. Thanks for help! And btw, we can then remove output matching totally IMO (for all Go versions) |
NP! Let's see if we can make this work :) I have to go AFK now, but I'll give it a try tomorrow if you don't beat me at it (feel free to continue experimenting in this same PR!) |
Ok, focusing on it now, let's go. |
Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
And it's working indeed! Yay! |
Thanks for great idea! Releasing 🤗 |
if lastVersion == "" { | ||
return "", errors.New("empty file") | ||
} | ||
return lastVersion, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I'm not wrong, this returns the last version found in the file, which seems to be how the file is laid out. Given that the semver
library already has functions to compare, is it worth sorting the versions based on semver instead of just returning the last one?
The modules reference does not say anything about how versions are sorted in that file: https://golang.org/ref/mod#module-cache
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm there are those custom versions too (with sha and date). But maybe it follows semver (: Then yes.
In practice what I checked this file is sorted, but you are right it would be better to ensure this just in case as this behavior is not stated anywhere. Let's do in separate PR
Adds support for Go 1.16 by getting rid of the missing go.sum errors:
In Go 1.16 the go-modules behavior changed and it no longer updates the
go.mod
andgo.sum
automatically when building or runninggo list
(https://blog.golang.org/go116-module-changes).To overcome this, in Go >= 1.16 we run
go mod downlaod
to make sure it populates what's missing so thatgo list
andgo build
succeed./cc @codefromthecrypt