-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmagefile.go
123 lines (104 loc) · 2.52 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
//go:build mage
// +build mage
package main
import (
"fmt"
"os"
"strings"
"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
"github.com/mysteriumnetwork/feedback/ci"
"github.com/mysteriumnetwork/go-ci/commands"
"github.com/mysteriumnetwork/go-ci/shell"
"github.com/mysteriumnetwork/go-ci/util"
)
// Build builds the service
func Build() error {
if os.Getenv("GITHUB_CI") == "" {
mg.Deps(Swag)
mg.Deps(Generate)
} else {
fmt.Println("Skipping swagger generation in CI environment")
}
return shell.NewCmd("go build -o ./build/feedback ./cmd/main.go").Run()
}
// Installs the swag generation tool
func swagInstall() error {
return sh.RunV("go", "install", "github.com/swaggo/swag/cmd/[email protected]")
}
// Swag generates the swagger documents
func Swag() error {
mg.Deps(swagInstall)
swag, err := util.GetGoBinaryPath("swag")
if err != nil {
return err
}
return sh.RunV(
swag, "init",
"--generalInfo", "./cmd/main.go",
"--output", "./docs",
"--parseDependency",
"--parseDepth", "1",
)
}
// Test runs unit tests
func Test() error {
packages, err := unitTestPackages()
if err != nil {
return err
}
args := append([]string{"test", "-race", "-count=1", "-timeout", "5m"}, packages...)
return sh.RunV("go", args...)
}
func unitTestPackages() ([]string, error) {
allPackages, err := listPackages()
if err != nil {
return nil, err
}
packages := make([]string, 0)
for _, p := range allPackages {
if !strings.Contains(p, "e2e") {
packages = append(packages, p)
}
}
return packages, nil
}
func listPackages() ([]string, error) {
output, err := sh.Output("go", "list", "./...")
if err != nil {
return nil, err
}
return strings.Split(strings.Replace(output, "\r\n", "\n", -1), "\n"), nil
}
// CheckCopyright checks for issues with go imports
func CheckCopyright() error {
return commands.CopyrightD(".", "docs")
}
// CheckGo checks for issues with go imports
func CheckGoImports() error {
return commands.GoImportsD(".", "docs")
}
// CheckGoLint reports linting errors
func CheckGoLint() error {
return commands.GoLintD(".", "docs")
}
// CheckGoVet checks that the source is compliant with go vet
func CheckGoVet() error {
return commands.GoVet(".")
}
// Check runs all checks
func Check() error {
return commands.CheckD(".", "docs")
}
// Run runs the service
func Run() error {
return sh.RunV("go", "run", "./cmd/main.go")
}
// E2E runs the e2e test suite
func E2E() error {
return ci.E2E()
}
// Generate runs go generate
func Generate() error {
return sh.RunV("go", "generate", "./...")
}