Skip to content

Commit c6da052

Browse files
authored
Merge pull request #1208 from sirupsen/magefile
migrate ci target from bash scripts to magefile
2 parents cd4bf4e + 3986c92 commit c6da052

File tree

6 files changed

+93
-13
lines changed

6 files changed

+93
-13
lines changed

.travis.yml

+3-6
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ os: linux
99
install:
1010
- ./travis/install.sh
1111
script:
12-
- ./travis/cross_build.sh
13-
- ./travis/lint.sh
14-
- export GOMAXPROCS=4
15-
- export GORACE=halt_on_error=1
16-
- go test -race -v ./...
17-
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then go test -race -v -tags appengine ./... ; fi
12+
- go run mage.go -v crossBuild
13+
- go run mage.go lint
14+
- go run mage.go test

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module github.com/sirupsen/logrus
22

33
require (
44
github.com/davecgh/go-spew v1.1.1 // indirect
5+
github.com/magefile/mage v1.10.0
56
github.com/pmezard/go-difflib v1.0.0 // indirect
67
github.com/stretchr/testify v1.2.2
78
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
22
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/magefile/mage v1.10.0 h1:3HiXzCUY12kh9bIuyXShaVe529fJfyqoVM42o/uom2g=
4+
github.com/magefile/mage v1.10.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
35
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
46
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
57
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=

mage.go

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// +build ignore
2+
3+
package main
4+
5+
import (
6+
"github.com/magefile/mage/mage"
7+
"os"
8+
)
9+
10+
func main() { os.Exit(mage.Main()) }

magefile.go

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// +build mage
2+
3+
package main
4+
5+
import (
6+
"encoding/json"
7+
"fmt"
8+
"os"
9+
"path"
10+
11+
"github.com/magefile/mage/mg"
12+
"github.com/magefile/mage/sh"
13+
)
14+
15+
// getBuildMatrix returns the build matrix from the current version of the go compiler
16+
func getBuildMatrix() (map[string][]string, error) {
17+
jsonData, err := sh.Output("go", "tool", "dist", "list", "-json")
18+
if err != nil {
19+
return nil, err
20+
}
21+
var data []struct {
22+
Goos string
23+
Goarch string
24+
}
25+
if err := json.Unmarshal([]byte(jsonData), &data); err != nil {
26+
return nil, err
27+
}
28+
29+
matrix := map[string][]string{}
30+
for _, v := range data {
31+
if val, ok := matrix[v.Goos]; ok {
32+
matrix[v.Goos] = append(val, v.Goarch)
33+
} else {
34+
matrix[v.Goos] = []string{v.Goarch}
35+
}
36+
}
37+
38+
return matrix, nil
39+
}
40+
41+
func CrossBuild() error {
42+
matrix, err := getBuildMatrix()
43+
if err != nil {
44+
return err
45+
}
46+
47+
for os, arches := range matrix {
48+
for _, arch := range arches {
49+
env := map[string]string{
50+
"GOOS": os,
51+
"GOARCH": arch,
52+
}
53+
if mg.Verbose() {
54+
fmt.Printf("Building for GOOS=%s GOARCH=%s\n", os, arch)
55+
}
56+
if err := sh.RunWith(env, "go", "build", "./..."); err != nil {
57+
return err
58+
}
59+
}
60+
}
61+
return nil
62+
}
63+
64+
func Lint() error {
65+
gopath := os.Getenv("GOPATH")
66+
if gopath == "" {
67+
return fmt.Errorf("cannot retrieve GOPATH")
68+
}
69+
70+
return sh.Run(path.Join(gopath, "bin", "golangci-lint"), "run", "./...")
71+
}
72+
73+
// Run the test suite
74+
func Test() error {
75+
return sh.RunWith(map[string]string{"GORACE": "halt_on_error=1"},
76+
"go", "test", "-race", "-v", "./...")
77+
}

travis/lint.sh

-7
This file was deleted.

0 commit comments

Comments
 (0)