This repository has been archived by the owner on May 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: add Go1.11.x, enable coverage for latest Go release
- Loading branch information
Showing
3 changed files
with
119 additions
and
23 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |