1
0
Fork 0
mirror of https://github.com/vbatts/git-validation.git synced 2024-12-26 23:46:30 +00:00

Merge pull request #58 from vbatts/mage

*go: trying out magefiles
This commit is contained in:
Vincent Batts 2023-03-14 21:58:05 -04:00 committed by GitHub
commit 767ae83c3f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 153 additions and 21 deletions

View file

@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go: ['1.13', '1.14', '1.15', '1.16']
go: ['1.17', '1.18', '1.19', '1.20']
name: Documentation and Linting
steps:
@ -30,9 +30,6 @@ jobs:
set -x
export PATH=$GOPATH/bin:$PATH
cd go/src/github.com/vbatts/git-validation
go get ./...
go vet -x ./...
go build -v .
go test -v ./...
go run mage.go -v vet build test
./git-validation -run DCO,short-subject,dangling-whitespace -v
./git-validation -run DCO,short-subject,dangling-whitespace -v -range ${GITHUB_SHA}..HEAD

View file

@ -102,6 +102,14 @@ vbatts@valse ~/src/vb/git-validation (master) $ GIT_CHECK_EXCLUDE="./vendor:./gi
using the `GIT_CHECK_EXCLUDE` environment variable. Multiple paths should be separated by colon(`:`)
## contributing
When making a change, verify it with:
```shell
go run mage.go vet build test
```
## Rules
Default rules are added by registering them to the `validate` package.

5
go.mod
View file

@ -3,9 +3,8 @@ module github.com/vbatts/git-validation
go 1.12
require (
github.com/fatih/color v1.15.0
github.com/hashicorp/go-version v1.3.0
github.com/konsorten/go-windows-terminal-sequences v1.0.3 // indirect
github.com/magefile/mage v1.14.0
github.com/sirupsen/logrus v1.8.1
github.com/stretchr/objx v0.1.1 // indirect
golang.org/x/sys v0.0.0-20210511113859-b0526f3d8744 // indirect
)

25
go.sum
View file

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

10
mage.go Normal file
View file

@ -0,0 +1,10 @@
// +build ignore
package main
import (
"os"
"github.com/magefile/mage/mage"
)
func main() { os.Exit(mage.Main()) }

119
magefile.go Normal file
View file

@ -0,0 +1,119 @@
//go:build mage
// +build mage
package main
import (
"fmt"
"io"
"os"
"os/exec"
"github.com/fatih/color"
"github.com/magefile/mage/mg" // mg contains helpful utility functions, like Deps
)
var (
// Default target to run when none is specified
// If not set, running mage will list available targets
Default = Build
app string = "git-validation"
Stdout = cw{c: color.New(color.FgGreen), o: os.Stdout}
Stderr = cw{c: color.New(color.FgRed), o: os.Stderr}
)
// hack around color.Color not implementing Write()
type cw struct {
c *color.Color
o io.Writer
}
func (cw cw) Write(p []byte) (int, error) {
i := len(p)
_, err := cw.c.Fprint(cw.o, string(p)) // discarding the number of bytes written for now...
return i, err
}
// A build step that requires additional params, or platform specific steps for example
func Build() error {
mg.Deps(InstallDeps)
fmt.Println("Building...")
cmd := exec.Command("go", "build", "-v", "-o", app, ".")
cmd.Stdout = Stdout
cmd.Stderr = Stderr
return cmd.Run()
}
// Vet the codes
func Vet() error {
fmt.Println("go vet...")
cmd := exec.Command("go", "vet", "./...")
cmd.Stdout = Stdout
cmd.Stderr = Stderr
return cmd.Run()
}
// Run the Linters
func Lint() error {
mg.Deps(InstallToolsLint)
fmt.Println("Linting...")
cmd := exec.Command("golangci-lint", "run")
cmd.Stdout = Stdout
cmd.Stderr = Stderr
return cmd.Run()
}
// Run the tests available
func Test() error {
fmt.Println("Testing...")
cmd := exec.Command("go", "test", "-v", "./...")
cmd.Stdout = Stdout
cmd.Stderr = Stderr
return cmd.Run()
}
// A custom install step if you need your bin someplace other than go/bin
func Install() error {
mg.Deps(Build)
fmt.Println("Installing...")
return os.Rename(app, "/usr/local/bin/"+app)
}
// Manage your deps, or running package managers.
func InstallDeps() error {
mg.Deps(Tidy)
fmt.Println("Installing Deps...")
cmd := exec.Command("go", "get", "./...")
cmd.Stdout = Stdout
cmd.Stderr = Stderr
return cmd.Run()
}
// Tools used during build/dev/test
func InstallTools() error {
mg.Deps(InstallToolsLint)
return nil
}
func InstallToolsLint() error {
fmt.Println("Installing Deps...")
cmd := exec.Command("go", "install", "github.com/golangci/golangci-lint/cmd/golangci-lint@v1.51.2")
cmd.Stdout = Stdout
cmd.Stderr = Stderr
return cmd.Run()
}
// Tidy go modules
func Tidy() error {
fmt.Println("Tidy up...")
cmd := exec.Command("go", "mod", "tidy")
cmd.Stdout = Stdout
cmd.Stderr = Stderr
return cmd.Run()
}
// Clean up after yourself
func Clean() {
fmt.Println("Cleaning...")
os.RemoveAll(app)
}