-
Notifications
You must be signed in to change notification settings - Fork 2
/
magefile.go
56 lines (46 loc) · 1.18 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
//go:build mage
// +build mage
package main
import (
"fmt"
"path/filepath"
"strings"
"github.com/magefile/mage/sh"
)
// Lint runs code linters on current directory and all
// subdirectories
func Lint() error {
linter := sh.OutCmd(filepath.Join(RepoRoot(), "bin", "golangci-lint"))
version := "1.52.2"
currentVersion, err := linter("--version")
if err != nil || !strings.Contains(currentVersion, version) {
fmt.Println("linter binary outdated or missing, downloading a new one now")
err := updateLinter(version)
if err != nil {
return err
}
}
out, err := linter("run", "--deadline=2m", "--config="+RepoRoot()+"/.golangci.yml", "./...")
if out != "" {
fmt.Println(out)
}
return err
}
// Test tests all go code in the current directory and
// all subdirectories
func Test() error {
return sh.RunV("go", "test", "./...")
}
func updateLinter(version string) error {
return sh.Run("bash", "-c",
"curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "+
RepoRoot()+"/bin v"+version,
)
}
func RepoRoot() string {
path, err := sh.Output("git", "rev-parse", "--show-toplevel")
if err != nil {
panic(err)
}
return path
}