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

build: pass mod vendoring flag on newer versions of go #2142

Merged
merged 2 commits into from
Jun 17, 2019

Conversation

eli-schwartz
Copy link
Contributor

When go autodetects that it is being run as a go mod, and that there is a vendor directory, it will still try to redownload all sources over the network, unless you use -mod=vendor to tell it to use that. Additionally, when using -mod=vendor the compiler will nicely avoid messing with $GOPATH at all, since it can operate in a completely self-contained manner.

Take advantage of this, when the detected go version is at least 1.11 (when the -mod flag was introduced).

@eli-schwartz
Copy link
Contributor Author

BTW the use of modules is super nifty and with its use, plus this, I can now remove a bunch of golang hacks from my distro packaging. Thanks!

@eli-schwartz
Copy link
Contributor Author

Ok -- this is entirely magical, everything errors out with "build flag -mod=vendor only valid when using modules" -- but it is using modules??? And it works on my machine and not in travis.

Copy link
Owner

@mislav mislav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this! I have no idea why CI fails. Maybe it's still set up to go with the GOPATH-based approach?

script/build Outdated Show resolved Hide resolved
When go autodetects that it is being run as a go mod, and that there is
a vendor directory, it will still try to redownload all sources over the
network, unless you use -mod=vendor to tell it to use that. Additionally,
when using -mod=vendor the compiler will nicely avoid messing with
$GOPATH at all, since it can operate in a completely self-contained
manner.

Take advantage of this, when the detected go version is at least 1.11
(when the -mod flag was introduced).
@eli-schwartz
Copy link
Contributor Author

eli-schwartz commented Jun 16, 2019

OK -- that (temporary commit adding bash -x debugging) mostly just told me what I already knew...

But local testing helped me figure out something else, which is that make will also fail locally for me... iff I set $GOPATH, and the hub repository is cloned to the $GOPATH. Simply building the repository with an externally defined $GOPATH is not sufficient to trigger this issue.

It seems that Travis' language support will clone the repository to /home/travis/gopath/src/github.com/github/hub, at which point this fails. Forcing -mod=vendor for a build in which you are cded to $GOPATH is apparently not something the go tools support.

Thoughts on fixing this?

@mislav
Copy link
Owner

mislav commented Jun 17, 2019

@eli-schwartz Thanks for digging into! Maybe we can clear GOPATH before running the build script in Travis? That way, even if the repo was initially cloned to GOPATH, with the environment variable being unset, it might cease to interfere with the module-based approach.

You are welcome to tweak .travis.yml in this PR and see if it helps. Thank you!

The go compiler doesn't like it when you mix the two, and Travis CI does
exactly that. Take advantage of the opportunity to disable it everywhere
else as well.
@eli-schwartz
Copy link
Contributor Author

I made that change in the Makefile itself. CI is now green.

@mislav mislav merged commit 936f704 into mislav:master Jun 17, 2019
@mislav
Copy link
Owner

mislav commented Jun 17, 2019

Thank you! 🙇

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

Successfully merging this pull request may close these issues.

2 participants