You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

78 lines
1.8 KiB

// +build mage
package main
import (
"fmt"
"os"
"strings"
"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
)
var (
binary = "track-instances"
oslist = []string{"windows", "linux", "darwin"}
archlist = []string{"amd64", "arm64", "arm"}
version = os.Getenv("VERSION")
)
func dependencies() {
sh.RunV("go", "get", "-u", "-v", "golang.org/x/lint/...", "honnef.co/go/tools/cmd/staticcheck", "github.com/fzipp/gocyclo/...")
}
func Test() error {
mg.Deps(dependencies)
// packages, _ := sh.Output("go", "list", "./...")
// fmt.Println(packages)
// strings.Split(packages, " ")
// sh.RunV("go", "test", "-v", "-race", "./...")
output, err := sh.Output("find", ".", "-iname", "*.go", "-type", "f")
if err != nil {
return err
}
gofiles := strings.Split(output, "\n")
err = sh.RunV("go", "vet", "./...")
if err != nil {
return err
}
err = sh.RunV("staticcheck", "./...")
if err != nil {
return err
}
args := []string{"-over", "19"}
err = sh.RunV("gocyclo", append(args, gofiles...)...)
if err != nil {
return err
}
err = sh.RunV("golint", "-set_exit_status", "./...")
if err != nil {
return err
}
return nil
}
func Build() error {
if version == "" {
version = "latest"
}
err := os.Mkdir("release", 0755)
if err != nil && !os.IsExist(err) {
return err
}
for _, ops := range oslist {
for _, arch := range archlist {
if err := sh.RunWithV(map[string]string{"GOOS": ops, "GOARCH": arch}, "go", "build", "-ldflags", "-s -w", "-o", "release/"+binary, "./cmd/track-instances"); err != nil {
continue
}
sh.RunV("tar", "-czf", fmt.Sprintf("release/%s-%s-%s-%s.tar.gz", binary, version, ops, arch), "README.md", "-C", "release", binary)
os.Remove("release/" + binary)
}
}
return nil
}
func Clean() error {
return os.RemoveAll("release")
}