-
Notifications
You must be signed in to change notification settings - Fork 0
/
Magefile.go
68 lines (54 loc) · 1.31 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
//go:build mage
// +build mage
package main
import (
"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
)
const (
BUILD_DIR = "build"
)
// Runs go mod download
func Download() error {
return sh.Run("go", "mod", "download")
}
// Installs the dev dependencies.
// Dependencies are: mage, golangci-lint
func InstallDevDependencies() error {
tools := []string{
"github.com/magefile/mage",
"github.com/golangci/golangci-lint/cmd/golangci-lint",
"github.com/cosmtrek/air",
}
for _, tool := range tools {
if err := sh.Run("go", "install", tool+"@latest"); err != nil {
return err
}
}
return nil
}
// Runs go mod download and then installs the binary.
func Build() error {
mg.Deps(Download)
return sh.Run("go", "build", "./cmd/server", "-o", BUILD_DIR)
}
// Run go tests.
func Test() error {
mg.Deps(Download)
return sh.Run("go", "test", "-coverprofile", BUILD_DIR+"/cover.out", "-v", "./...")
}
// Lint the code.
func Lint() error {
mg.Deps(InstallDevDependencies)
return sh.Run("golangci-lint", "run", "./...")
}
// Starts the development server with air featuring live reload.
func Dev() error {
mg.Deps(Download)
return sh.Run("air")
}
// Opens the coverage report in the browser.
func Coverage() error {
mg.Deps(Test)
return sh.Run("go", "tool", "cover", "-html="+BUILD_DIR+"/cover.out")
}