-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmagefile.go
77 lines (62 loc) · 1.92 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
// Copyright (c) 2020, Sylabs, Inc. All rights reserved.
// +build mage
package main
import (
"fmt"
"strings"
"time"
"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
"github.com/sirupsen/logrus"
)
// Schema validates the GraphQL schema and generates a Go file containing the schema.
func Schema() error {
return generateSchema()
}
// ldFlags returns standard linker flags to pass to various Go commands.
func ldFlags() string {
vals := []string{
fmt.Sprintf("-X main.builtAt=%v", time.Now().UTC().Format(time.RFC3339)),
}
// Attempt to get git details.
d, err := describeHead()
if err == nil {
vals = append(vals, fmt.Sprintf("-X main.gitCommit=%v", d.ref.Hash().String()))
if d.isClean {
vals = append(vals, "-X main.gitTreeState=clean")
} else {
vals = append(vals, "-X main.gitTreeState=dirty")
}
if v, err := getVersion(d); err != nil {
logrus.WithError(err).Warn("failed to get version from git description")
} else {
vals = append(vals, fmt.Sprintf("-X main.gitVersion=%v", v.String()))
}
}
return strings.Join(vals, " ")
}
// Build builds Fuzzball assets using `go build`.
func Build() error {
mg.Deps(Schema)
return sh.RunV(mg.GoCmd(), "build", "-ldflags", ldFlags(), "./...")
}
// Install installs Fuzzball assets using `go install`.
func Install() error {
mg.Deps(Schema)
return sh.RunV(mg.GoCmd(), "install", "-ldflags", ldFlags(), "./...")
}
// Run runs the Fuzzball server using `go run`.
func Run() error {
mg.Deps(Schema)
return sh.RunV(mg.GoCmd(), "run", "-ldflags", ldFlags(), "./cmd/server/")
}
// Test runs unit and integration tests using `go test`.
func Test() error {
mg.Deps(Schema)
return sh.RunV(mg.GoCmd(), "test", "-ldflags", ldFlags(), "-cover", "-race", "-tags=integration", "./...")
}
// UnitTest runs unit tests using `go test`.
func UnitTest() error {
mg.Deps(Schema)
return sh.RunV(mg.GoCmd(), "test", "-ldflags", ldFlags(), "-cover", "-race", "./...")
}