-
Notifications
You must be signed in to change notification settings - Fork 0
/
magefile.go
130 lines (96 loc) · 3.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
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
124
125
126
127
128
129
130
//go:build mage
package main
import (
"fmt"
"os"
"github.com/magefile/mage/mg"
mageextras "github.com/mcandre/mage-extras"
"github.com/mcandre/stank"
)
// artifactsPath describes where artifacts are produced.
var artifactsPath = "bin"
// Default references the default build task.
var Default = Test
// Govulncheck runs govulncheck.
func Govulncheck() error { return mageextras.Govulncheck("-scan", "package", "./...") }
// SnykTest runs Snyk SCA.
func Snyk() error { return mageextras.SnykTest() }
// Audit runs a security audit.
func Audit() error {
mg.Deps(Govulncheck)
return Snyk()
}
// Test runs a unit test.
func Test() error { return mageextras.UnitTest() }
// CoverHTML denotes the HTML formatted coverage filename.
var CoverHTML = "cover.html"
// CoverProfile denotes the raw coverage data filename.
var CoverProfile = "cover.out"
// CoverageHTML generates HTML formatted coverage data.
func CoverageHTML() error {
mg.Deps(CoverageProfile)
return mageextras.CoverageHTML(CoverHTML, CoverProfile)
}
// CoverageProfile generates raw coverage data.
func CoverageProfile() error { return mageextras.CoverageProfile(CoverProfile) }
// Deadcode runs deadcode.
func Deadcode() error { return mageextras.Deadcode("./...") }
// Gofmt runs gofmt.
func GoFmt() error { return mageextras.GoFmt("-s", "-w") }
// GoImports runs goimports.
func GoImports() error { return mageextras.GoImports("-w") }
// GoVet runs default go vet analyzers.
func GoVet() error { return mageextras.GoVet() }
// Errcheck runs errcheck.
func Errcheck() error { return mageextras.Errcheck("-blank") }
// Nakedret runs nakedret.
func Nakedret() error { return mageextras.Nakedret("-l", "0") }
// Revive runs revive.
func Revive() error { return mageextras.Revive("-set_exit_status") }
// Shadow runs go vet with shadow checks enabled.
func Shadow() error { return mageextras.GoVetShadow() }
// Staticcheck runs staticcheck.
func Staticcheck() error { return mageextras.Staticcheck() }
// Unmake runs unmake.
func Unmake() error {
err := mageextras.Unmake(".")
if err != nil {
return err
}
return mageextras.Unmake("-n", ".")
}
// Lint runs the lint suite.
func Lint() error {
mg.Deps(Deadcode)
mg.Deps(GoFmt)
mg.Deps(GoImports)
mg.Deps(GoVet)
mg.Deps(Errcheck)
mg.Deps(Nakedret)
mg.Deps(Revive)
mg.Deps(Shadow)
mg.Deps(Staticcheck)
mg.Deps(Unmake)
return nil
}
// portBasename labels the artifact basename.
var portBasename = fmt.Sprintf("stank-%s", stank.Version)
// repoNamespace identifies the Go namespace for this project.
var repoNamespace = "github.com/mcandre/stank"
// Factorio cross-compiles Go binaries for a multitude of platforms.
func Factorio() error { return mageextras.Factorio(portBasename) }
// Port builds and compresses artifacts.
func Port() error { mg.Deps(Factorio); return mageextras.Archive(portBasename, artifactsPath) }
// Install builds and installs Go applications.
func Install() error { return mageextras.Install() }
// Uninstall deletes installed Go applications.
func Uninstall() error { return mageextras.Uninstall("stink", "stank", "funk") }
// CleanCoverage deletes coverage data.
func CleanCoverage() error {
if err := os.RemoveAll(CoverHTML); err != nil {
return err
}
return os.RemoveAll(CoverProfile)
}
// Clean deletes artifacts.
func Clean() error { mg.Deps(CleanCoverage); return os.RemoveAll(artifactsPath) }