New forks fail to build because of missing dependencies
I think this is occurring because absolute import paths are being used when relative paths may be required, but this issue is pervasive, so I wanted to get some feedback before creating a pull request.
Should the import statements refer to e.g. toxiproxy/stream or just stream (I'm not fluent in Go), rather than github.com/Shopify/toxiproxy/stream? The current imports have the effect of directing Go to look for those packages in the vendor/ directory when a fork builds (see sample Travis log snippet below).
NB I did briefly look at the docs for the tools/godep project, but it appears to be deprecated.
An example is link.go:
package toxiproxy
import (
"io"
"github.com/Shopify/toxiproxy/stream"
"github.com/Shopify/toxiproxy/toxics"
"github.com/sirupsen/logrus"
)
This results in build errors on a fresh fork:
$ godep go build
link.go:6:2: cannot find package "github.com/Shopify/toxiproxy/stream" in any of:
/home/travis/gopath/src/github.com/jimkleine/toxiproxy/vendor/github.com/Shopify/toxiproxy/stream (vendor tree)
/home/travis/.gimme/versions/go1.9.7.linux.amd64/src/github.com/Shopify/toxiproxy/stream (from $GOROOT)
/home/travis/gopath/src/github.com/jimkleine/toxiproxy/Godeps/_workspace/src/github.com/Shopify/toxiproxy/stream (from $GOPATH)
/home/travis/gopath/src/github.com/Shopify/toxiproxy/stream
api.go:12:2: cannot find package "github.com/Shopify/toxiproxy/toxics" in any of:
/home/travis/gopath/src/github.com/jimkleine/toxiproxy/vendor/github.com/Shopify/toxiproxy/toxics (vendor tree)
/home/travis/.gimme/versions/go1.9.7.linux.amd64/src/github.com/Shopify/toxiproxy/toxics (from $GOROOT)
/home/travis/gopath/src/github.com/jimkleine/toxiproxy/Godeps/_workspace/src/github.com/Shopify/toxiproxy/toxics (from $GOPATH)
/home/travis/gopath/src/github.com/Shopify/toxiproxy/toxics
godep: go exit status 1
The command "godep go build" failed and exited with 1 during .
The equivalent Travis build log from the Shopify repo is:
$ godep go build
10.28s$ godep go test ./...
ok github.com/Shopify/toxiproxy 0.579s
? github.com/Shopify/toxiproxy/cli [no test files]
? github.com/Shopify/toxiproxy/client [no test files]
? github.com/Shopify/toxiproxy/cmd [no test files]
ok github.com/Shopify/toxiproxy/stream 0.052s
ok github.com/Shopify/toxiproxy/testhelper 0.010s
ok github.com/Shopify/toxiproxy/testing 0.010s [no tests to run]
ok github.com/Shopify/toxiproxy/toxics 6.507s
The command "godep go test ./..." exited with 0.
Upon researching this further, relative paths are apparently no longer permitted "by design" (since ~v1.1), and I am not the first to note that this approach isn't really sane in a post-GitHub world.
At minimum, this issue probably needs to be documented. One serious implication is that edits to import paths within GitHub forks could "taint" any pull requests originating from forks.
There are some potential workarounds using file system links and/or changes to the GOPATH, but those may not work for e.g. Travis. Modules may also offer some relief: I need to read further.
Some additional references: https://github.com/golang/go/issues/26645#issuecomment-408572701 https://github.com/golang/go/issues/20883 https://stackoverflow.com/questions/38517593/relative-imports-in-go https://scene-si.org/2018/01/25/go-tips-and-tricks-almost-everything-about-imports/
I've logged a support case with Travis to see if they have a documented solution (perhaps via a .travis.yml directive): I'm still awaiting a response.
@ScottMansfield, I've read your blog post addressing this for local repos. Do you have any thoughts on how to resolve this for CI environments?