-
Notifications
You must be signed in to change notification settings - Fork 0
/
magefile.go
71 lines (57 loc) · 1.48 KB
/
magefile.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//go:build mage
package main
import (
"fmt"
"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
)
var Default = Test.Run
type Test mg.Namespace
// Runs the tests.
func (Test) Run() error {
goCmd := mg.GoCmd()
env := map[string]string{
"APP_ENV": "test",
}
return sh.RunWithV(env, goCmd, "test", "./...", "-race", "-count=1", "-v")
}
// Generates proto test files.
func (Test) GenerateProto() error {
return sh.RunV(
"protoc",
"--proto_path=./pkg/testing/testproto",
"--go_out=./pkg/testing/testproto",
"--go_opt=paths=source_relative",
"--go-grpc_out=./pkg/testing/testproto",
"--go-grpc_opt=paths=source_relative",
"sdktest.proto")
}
type Fmt mg.Namespace
// Runs gofmt.
func (Fmt) Run() error {
goCmd := mg.GoCmd()
return sh.RunV(goCmd, "fmt", "./...")
}
// Checks the code formatting.
func (Fmt) Check() error {
goModule, err := sh.Output(mg.GoCmd(), "list", "-m")
if err != nil {
return err
}
// flag -local string: put imports beginning with this string after 3rd-party packages; comma-separated list.
// flag -e: report all errors (not just the first 10 on different lines).
// flag -d: display diffs instead of rewriting files.
output, err := sh.Output("goimports", "-local="+goModule, "-e", "-d", ".")
if err != nil {
return err
}
if output != "" {
return fmt.Errorf("source code is not formatted:\n\n%s", output)
}
return nil
}
// Runs the linter.
func (Fmt) Lint() error {
lintCmd := "golangci-lint"
return sh.RunV(lintCmd, "run")
}