Skip to content

Commit 767ae83

Browse files
authored
Merge pull request #58 from vbatts/mage
*go: trying out magefiles
2 parents 56e85dc + 6947667 commit 767ae83

File tree

6 files changed

+153
-21
lines changed

6 files changed

+153
-21
lines changed

.github/workflows/go.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
runs-on: ubuntu-latest
1010
strategy:
1111
matrix:
12-
go: ['1.13', '1.14', '1.15', '1.16']
12+
go: ['1.17', '1.18', '1.19', '1.20']
1313

1414
name: Documentation and Linting
1515
steps:
@@ -30,9 +30,6 @@ jobs:
3030
set -x
3131
export PATH=$GOPATH/bin:$PATH
3232
cd go/src/github.com/vbatts/git-validation
33-
go get ./...
34-
go vet -x ./...
35-
go build -v .
36-
go test -v ./...
33+
go run mage.go -v vet build test
3734
./git-validation -run DCO,short-subject,dangling-whitespace -v
3835
./git-validation -run DCO,short-subject,dangling-whitespace -v -range ${GITHUB_SHA}..HEAD

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ vbatts@valse ~/src/vb/git-validation (master) $ GIT_CHECK_EXCLUDE="./vendor:./gi
102102

103103
using the `GIT_CHECK_EXCLUDE` environment variable. Multiple paths should be separated by colon(`:`)
104104

105+
## contributing
106+
107+
When making a change, verify it with:
108+
109+
```shell
110+
go run mage.go vet build test
111+
```
112+
105113
## Rules
106114

107115
Default rules are added by registering them to the `validate` package.

go.mod

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ module github.com/vbatts/git-validation
33
go 1.12
44

55
require (
6+
github.com/fatih/color v1.15.0
67
github.com/hashicorp/go-version v1.3.0
7-
github.com/konsorten/go-windows-terminal-sequences v1.0.3 // indirect
8+
github.com/magefile/mage v1.14.0
89
github.com/sirupsen/logrus v1.8.1
9-
github.com/stretchr/objx v0.1.1 // indirect
10-
golang.org/x/sys v0.0.0-20210511113859-b0526f3d8744 // indirect
1110
)

go.sum

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
22
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3-
github.com/hashicorp/go-version v1.2.0 h1:3vNe/fWF5CBgRIguda1meWhsZHy3m8gCJ5wx+dIzX/E=
4-
github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
3+
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
4+
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
55
github.com/hashicorp/go-version v1.3.0 h1:McDWVJIU/y+u1BRV06dPaLfLCaT7fUTJLp5r04x7iNw=
66
github.com/hashicorp/go-version v1.3.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
7-
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
8-
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
9-
github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8=
10-
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
7+
github.com/magefile/mage v1.14.0 h1:6QDX3g6z1YvJ4olPhT1wksUcSa/V0a1B+pJb73fBjyo=
8+
github.com/magefile/mage v1.14.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
9+
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
10+
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
11+
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
12+
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
13+
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
1114
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
1215
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
13-
github.com/sirupsen/logrus v1.4.1 h1:GL2rEmy6nsikmW0r8opw9JIRScdMF5hA8cOYLH7In1k=
14-
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
1516
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
1617
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
17-
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
1818
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
1919
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
20-
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33 h1:I6FyU15t786LL7oL/hn43zqTuEGr4PN7F4XJ1p4E3Y8=
21-
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
2220
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
23-
golang.org/x/sys v0.0.0-20210511113859-b0526f3d8744 h1:yhBbb4IRs2HS9PPlAg6DMC6mUOKexJBNsLf4Z+6En1Q=
24-
golang.org/x/sys v0.0.0-20210511113859-b0526f3d8744/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
21+
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
22+
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
23+
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

mage.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// +build ignore
2+
3+
package main
4+
5+
import (
6+
"os"
7+
"github.com/magefile/mage/mage"
8+
)
9+
10+
func main() { os.Exit(mage.Main()) }

