Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ci: update CI scaffolding #148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ jobs:
run: |
GOARCH=386 go test $TAGS ./...
GOARCH=amd64 go run ./ci/run-tests.go $TAGS -race $COVERAGE
python3 py3test.py
## FIXME(sbinet): bring back python3.4 or upgrade gpython to python3.x
## python3 py3test.py
- name: Test Windows
if: matrix.platform == 'windows-latest'
run: |
Expand Down
76 changes: 52 additions & 24 deletions ci/run-tests.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Copyright 2018 The go-python Authors. All rights reserved.
// Copyright ©2018 The go-python Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build ignore
// +build ignore

package main
Expand All @@ -10,32 +11,33 @@ import (
"bufio"
"bytes"
"flag"
"io/ioutil"
"fmt"
"log"
"os"
"os/exec"
"strings"
"time"
)

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

start := time.Now()
defer func() {
log.Printf("elapsed time: %v\n", time.Since(start))
}()

var (
race = flag.Bool("race", false, "enable race detector")
cover = flag.Bool("cover", false, "enable code coverage")
tags = flag.String("tags", "", "build tags")
race = flag.Bool("race", false, "enable race detector")
cover = flag.String("coverpkg", "", "apply coverage analysis in each test to packages matching the patterns.")
tags = flag.String("tags", "", "build tags")
verbose = flag.Bool("v", false, "enable verbose output")
)

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()
pkgs, err := pkgList()
if err != nil {
log.Fatal(err)
}
Expand All @@ -48,23 +50,24 @@ func main() {

args := []string{"test"}

if *cover {
args = append(args, "-coverprofile=profile.out", "-covermode=atomic")
if *verbose {
args = append(args, "-v")
}
if *cover != "" {
args = append(args, "-coverprofile=profile.out", "-covermode=atomic", "-coverpkg="+*cover)
}
if *tags != "" {
args = append(args, "-tags="+*tags)
}
if *race {
args = append(args, "-race")
switch {
case *race:
args = append(args, "-race", "-timeout=20m")
default:
args = append(args, "-timeout=10m")
}
args = append(args, "")

scan := bufio.NewScanner(out)
for scan.Scan() {
pkg := scan.Text()
if strings.Contains(pkg, "vendor") {
continue
}
for _, pkg := range pkgs {
args[len(args)-1] = pkg
cmd := exec.Command("go", args...)
cmd.Stdin = os.Stdin
Expand All @@ -74,8 +77,8 @@ func main() {
if err != nil {
log.Fatal(err)
}
if *cover {
profile, err := ioutil.ReadFile("profile.out")
if *cover != "" {
profile, err := os.ReadFile("profile.out")
if err != nil {
log.Fatal(err)
}
Expand All @@ -92,3 +95,28 @@ func main() {
log.Fatal(err)
}
}

func pkgList() ([]string, error) {
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 {
return nil, fmt.Errorf("could not get package list: %w", err)
}

var pkgs []string
scan := bufio.NewScanner(out)
for scan.Scan() {
pkg := scan.Text()
if strings.Contains(pkg, "vendor") {
continue
}
pkgs = append(pkgs, pkg)
}

return pkgs, nil
}