Go

1 minute read

Versions and setup

Go 1.21 is installed by default. To change to another Go version, use this script in your Setup Commands.

Set the desired version as an environment variable in your project or add it in the Setup Commands along with the install script:

export GO_VERSION=1.22.0 source /dev/stdin <<< "$(curl -sSL https://raw.githubusercontent.com/codeship/scripts/master/languages/go.sh)"

Path

We set the GOPATH to ${HOME} and checkout your code into

${HOME}/src/github.com/GITHUB_USER_NAME/GITHUB_REPOSITORY_NAME

Building Your Project

You can build your Go project with

go build

Dependencies

You can install dependencies with:

go get

To also install test dependencies, use the following command instead

go get -t -v ./...

Dependency Cache

We do not cache Go dependencies between builds.

Frameworks And Testing

We support all Go tools and test frameworks. You can run your tests with a standard go test -v or by using test frameworks such as gocheck.

For example, using gocheck would look like:

go get launchpad.net/gocheck go test -gocheck.v

Parallel Testing

If you are running parallel test pipelines, you will want separate your tests into groups and call a group specifically in each pipeline. For instance:

Pipeline 1:

go test tests_1.go

Pipeline 2:

go test tests_2.go

Parallelization Modules

In addition to parallelizing your tests explicitly via parallel pipelines, some customers have found using Go’s built-in test parallelization is a good way to speed up your tests.

Note that aggressive parallelization can cause resource and build failure issues, as well.

Notes And Known Issues

Due to Go version and build issues, you may find it helpful to tests your commands with different versions via an SSH debug session if tests are running differently on CodeShip compared to your local machine.