faun / golang-example

An example on how to test a Golang program using Buildkite

Home Page:https://github.com/buildkite/example-pipelines

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Buildkite Golang Example

Add to Buildkite

This repository is an example on how to test a Golang project using Buildkite.

Interested in using Docker instead? (which is way mega simpler than this) Check out https://github.com/buildkite/golang-docker-example

Using in your own build pipelines

We've wrapped up the $GOPATH wrangling required to get Golang projects to run into a pre-command hook which you can see here: https://github.com/buildkite/golang-example/blob/master/.buildkite/hooks/pre-command

To use in your own build pipelines:

  1. Copy the pre-command hook into your project:

    cd /your/golang/repo
    mkdir -p .buildkite/hooks
    curl -o .buildkite/hooks/pre-command https://raw.githubusercontent.com/buildkite/golang-example/master/.buildkite/hooks/pre-command
    chmod +x .buildkite/hooks/pre-command
  2. Add BUILDKTE_GOLANG_IMPORT_PATH to your build steps. If your import path in Golang looks like this:

    import (
      "github.com/keithpitt/project/sub-package"
    )

    Then your BUILDKTE_GOLANG_IMPORT_PATH would be github.com/keithpitt/project (we don't include the sub-package part of the import). This path should also match the directory structure within the $GOPATH on your own development machine.

    You can add the $BUILDKITE_BUILD_CHECKOUT_PATH to your .pipeline.yml file like this:

    steps:
      - command: "./scripts/test.sh"
        env:
          BUILDKTE_GOLANG_IMPORT_PATH: "github.com/buildkite/golang-example"

How does it work?

Testing Golang projects can be tricky due to how Golang handles it's $GOPATH. What our pre-command hook does is create an entirely new $GOPATH tree within the current build directory (under tmp/go), and symlink the current build directory to the desired go import path location. So the new build directory would look something like this:

$BUILDKITE_BUILD_CHECKOUT_PATH/tmp/go/src/github.com/buildkite/golang-example

The hook then changes the working directory to this new folder, so all of your build commands happen within the directory.

License

See Licence.md (MIT)

About

An example on how to test a Golang program using Buildkite

https://github.com/buildkite/example-pipelines

License:MIT License


Languages

Language:Shell 58.1%Language:Go 41.9%