From 460942a32d6ea727b5522250ee5ad20f778b9a7e Mon Sep 17 00:00:00 2001 From: Mark Bates Date: Sat, 18 Jan 2020 14:06:30 -0500 Subject: [PATCH] actions and less mods (#40) --- .gometalinter.json | 3 - Makefile | 13 +---- go.mod | 6 +- go.sum | 24 ++------ grifts/release.go | 139 --------------------------------------------- refresh/events.go | 8 --- refresh/manager.go | 15 +---- 7 files changed, 8 insertions(+), 200 deletions(-) delete mode 100644 .gometalinter.json delete mode 100644 grifts/release.go delete mode 100644 refresh/events.go diff --git a/.gometalinter.json b/.gometalinter.json deleted file mode 100644 index e4f65a3..0000000 --- a/.gometalinter.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "Enable": ["vet", "golint", "goimports", "deadcode", "gotype", "ineffassign", "misspell", "nakedret", "unconvert", "megacheck", "varcheck"] -} diff --git a/Makefile b/Makefile index 199dfc0..4052cd5 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,5 @@ -TAGS ?= "sqlite" - install: - packr2 - go install -v ./. - -build: - packr2 - go build -v . + go install -v . test: - packr2 - go test -tags ${TAGS} ./... - + go test -cover -failfast ./... \ No newline at end of file diff --git a/go.mod b/go.mod index 6d7c81c..78bd0cc 100644 --- a/go.mod +++ b/go.mod @@ -3,12 +3,8 @@ module github.com/markbates/refresh go 1.13 require ( - github.com/fatih/color v1.7.0 + github.com/fatih/color v1.9.0 github.com/fsnotify/fsnotify v1.4.7 - github.com/gobuffalo/events v1.4.0 - github.com/markbates/grift v1.5.0 - github.com/mattn/go-colorable v0.1.4 // indirect - github.com/mattn/go-isatty v0.0.11 // indirect github.com/mitchellh/go-homedir v1.1.0 github.com/spf13/cobra v0.0.5 gopkg.in/yaml.v2 v2.2.7 diff --git a/go.sum b/go.sum index 34a2a54..5cda5d0 100644 --- a/go.sum +++ b/go.sum @@ -4,27 +4,16 @@ github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 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/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys= -github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= +github.com/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s= +github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/gobuffalo/events v1.4.0 h1:Vje/vgTWs+dyhIS0U03oLpvx1SUdAqutv/hDWIz2ErM= -github.com/gobuffalo/events v1.4.0/go.mod h1:gQbNh681BwO+urxPpHHBiVD8Y+2lg17Wj2xuCMMKr8E= -github.com/gobuffalo/here v0.4.0/go.mod h1:bTNk/uKZgycuB358iR0D32dI9kHBClBGpXjW2HVHkNo= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= -github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= -github.com/markbates/grift v1.5.0 h1:CZyK0k+8BdhQMgbwzuKMysC12y4tf9H004jAs/FutX4= -github.com/markbates/grift v1.5.0/go.mod h1:1ssFm5gSGmzTkhi3Wfh/nqlU74J73TlAjoDMttQbpfY= github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA= github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= @@ -45,23 +34,18 @@ github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb6 github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg= github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= -github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a h1:1n5lsVfiQW3yfsRGu98756EH1YthsFqr/5mxHduZW2A= golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo= gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/grifts/release.go b/grifts/release.go deleted file mode 100644 index 28f30b9..0000000 --- a/grifts/release.go +++ /dev/null @@ -1,139 +0,0 @@ -package grifts - -import ( - "bytes" - "encoding/json" - "errors" - "fmt" - "io" - "io/ioutil" - "net/http" - "os" - "os/exec" - "path/filepath" - "regexp" - - . "github.com/markbates/grift/grift" -) - -var _ = Desc("release", "Generates a CHANGELOG and creates a new GitHub release based on what is in the version.go file.") -var _ = Add("release", func(c *Context) error { - Run("shoulders", c) - v, err := findVersion() - if err != nil { - return err - } - - err = installBin() - if err != nil { - return err - } - - // err = localTest() - // if err != nil { - // return err - // } - // - err = tagRelease(v) - if err != nil { - return err - } - - err = runChangelogGenerator(v) - if err != nil { - return err - } - - return commitAndPush(v) -}) - -func installBin() error { - cmd := exec.Command("go", "install", "-v", ".") - cmd.Stdin = os.Stdin - cmd.Stderr = os.Stderr - cmd.Stdout = os.Stdout - return cmd.Run() -} - -func localTest() error { - cmd := exec.Command("go", "test", "-v", "./...") - cmd.Stdin = os.Stdin - cmd.Stderr = os.Stderr - cmd.Stdout = os.Stdout - return cmd.Run() -} - -func tagRelease(v string) error { - token := os.Getenv("GITHUB_TOKEN") - if token == "" { - return errors.New("GITHUB_TOKEN is not set!!") - } - - body := map[string]interface{}{ - "tag_name": fmt.Sprintf("v%s", v), - "prerelease": false, - } - - b, err := json.Marshal(&body) - if err != nil { - return err - } - - res, err := http.Post(fmt.Sprintf("https://api.github.com/repos/markbates/refresh/releases?access_token=%s", token), "application/json", bytes.NewReader(b)) - if err != nil { - return err - } - - code := res.StatusCode - if code < 200 || code >= 300 { - io.Copy(os.Stderr, res.Body) - return fmt.Errorf("got a not successful status code from github! %d", code) - } - - return nil -} - -func runChangelogGenerator(v string) error { - cmd := exec.Command("github_changelog_generator") - cmd.Stdin = os.Stdin - cmd.Stderr = os.Stderr - cmd.Stdout = os.Stdout - return cmd.Run() -} - -func commitAndPush(v string) error { - cmd := exec.Command("git", "commit", "CHANGELOG.md", "-m", fmt.Sprintf("Updated changelog for release v%s", v)) - cmd.Stdin = os.Stdin - cmd.Stderr = os.Stderr - cmd.Stdout = os.Stdout - err := cmd.Run() - if err != nil { - return err - } - - cmd = exec.Command("git", "push", "origin", "master") - cmd.Stdin = os.Stdin - cmd.Stderr = os.Stderr - cmd.Stdout = os.Stdout - return cmd.Run() -} - -func findVersion() (string, error) { - pwd, err := os.Getwd() - if err != nil { - return "", err - } - vfile, err := ioutil.ReadFile(filepath.Join(pwd, "./cmd/version.go")) - if err != nil { - return "", err - } - - //var Version = "0.4.0" - re := regexp.MustCompile(`const Version = "(.+)"`) - matches := re.FindStringSubmatch(string(vfile)) - if len(matches) < 2 { - return "", errors.New("failed to find the version!") - } - v := matches[1] - return v, nil -} diff --git a/refresh/events.go b/refresh/events.go deleted file mode 100644 index e8b6ab4..0000000 --- a/refresh/events.go +++ /dev/null @@ -1,8 +0,0 @@ -package refresh - -const ( - EvtRaw = "refresh:raw" - EvtBuildStarted = "refresh:build:started" - EvtBuildFinished = "refresh:build:finished" - EvtErrBuild = "refresh:build:err" -) diff --git a/refresh/manager.go b/refresh/manager.go index e85768d..7c7c160 100644 --- a/refresh/manager.go +++ b/refresh/manager.go @@ -11,7 +11,6 @@ import ( "time" "github.com/fsnotify/fsnotify" - "github.com/gobuffalo/events" ) type Manager struct { @@ -51,7 +50,6 @@ func (r *Manager) Start() error { for { select { case event := <-w.Events(): - events.EmitPayload(EvtRaw, events.Payload{"event": event}) if event.Op != fsnotify.Chmod { go r.build(event) } @@ -85,24 +83,16 @@ func (r *Manager) build(event fsnotify.Event) { r.buildTransaction(func() error { // time.Sleep(r.BuildDelay * time.Millisecond) - payload := events.Payload{ - "event": event, - } - now := time.Now() r.Logger.Print("Rebuild on: %s", event.Name) args := []string{"build", "-v"} args = append(args, r.BuildFlags...) args = append(args, "-o", r.FullBuildPath(), r.BuildTargetPath) - cmd := exec.Command("go", args...) - payload["cmd"] = cmd.Args - - events.EmitPayload(EvtBuildStarted, payload) + cmd := exec.CommandContext(r.context, "go", args...) err := r.runAndListen(cmd) if err != nil { - events.EmitError(EvtErrBuild, err, payload) if strings.Contains(err.Error(), "no buildable Go source files") { r.cancelFunc() log.Fatal(err) @@ -111,9 +101,6 @@ func (r *Manager) build(event fsnotify.Event) { } tt := time.Since(now) - payload["pid"] = cmd.Process.Pid - payload["build_time"] = tt - events.EmitPayload(EvtBuildFinished, payload) r.Logger.Success("Building Completed (PID: %d) (Time: %s)", cmd.Process.Pid, tt) r.Restart <- true return nil