-
Notifications
You must be signed in to change notification settings - Fork 0
/
magefile.go
186 lines (138 loc) · 4.55 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
//go:build mage
package main
import (
"bufio"
"bytes"
"errors"
"fmt"
"os"
"os/exec"
"path"
"strings"
"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()
}
// UnitTests runs the unit test suite.
func UnitTest() error { return mageextras.UnitTest() }
// IntegrationTest executes the integration test suite.
func IntegrationTest() error {
mg.Deps(Install)
examplesDir := "examples"
var stinkOut bytes.Buffer
cmdStink := exec.Command("stink", path.Join(examplesDir, "hello.sh"))
cmdStink.Stdout = bufio.NewWriter(&stinkOut)
cmdStink.Stderr = os.Stderr
if err := cmdStink.Run(); err != nil {
return err
}
stinkOutString := stinkOut.String()
if !strings.Contains(stinkOutString, "\"POSIXy\":true") {
return fmt.Errorf("Expected stink output to treat hello.sh as POSIXy: true, got %s\n", stinkOutString)
}
cmdStank := exec.Command("stank", examplesDir)
cmdStank.Stdout = os.Stdout
cmdStank.Stderr = os.Stderr
if err := cmdStank.Run(); err != nil {
return err
}
cmdRosy := exec.Command("rosy", "-kame", examplesDir)
cmdRosy.Stdout = os.Stdout
cmdRosy.Stderr = os.Stderr
err := cmdRosy.Run()
if err == nil {
return errors.New("Expected non-zero exit status from rosy")
}
cmdFunk := exec.Command("funk", examplesDir)
cmdFunk.Stdout = os.Stdout
cmdFunk.Stderr = os.Stderr
err = cmdFunk.Run()
if err == nil {
return errors.New("Expected non-zero exit status from funk")
}
return nil
}
// Test runs unit and integration tests.
func Test() error { mg.Deps(UnitTest); mg.Deps(IntegrationTest); return nil }
// 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") }
// 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(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", "rosy") }
// 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) }