-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmage.go
71 lines (58 loc) · 1.69 KB
/
mage.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
//go:build mage
package main
import (
"context"
"fmt"
"os"
"runtime/debug"
"strconv"
"github.com/golangci/golangci-lint/pkg/commands"
"github.com/magefile/mage/mg"
"golang.org/x/vuln/scan"
)
func init() {
os.Setenv(mg.VerboseEnv, strconv.FormatBool(true))
}
func LintVerbose(ctx context.Context) error {
oldArgs := make([]string, len(os.Args))
copy(oldArgs, os.Args)
os.Args = append([]string{"golangci-lint"}, "run", "-v", "./...")
defer func() { os.Args = oldArgs }()
info := commands.BuildInfo{}
if buildInfo, available := debug.ReadBuildInfo(); available {
info.GoVersion = buildInfo.GoVersion
info.Version = buildInfo.Main.Version
info.Commit = fmt.Sprintf("(unknown, mod sum: %q)", buildInfo.Main.Sum)
info.Date = "(unknown)"
}
return commands.NewExecutor(info).Execute()
}
func Lint(ctx context.Context) error {
oldArgs := make([]string, len(os.Args))
copy(oldArgs, os.Args)
os.Args = append([]string{"golangci-lint"}, "run", "./...")
defer func() { os.Args = oldArgs }()
info := commands.BuildInfo{}
if buildInfo, available := debug.ReadBuildInfo(); available {
info.GoVersion = buildInfo.GoVersion
info.Version = buildInfo.Main.Version
info.Commit = fmt.Sprintf("(unknown, mod sum: %q)", buildInfo.Main.Sum)
info.Date = "(unknown)"
}
return commands.NewExecutor(info).Execute()
}
// VulnCheck runs golang.org/x/vuln/scan with given args.
func VulnCheck(ctx context.Context) error {
cmd := scan.Command(ctx, "./...")
err := cmd.Start()
if err == nil {
err = cmd.Wait()
}
return err
}
func CheckAllVerboseLint(ctx context.Context) {
mg.SerialCtxDeps(ctx, LintVerbose, VulnCheck)
}
func CheckAll(ctx context.Context) {
mg.SerialCtxDeps(ctx, Lint, VulnCheck)
}