magefile.go

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
//go:build mage
2+
// +build mage
3+
4+
package main
5+
6+
import (
7+
"fmt"
8+
"io"
9+
"os"
10+
"os/exec"
11+
12+
"github.com/fatih/color"
13+
"github.com/magefile/mage/mg" // mg contains helpful utility functions, like Deps
14+
)
15+
16+
var (
17+
// Default target to run when none is specified
18+
// If not set, running mage will list available targets
19+
Default = Build
20+
app string = "git-validation"
21+
Stdout = cw{c: color.New(color.FgGreen), o: os.Stdout}
22+
Stderr = cw{c: color.New(color.FgRed), o: os.Stderr}
23+
)
24+
25+
// hack around color.Color not implementing Write()
26+
type cw struct {
27+
c *color.Color
28+
o io.Writer
29+
}
30+
31+
func (cw cw) Write(p []byte) (int, error) {
32+
i := len(p)
33+
_, err := cw.c.Fprint(cw.o, string(p)) // discarding the number of bytes written for now...
34+
return i, err
35+
}
36+
37+
// A build step that requires additional params, or platform specific steps for example
38+
func Build() error {
39+
mg.Deps(InstallDeps)
40+
fmt.Println("Building...")
41+
cmd := exec.Command("go", "build", "-v", "-o", app, ".")
42+
cmd.Stdout = Stdout
43+
cmd.Stderr = Stderr
44+
return cmd.Run()
45+
}
46+
47+
// Vet the codes
48+
func Vet() error {
49+
fmt.Println("go vet...")
50+
cmd := exec.Command("go", "vet", "./...")
51+
cmd.Stdout = Stdout
52+
cmd.Stderr = Stderr
53+
return cmd.Run()
54+
}
55+
56+
// Run the Linters
57+
func Lint() error {
58+
mg.Deps(InstallToolsLint)
59+
fmt.Println("Linting...")
60+
cmd := exec.Command("golangci-lint", "run")
61+
cmd.Stdout = Stdout
62+
cmd.Stderr = Stderr
63+
return cmd.Run()
64+
}
65+
66+
// Run the tests available
67+
func Test() error {
68+
fmt.Println("Testing...")
69+
cmd := exec.Command("go", "test", "-v", "./...")
70+
cmd.Stdout = Stdout
71+
cmd.Stderr = Stderr
72+
return cmd.Run()
73+
}
74+
75+
// A custom install step if you need your bin someplace other than go/bin
76+
func Install() error {
77+
mg.Deps(Build)
78+
fmt.Println("Installing...")
79+
return os.Rename(app, "/usr/local/bin/"+app)
80+
}
81+
82+
// Manage your deps, or running package managers.
83+
func InstallDeps() error {
84+
mg.Deps(Tidy)
85+
fmt.Println("Installing Deps...")
86+
cmd := exec.Command("go", "get", "./...")
87+
cmd.Stdout = Stdout
88+
cmd.Stderr = Stderr
89+
return cmd.Run()
90+
}
91+
92+
// Tools used during build/dev/test
93+
func InstallTools() error {
94+
mg.Deps(InstallToolsLint)
95+
return nil
96+
}
97+
98+
func InstallToolsLint() error {
99+
fmt.Println("Installing Deps...")
100+
cmd := exec.Command("go", "install", "github.com/golangci/golangci-lint/cmd/[email protected]")
101+
cmd.Stdout = Stdout
102+
cmd.Stderr = Stderr
103+
return cmd.Run()
104+
}
105+
106+
// Tidy go modules
107+
func Tidy() error {
108+
fmt.Println("Tidy up...")
109+
cmd := exec.Command("go", "mod", "tidy")
110+
cmd.Stdout = Stdout
111+
cmd.Stderr = Stderr
112+
return cmd.Run()
113+
}
114+
115+
// Clean up after yourself
116+
func Clean() {
117+
fmt.Println("Cleaning...")
118+
os.RemoveAll(app)
119+
}

0 commit comments

Comments
 (0)