尝试golang的CI

环境

gitlab:

  • docker,gitlab
  • docker,gitlab-runner
  • 用于集成部署的镜像制作,golang版本,和一些必须的工具(golint等)
  • runner 注册和配置
  • 定义规则,.gitlab-ci.yml
    • 获取列表,go list ./... | grep -v /vendor/
    • 单元测试, go test -short
    • 数据竞争, go test -race -short
    • 代码覆盖率
    • 构建
    • linter

github + travis-ci:

参考

language: go

go:
  - 1.9
  - 1.8
  - 1.7

branches:
  only:
    - master

cache:
  directories:
    - $GOPATH/pkg/dep

env:
  - DEP_VERSION="0.3.2"

before_install:
  # Setup some env variables
  - GO_FILES=$(find . -iname '*.go' | grep -v /vendor/)  # All the .go files, excluding vendor/
  - PKGS=$(go list ./... | grep -v /vendor/)             # All the import paths, excluding vendor/

  # Setup dependency management tool
  - curl -L -s https://github.com/golang/dep/releases/download/v${DEP_VERSION}/dep-linux-amd64 -o $GOPATH/bin/dep
  - chmod +x $GOPATH/bin/dep
  # To install latest version, use `go get -u github.com/golang/dep/cmd/dep`

  # Install linters
  - go get -u github.com/golang/lint/golint              # Linter
  - go get -u honnef.co/go/tools/cmd/megacheck           # Badass static analyzer/linter
  - go get -u github.com/kisielk/errcheck                # errcheck checks that you checked errors.

  # Install goveralls, Go integration for Coveralls.io.
  - go get -u github.com/mattn/goveralls

install:
  - dep ensure

script:
  - test -z $(gofmt -s -l $GO_FILES)  # Fail if a .go file hasn't been formatted with gofmt
  - go vet $PKGS                      # go vet is the official Go static analyzer
  - megacheck $PKGS                   # "go vet on steroids" + linter
  - errcheck $PKGS                    # Check for unchecked errors
  - golint -set_exit_status $PKGS     # One last linter
  # Run all the tests, track coverage in coveralls.io
  - go test -v -covermode=count -coverprofile=profile.cov $PKGS
  - goveralls -coverprofile=profile.cov -service=travis-ci