Go Vendoring and CircleCI

CircleCI is really nice but has some completely fubar’d support for Go. Chief among them, WHY WOULD YOU ADD TWO PATHS TO THE GOPATH? It also has no real support for godeps, glide or any other vendoring in Go 1.5+. Most of the blog posts that you will find on the web are out of date or plain wrong (especially the thoughtbot one).

Here is a simple way to bend CircleCI to build and test your Go project. Let’s start with the simple circle.yml file:

machine:
  environment:
    IMPORT_PATH: "github.com/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME"
    GOOD_PATH: "/home/ubuntu/.go_workspace/src/${IMPORT_PATH}"
  dependencies:
    pre:
      - go get github.com/tools/godep
  override:
    - mkdir -p $GOOD_PATH
    - rsync -azC --delete ./ $GOOD_PATH
test:
  override:
    - cd $GOOD_PATH && make test
    - cd $GOOD_PATH && make build_all

The Machine > environment > section is the key here:

  • Setup a path to where CircleCI places your project code ($IMPORT_PATH)
  • Then a separate path (that is inside the $GOPATH) where you’ll move things to compile ($GOOD_PATH).

After that just add any dependencies that you want (i.e. godep), use the override to copy your source into the $GOOD_PATH. Then just test and build as usual after you’ve cd to $GOOD_PATH before each command. I am using my Makefile here, but if you are using the standard go test you can omit this section.

Now, make sure that your CircleCI project is setup correctly. You need to be using the the Ubuntu 14.04 image, which is tucked away in your project settings menu.

go  golang  cicd 

See also