Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recommended Go build system for a CI server?

Tags:

go

So I have a go project with go-gettable dependencies, tests, etc.

I want to integrate it into Jenkins. Is there an automated build system for go that anyone recommends for this use case, other than writing makefiles?

I need:

  1. automatic installation of go-get deps (they can be in a spec file of course)
  2. recursive build.
  3. running tests.
  4. GOPATH/GOROOT management (to isolate SDKs and paths)

I've used godag in the past for this sort of job but it seems a bit unmaintained.

EDIT: For the time being I'm living with the following script entered directly into Jenkins as a build step:

#this gets the dependencies but doesn't install them, avoiding permission problems
go get -d

#build the packages, -x outputs the compiler command line
go build -x

#this was tricky - ./... means "for each sub-package recursively"
go test ./... 
like image 433
Not_a_Golfer Avatar asked Jan 15 '14 10:01

Not_a_Golfer


2 Answers

You can do it with teamcity as well.

Here is an example for building terraform.

Teamcity agent setup:

  • Install Go
  • Add Go to path
  • Don't forget to restart agent as path was changed

Teamcity build setup:

  • Use agent side checkout (if we want to include the .git folder, which a lot of build scripts make use of)
  • Use checkout rule (we want to use the Go convention):

    +:. => src/github.com/mitchellh/terraform

Build steps:

echo cd %system.teamcity.build.checkoutDir%
cd "%system.teamcity.build.checkoutDir%"
path=C:\Program Files (x86)\Git\bin;%env.Path%;%system.teamcity.build.checkoutDir%\bin;
echo path=C:\Program Files (x86)\Git\bin;%env.Path%;%system.teamcity.build.checkoutDir%\bin;
set GOPATH=%system.teamcity.build.checkoutDir%
echo set GOPATH=%system.teamcity.build.checkoutDir%

echo "Getting dependancies"
go get golang.org/x/tools/cmd/vet
go get golang.org/x/tools/cmd/cover
go get golang.org/x/tools/cmd/stringer
go get github.com/mitchellh/gox

echo cd %system.teamcity.build.checkoutDir%\src\github.com\mitchellh\terraform
cd "%system.teamcity.build.checkoutDir%\src\github.com\mitchellh\terraform"

echo "Update resources"
go get ./...

echo "Run static code analysis"
go tool vet -asmdecl -atomic -bool -buildtags -copylocks -methods -nilfunc -printf -rangeloops -shift -structtags -unsafeptr .

echo "Build"
cd scripts
sh build.sh

echo "Run unit tests"
go test -timeout=30s -parallel=4

echo "Run code coverage"
go test -coverprofile=coverage.out
go tool cover -html=coverage.out
rm coverage.out
like image 163
Taliesin Avatar answered Oct 19 '22 22:10

Taliesin


I am using a Team City build server on a Mac that runs a rake file, in the rake file I do all the commands to get dependancies, (go gets), tests and builds to the correct environment.

let me know if you want any pointers in writing the Rake files,

As a side note, i have been creating functional tests for REST Api's using this frame work. This has saved my code many times over. http://github.com/DigitalInnovation/cucumber_rest_api

like image 26
gregmcpugh Avatar answered Oct 19 '22 23:10

gregmcpugh