Continuous Integration, and Continuous Deployment for Go

This guide will help you to build configuration for a Go project on Scrutinizer. Notice that, Scrutinizer automatically infers your build configuration and test commands depending on your build system by default.

If you have a specific set-up, you can override the inferred commands in your configuration, or use a a minimal node to completely disable any inferred commands.

Setup Go Environment

Go Version

Scrutinizer supports several Go versions. You can either specify a minor version or just use the latest for a given major version.

build:
    environment:
        go: 'go1.9.2' or 'go1.8'

Go Import Path

By default, GOPATH is set to $HOME/gopath, and your repository source code is placed in $GOPATH/github.com/user/repo or $GOPATH/bitbucket.org/user/repo.

If you use another Remote import path , you might need to specify the go_import_path in the configuration:

build:
    environment:
        go:
            version: 'go1.9.2'
            go_import_path: 'example.com/user/repo'

Dependencies

Scrutinizer will automatically infer dependency install commands based on your project using go get, Dep or Godep.

In case of godep, Scrutinizer will also automatically set the correct go_import_path for you.

If you would like to override the inferred commands, you can do so in your configuration:

build:
    nodes:
        my-tests:
            dependencies:
                override:
                    - ./install-deps

Testing

If you use make as build tool and have a Makefile in your root folder, the inferred command will be:

make

Otherwise go test will be inferred by default:

go test -v $(go list ./... | grep -v vendor)

In case that you would like to run a customized test script, you can override the default inferred command by adding them in your configuration:

build:
    nodes:
        my-tests:
            tests:
                override:
                    - ./run-tests.sh

Code Coverage

Scrutinizer supports default coverage file format of go tool Cover and clover, cobertura as well.

Take Cover as example, the configuration will look like:

build:
    nodes:
        tests-with-coverage:
            tests:
                override:
                    -
                        command: go test -coverprofile=cover.out
                        coverage:
                            file: 'cover.out'
                            format: 'go-cc'

If you have multiple commands that generate code coverage data, we will automatically take care of merging.

Deployment

Scrutinizer provides first-class support for deployment. Once all your tests have passed, it will automatically trigger deployment of your code. You can define deploy commands in your configuration:

build:
  nodes:
    deployment:
      requires:
        - branch: master
        - branch: /feature.*/
        - node: my-tests       # only runs if my-tests node succeeded

      commands:
        - deploy.sh

Multi-Core Builds

If your build benefits from multiple CPU cores, you can currently request up to 8 CPUs for your build. Simply, add the following to your configuration:

build:
  nodes:
    my-tests:
      resources:
        cpus: 4
Note: The maximum CPU number is limited by the number of available containers in your plan.

Cache

In order to speed up the future build, Scrutinizer automatically vendor directory vendor for go project. You can also customize configuration for caching, learn more in our Caching Reference.

For more informations about build configuration, please check out Build Config Reference.