Skip to content
This repository has been archived by the owner on May 11, 2020. It is now read-only.

Commit

Permalink
ci: add Go1.11.x, enable coverage for latest Go release
Browse files Browse the repository at this point in the history
  • Loading branch information
sbinet committed Oct 16, 2018
1 parent a2a4ba6 commit 5d3ba92
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 23 deletions.
18 changes: 0 additions & 18 deletions .ci/code-coverage.sh

This file was deleted.

30 changes: 25 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,40 @@
language: go
go:
- 1.9.x
- 1.10.x
- master
os:
- linux

env:
- TAGS="-tags travis"

cache:
directories:
- $HOME/.cache/go-build
- $HOME/gopath/pkg/mod

matrix:
fast_finish: true
allow_failures:
- go: master
include:
- go: 1.9.x
env:
- COVERAGE=""
- go: 1.10.x
env:
- COVERAGE=""
- go: 1.11.x
env:
- COVERAGE="-cover -race"
- go: master
env:
- COVERAGE="-race"
- GO111MODULE="on"

sudo: false

script:
- go get -d -t -v ./...
- go install -v $TAGS ./...
- ./.ci/code-coverage.sh
- go run ./ci/run-tests.go $COVERAGE

after_success:
- bash <(curl -s https://codecov.io/bash)
94 changes: 94 additions & 0 deletions ci/run-tests.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// Copyright 2018 The go-interpreter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build ignore

package main

import (
"bufio"
"bytes"
"flag"
"io/ioutil"
"log"
"os"
"os/exec"
"strings"
)

func main() {
log.SetPrefix("ci: ")
log.SetFlags(0)

var (
race = flag.Bool("race", false, "enable race detector")
cover = flag.Bool("cover", false, "enable code coverage")
tags = flag.String("tags", "", "build tags")
)

flag.Parse()

out := new(bytes.Buffer)
cmd := exec.Command("go", "list", "./...")
cmd.Stdout = out
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin

err := cmd.Run()
if err != nil {
log.Fatal(err)
}

f, err := os.Create("coverage.txt")
if err != nil {
log.Fatal(err)
}
defer f.Close()

args := []string{"test", "-v"}

if *cover {
args = append(args, "-coverprofile=profile.out", "-covermode=atomic")
}
if *tags != "" {
args = append(args, "-tags="+*tags)
}
if *race {
args = append(args, "-race")
}
args = append(args, "")

scan := bufio.NewScanner(out)
for scan.Scan() {
pkg := scan.Text()
if strings.Contains(pkg, "vendor") {
continue
}
args[len(args)-1] = pkg
cmd := exec.Command("go", args...)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run()
if err != nil {
log.Fatal(err)
}
if *cover {
profile, err := ioutil.ReadFile("profile.out")
if err != nil {
log.Fatal(err)
}
_, err = f.Write(profile)
if err != nil {
log.Fatal(err)
}
os.Remove("profile.out")
}
}

err = f.Close()
if err != nil {
log.Fatal(err)
}
}

0 comments on commit 5d3ba92

Please sign in to comment.