-
Notifications
You must be signed in to change notification settings - Fork 2
/
magefile.go
65 lines (51 loc) · 1.35 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
//go:build mage
// +build mage
package main
import (
"fmt"
"os"
"path/filepath"
"github.com/magefile/mage/mg" // mg contains helpful utility functions, like Deps
"github.com/magefile/mage/sh"
)
var Default = Build
var pgnGeneratedCodePath = filepath.Join("pkg", "n2k", "pgninfo_generated.go")
// Build builds the code
func Build() error {
// If we haven't codegened yet, do that first
if _, err := os.Stat(pgnGeneratedCodePath); os.IsNotExist(err) {
mg.Deps(CodeGen)
}
mg.Deps(Dep)
fmt.Println("Building...")
return sh.RunV("go", "build", "-v", "-o", "bin/", "./cmd/...")
}
// Dep ensures that we've got our dependencies
func Dep() error {
fmt.Println("Installing Deps...")
if err := sh.RunV("go", "mod", "download"); err != nil {
return err
}
return nil
}
func CodeGen() error {
return sh.RunV("go", "run", "./cmd/pgngen/main.go", "./cmd/pgngen/deduper.go")
}
// Test runs the tests on this repository
func Test() error {
if os.Getenv("CI") == "" {
if err := sh.Run("golangci-lint", "run"); err != nil {
return err
}
}
return TestFast()
}
// TestFast runs the tests on this repository without golangci-lint, for fast cycles
func TestFast() error {
return sh.RunV("go", "test", "-coverpkg=./...", "-coverprofile=c.out", "./...")
}
// Clean cleans up all build artifacts
func Clean() {
fmt.Println("Cleaning...")
os.RemoveAll("bin")
}