forked from princjef/gomarkdoc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
magefile.go
85 lines (68 loc) · 1.76 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
//go:build mage
// +build mage
package main
import (
"os"
"path/filepath"
"github.com/princjef/mageutil/bintool"
"github.com/princjef/mageutil/shellcmd"
)
var linter = bintool.Must(bintool.New(
"golangci-lint{{.BinExt}}",
"1.61.0",
"https://github.com/golangci/golangci-lint/releases/download/v{{.Version}}/golangci-lint-{{.Version}}-{{.GOOS}}-{{.GOARCH}}{{.ArchiveExt}}",
))
func Lint() error {
if err := linter.Ensure(); err != nil {
return err
}
return linter.Command(`run`).Run()
}
func Generate() error {
return shellcmd.Command(`go generate .`).Run()
}
func Build() error {
return shellcmd.Command(`go build -o ./bin/gomarkdoc ./cmd/gomarkdoc`).Run()
}
func Doc() error {
return shellcmd.RunAll(
`go run ./cmd/gomarkdoc .`,
`go run ./cmd/gomarkdoc --header "" ./lang/...`,
`go run ./cmd/gomarkdoc --header "" ./format/...`,
`go run ./cmd/gomarkdoc --header "" ./cmd/...`,
)
}
func DocVerify() error {
return shellcmd.RunAll(
`go run ./cmd/gomarkdoc -c .`,
`go run ./cmd/gomarkdoc -c --header "" ./lang/...`,
`go run ./cmd/gomarkdoc -c --header "" ./format/...`,
`go run ./cmd/gomarkdoc -c --header "" ./cmd/...`,
)
}
func RegenerateTestDocs() error {
dirs, err := os.ReadDir("./testData")
if err != nil {
return err
}
base, err := os.Getwd()
if err != nil {
return err
}
for _, dir := range dirs {
if !dir.IsDir() {
continue
}
os.Chdir(filepath.Join(base, "./testData", dir.Name()))
if err := shellcmd.Command(`go run ../../cmd/gomarkdoc -o "{{.Dir}}/README.md" ./...`).Run(); err != nil {
return err
}
}
return nil
}
func Test() error {
return shellcmd.Command(`go test -count 1 -coverprofile=coverage.txt ./...`).Run()
}
func Coverage() error {
return shellcmd.Command(`go tool cover -html=coverage.txt`).Run()
}