-
-
Save mikeatlas/3f21d8d64b8c9217c7d3 to your computer and use it in GitHub Desktop.
# See docs/examples | |
# http://doc.gitlab.com/ce/ci/quick_start/README.html | |
# http://doc.gitlab.com/ce/ci/yaml/README.html | |
# GitLab CI template for Go tests. Note this installs | |
# a new working copy of Go in a non-standard path such | |
# that sudo/root is not needed for the install stage. | |
# note that this particular install-environment stage | |
# is overly verbose in order to debug anything tricky | |
# or weird in your environment - feel free to trim it | |
# down as needed | |
stages: | |
- install-environment | |
- build | |
- test | |
install-go: | |
stage: install-environment | |
script: | |
- export CURRENT_BUILD_PATH=$(pwd) | |
- echo $PATH | |
- rm -rf $HOME/golang | |
- rm -rf $HOME/gopath | |
- mkdir -p $HOME/golang # for GOROOT (contains the Go binary & core packages) | |
- mkdir -p $HOME/gopath # for GOPATH (contains code and external packages) | |
- curl http://storage.googleapis.com/golang/go1.5.2.linux-amd64.tar.gz 2>/dev/null > go1.5.2.linux-amd64.tar.gz | |
- tar -C $HOME/golang -xzf go1.5.2.linux-amd64.tar.gz | |
- export GOROOT=$HOME/golang/go | |
- export GOPATH=$HOME/gopath | |
- export PATH=$PATH:$GOROOT/bin | |
- export PATH=$PATH:$GOPATH/bin | |
- (if [[ "$(go version)" == *"go version go1.5"* ]]; then echo "✓ Go binary installed!"; else echo "Go binary not installed"; exit -1; fi); | |
- go version | |
- echo $PATH | |
- go env | |
- which go | |
build-my-project: | |
stage: build | |
script: | |
- cd $CURRENT_BUILD_PATH | |
- go build | |
test-my-project: | |
stage: test | |
script: | |
- cd $CURRENT_BUILD_PATH | |
- go test |
@Lorac @odunboye try this, I'm still trying to get deploy to work with it but it at least runs the tests.
https://gist.github.com/jcloutz/a9831d60aefb5e6ca29fd7848a230467
This is what I have for using go 1.8 and go dep. Dep requires to have a somewhat valid go path:
image: golang:1.8
stages:
- test
- build
before_script:
- go get -u github.com/golang/dep/cmd/dep
- export GOPATH=$(dirname $CI_PROJECT_DIR)/go
- mkdir -p $GOPATH/src
- cd $GOPATH/src
- ln -s $CI_PROJECT_DIR
- cd $CI_PROJECT_NAME
- dep ensure -update
test:
stage: test
script:
- go test
build:
stage: build
script:
- go build
If the issue is installing go, I would recommend you to build an image in a different pipeline and push it to a registry and then just use it. Else, it feels like your ci build is getting much more complicated than necessary.
Building on the answer from @pcarranza, I simplified the script a little. The fiddling around with the go path did not work for me. Also dep
does not download the vendor
directory any longer when the update
command is passed in, so I removed this as well:
image: golang:1.10
stages:
- test
- build
before_script:
- go get -u github.com/golang/dep/cmd/dep
- mkdir -p $GOPATH/src
- cd $GOPATH/src
- ln -s $CI_PROJECT_DIR
- cd $CI_PROJECT_NAME
- dep ensure
test:
stage: test
script:
- go test
build:
stage: build
script:
- go build
I'm using a similar setup, but I would really love to use caching to save the vendor folder between jobs. Has anybody achieved this? I run multiple jobs in my test stage (test, bench, coverage, etc.) and try to run a cache warmup stage at first.
How to use dep cache for gitlab ci.
the runners change when pipeline gets to the next stages causing failure for build and test (can not find go command), is there any fix to this?