Giter Club home page Giter Club logo

golang-example's Introduction

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 BUILDKITE_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 BUILDKITE_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:
          BUILDKITE_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)

golang-example's People

Contributors

keithpitt avatar toolmantim avatar faun avatar hwchiu avatar

Stargazers

Banging avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.