CircleCI is ignoring the vendor directory with Go (Golang) v1.7

For some reason, even though I’ve checked the Go version and Circle is running v1.7, for some reason the build is completely ignoring the /vendor/ directory when looking for dependencies.

There error I’m seeing is simply that the packages don’t exist (when they clearly have been checked into git)

main.go:12:2: cannot find package "github.com/gorilla/mux" in any of:
	/usr/local/go/src/github.com/gorilla/mux (from $GOROOT)
	/home/ubuntu/MYPROJECT/Godeps/_workspace/src/github.com/gorilla/mux (from $GOPATH)
	/home/ubuntu/.go_workspace/src/github.com/gorilla/mux
	/usr/local/go_workspace/src/github.com/gorilla/mux
	/home/ubuntu/.go_project/src/github.com/gorilla/mux

Here is my circle.yml file:


machine:
  environment:
    # GOROOT is not set by default
    GOROOT: ""
    PATH: "/usr/local/go/bin:/usr/local/go_workspace/bin:~/.go_workspace/bin:${PATH}"
    GOPATH: "${HOME}/.go_workspace:/usr/local/go_workspace:${HOME}/.go_project"

dependencies:
    pre: 
    - go get github.com/tools/godep
  override:
    - mkdir -p ~/.go_project/src/github.com/${CIRCLE_PROJECT_USERNAME}
    - ln -s ${HOME}/${CIRCLE_PROJECT_REPONAME} ${HOME}/.go_project/src/github.com/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}

test:
  pre:
    - go vet ./...
  override:
    # './...' is a relative pattern which means all subdirectories
    - godep go test ./...

How can I get this to work? The whole idea of these builds is to replicate environments so I don’t want to rely on go get-ing the dependencies.

I’ve ran the same thing with just go test ./... and it doesn’t check the /vendor/ packages either for the dependencies. This is odd, because as of Go 1.6, the actual “lookup paths” are, in order:

./vendor
$GOPATH/src
$GOROOT/src

Because it’s Go 1.7, the environment variable to set vendor experiment is no longer in place. It is default behaviour (https://golang.org/doc/go1.6#go_command)

Long story short, I have no idea why Circle is ignoring my vendor directory it starts the tests. Neither the normal go test command nor godep go test are checking the vendor directory even though they do on every other machine I’ve tested.

Hmm it appears for some reason that running godep go test ./... is checking MYPROJECT/Godeps/_workspace for some reason when it should be checking /MYPROJECT/vendor/.

Is it that Circle is somehow not using the master branch of Godep when I install it in the Circle container?

Here’s what finally worked for me. Really should be supported with documentation somewhere.

machine:
  environment:
    # GOROOT is not set by default
    GOROOT: ""
    GOPATH: "${HOME}/.go_project"
    PATH: "${GOPATH}/bin:${PATH}"
    BUILD_PATH: "${GOPATH}/src/github.com/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}"

dependencies:
  pre:
    - go get github.com/tools/godep

  override:
    - mkdir -p ~/.go_project/src/github.com/${CIRCLE_PROJECT_USERNAME}
    - ln -s ${HOME}/${CIRCLE_PROJECT_REPONAME} ${BUILD_PATH}

test:
  pre:
    - cd $BUILD_PATH && go vet $(go list ./... | grep -v /vendor/)
  override:
    - cd $BUILD_PATH && godep go test -v -race $(go list ./... | grep -v /vendor/)