Skip to content

Commit 06691b7

Browse files
authored
Integrate go-reportcard (#63)
* Run gofmt * Add golint * Add badge
1 parent 780774f commit 06691b7

26 files changed

+134
-113
lines changed

.travis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ go_import_path: github.com/goeuro/myke
33
go:
44
- 1.7
55
install:
6-
- go get -u -v github.com/tools/godep
7-
- go get -u -v github.com/mitchellh/gox
8-
- go get -u -v github.com/jteeuwen/go-bindata/...
9-
- godep restore -v
6+
- bin/init.sh
107
script:
8+
- gofmt -d -s -e . 2>&1 | tee -a fmt.out
9+
- test ! -s fmt.out
10+
- golint -set_exit_status .
1111
- go test ./...
1212
- bin/cross-compile.sh "$TRAVIS_TAG-$TRAVIS_COMMIT"
1313
deploy:

Dockerfile

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
FROM golang:1.7
22

33
WORKDIR /go/src/github.com/goeuro/myke
4-
COPY Godeps /go/src/github.com/goeuro/myke/Godeps
5-
RUN go get -u -v github.com/tools/godep && \
6-
go get -u -v github.com/mitchellh/gox && \
7-
go get -u -v github.com/jteeuwen/go-bindata/... && \
8-
godep restore -v
4+
COPY Godeps Godeps
5+
COPY bin/init.sh bin/
6+
RUN bin/init.sh
97

108
COPY . /go/src/github.com/goeuro/myke
119
CMD ["bin/cross-compile.sh"]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# myke [![Build Status](https://travis-ci.org/goeuro/myke.svg?branch=travis-ci)](https://travis-ci.org/goeuro/myke) [![Latest Release](https://img.shields.io/github/tag/goeuro/myke.svg)](https://github.com/goeuro/myke/releases/latest)
1+
# myke [![Build Status](https://travis-ci.org/goeuro/myke.svg?branch=travis-ci)](https://travis-ci.org/goeuro/myke) [![Latest Release](https://img.shields.io/github/tag/goeuro/myke.svg)](https://github.com/goeuro/myke/releases/latest) [![Go Report Card](https://goreportcard.com/badge/github.com/goeuro/myke)](https://goreportcard.com/report/github.com/goeuro/myke)
22

33
> myke makes it easy to write development tasks
44

bin/init.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
set -xe
3+
go get -u -v github.com/golang/lint/golint
4+
go get -u -v github.com/tools/godep
5+
go get -u -v github.com/mitchellh/gox
6+
go get -u -v github.com/jteeuwen/go-bindata/...
7+
godep restore -v

cmd/license.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package cmd
22

33
import (
4-
"gopkg.in/urfave/cli.v1"
4+
"fmt"
55
"github.com/goeuro/myke/core"
66
"github.com/pkg/errors"
7-
"fmt"
7+
"gopkg.in/urfave/cli.v1"
88
)
99

10+
// License prints all open source licenses
1011
func License(c *cli.Context) error {
1112
data, err := core.Asset("tmp/LICENSES")
1213
if err != nil {

cmd/list.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package cmd
22

33
import (
4-
"gopkg.in/urfave/cli.v1"
54
"github.com/rdsubhas/go-elastictable"
6-
"strings"
5+
"gopkg.in/urfave/cli.v1"
76
"sort"
7+
"strings"
88
)
99

1010
var headers = []string{"PROJECT", "TAGS", "TASKS"}
1111

12+
// List lists tasks
1213
func List(c *cli.Context) error {
1314
w := loadWorkspace(c.String("file"))
1415
t := elastictable.NewElasticTable(headers)

cmd/root.go

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,46 @@
11
package cmd
22

33
import (
4-
"gopkg.in/urfave/cli.v1"
5-
"github.com/goeuro/myke/core"
64
"github.com/apex/log"
75
logcli "github.com/apex/log/handlers/cli"
6+
"github.com/goeuro/myke/core"
7+
"gopkg.in/urfave/cli.v1"
8+
"os"
89
"path/filepath"
910
"strings"
10-
"os"
1111
)
1212

13+
// NewApp creates a new CLI app
1314
func NewApp() *cli.App {
1415
app := cli.NewApp()
1516
app.Name = "myke"
1617
app.Version = Version()
1718
app.Usage = "make with yml"
1819
app.Action = Action
19-
app.Flags = []cli.Flag {
20+
app.Flags = []cli.Flag{
2021
cli.StringFlag{
21-
Name: "f, file",
22-
Value: "myke.yml",
23-
Usage: "`yml-file` to load",
22+
Name: "f, file",
23+
Value: "myke.yml",
24+
Usage: "`yml-file` to load",
2425
},
2526
cli.StringFlag{
26-
Name: "template",
27-
Usage: "render template `tpl-file` (will not run any command)",
27+
Name: "template",
28+
Usage: "render template `tpl-file` (will not run any command)",
2829
},
2930
cli.BoolFlag{
30-
Name: "license",
31-
Usage: "show license",
31+
Name: "license",
32+
Usage: "show license",
3233
},
3334
cli.StringFlag{
34-
Name: "loglevel",
35+
Name: "loglevel",
3536
Value: "info",
3637
Usage: "log level, one of debug|`info`|warn|error|fatal",
3738
},
3839
}
3940
return app
4041
}
4142

43+
// Action is the CLI entrypoint
4244
func Action(c *cli.Context) error {
4345
log.SetHandler(&logcli.Handler{Writer: os.Stdout, Padding: 0})
4446
if level, err := log.ParseLevel(c.String("loglevel")); err == nil {
@@ -51,11 +53,12 @@ func Action(c *cli.Context) error {
5153
return License(c)
5254
} else if c.NArg() > 0 {
5355
return Run(c)
54-
} else {
55-
return List(c)
5656
}
57+
58+
return List(c)
5759
}
5860

61+
// Version prints myke version
5962
func Version() string {
6063
version, _ := core.Asset("tmp/version")
6164
return strings.TrimSpace(string(version))

cmd/run.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package cmd
22

33
import (
4-
"gopkg.in/urfave/cli.v1"
54
"github.com/goeuro/myke/core"
65
"github.com/pkg/errors"
6+
"gopkg.in/urfave/cli.v1"
77
)
88

9+
// Run runs the given tasks
910
func Run(c *cli.Context) error {
1011
qs := make([]string, len(c.Args()))
1112
for i, v := range c.Args() {

cmd/template.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package cmd
22

33
import (
4-
"gopkg.in/urfave/cli.v1"
4+
"fmt"
55
"github.com/goeuro/myke/core"
66
"github.com/pkg/errors"
7-
"fmt"
7+
"gopkg.in/urfave/cli.v1"
88
"io/ioutil"
99
)
1010

11+
// Template renders the given template file
1112
func Template(c *cli.Context) error {
1213
bytes, err := ioutil.ReadFile(c.String("template"))
1314
if err != nil {

core/bindata.go

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/execution.go

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
package core
22

33
import (
4+
"errors"
45
"github.com/apex/log"
56
"github.com/kardianos/osext"
67
"os"
78
"os/exec"
8-
"time"
99
"strings"
10-
"errors"
10+
"time"
1111
)
1212

13+
// Execution represents a task and context being invoked
1314
type Execution struct {
1415
Workspace *Workspace
1516
Query *Query
1617
Project *Project
1718
Task *Task
1819
}
1920

21+
// ExecuteQuery executes the given query in the workspace
2022
func ExecuteQuery(w *Workspace, q Query) error {
21-
matches := q.Search(w)
23+
matches := q.search(w)
2224
if len(matches) == 0 {
2325
return errors.New("no task matched: " + q.Raw)
2426
}
@@ -37,6 +39,7 @@ func ExecuteQuery(w *Workspace, q Query) error {
3739
return nil
3840
}
3941

42+
// Execute executes the current task
4043
func (e *Execution) Execute() error {
4144
start := time.Now()
4245
displayName := e.Project.Name + "/" + e.Task.Name
@@ -54,7 +57,6 @@ func (e *Execution) Execute() error {
5457
elapsed := time.Since(start)
5558
if err != nil {
5659
log.Errorf("%v/%v: Failed, Took: %v", e.Project.Name, e.Task.Name, elapsed)
57-
return err
5860
} else {
5961
log.Infof("%v: Completed, Took: %v", displayName, elapsed)
6062
}
@@ -82,39 +84,39 @@ func (e *Execution) executeCmd(cmd string) error {
8284
return err
8385
}
8486

85-
shell := []string{"sh", "-exc",}
87+
shell := []string{"sh", "-exc"}
8688
if len(e.Task.Shell) > 0 {
8789
shell = strings.Split(strings.TrimSpace(e.Task.Shell), " ")
8890
}
8991
shell = append(shell, cmd)
9092

9193
proc := exec.Command(shell[0], shell[1:]...)
9294
proc.Dir = e.Project.Cwd
93-
proc.Env = e.EnvList()
95+
proc.Env = e.envList()
9496
proc.Stdin = os.Stdin
9597
proc.Stdout = os.Stdout
9698
proc.Stderr = os.Stderr
9799
return proc.Run()
98100
}
99101

100-
func (e *Execution) Env() map[string]string {
102+
func (e *Execution) env() map[string]string {
101103
myke, _ := osext.Executable()
102104
extraEnv := map[string]string{
103-
"myke": myke,
105+
"myke": myke,
104106
"MYKE_PROJECT": e.Project.Name,
105-
"MYKE_TASK": e.Task.Name,
106-
"MYKE_CWD": e.Project.Cwd,
107+
"MYKE_TASK": e.Task.Name,
108+
"MYKE_CWD": e.Project.Cwd,
107109
}
108110
env := mergeEnv(mergeEnv(e.Project.Env, extraEnv), OsEnv())
109-
env["PATH"] = strings.Join([]string{ env["PATH"], os.Getenv("PATH") }, PathSep)
111+
env["PATH"] = strings.Join([]string{env["PATH"], os.Getenv("PATH")}, pathSep)
110112
return env
111113
}
112114

113-
func (e *Execution) EnvList() []string {
114-
env := e.Env()
115-
envList := make([]string, len(env))
115+
func (e *Execution) envList() []string {
116+
env := e.env()
117+
list := make([]string, len(env))
116118
for k, v := range env {
117-
envList = append(envList, k+"="+v)
119+
list = append(list, k+"="+v)
118120
}
119-
return envList
121+
return list
120122
}

core/project.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ import (
66

77
"io/ioutil"
88
"path/filepath"
9-
"strings"
109
"sort"
10+
"strings"
1111
)
1212

13+
// Project represents a parsed project
1314
type Project struct {
1415
Src string
1516
Cwd string
@@ -23,6 +24,7 @@ type Project struct {
2324
Tasks map[string]Task
2425
}
2526

27+
// ParseProject parses the given project
2628
func ParseProject(path string) (Project, error) {
2729
src, err := filepath.Abs(path)
2830
if err != nil {
@@ -33,17 +35,17 @@ func ParseProject(path string) (Project, error) {
3335
return ParseProject(filepath.Join(src, "myke.yml"))
3436
}
3537

36-
p, err := loadProjectYaml(src)
38+
p, err := loadProjectYAML(src)
3739
if err != nil {
3840
return Project{}, err
3941
}
4042

4143
p.Src = src
4244
p.Cwd = filepath.Dir(src)
43-
p.EnvFiles = append(p.EnvFiles, strings.TrimSuffix(src, ".yml") + ".env")
45+
p.EnvFiles = append(p.EnvFiles, strings.TrimSuffix(src, ".yml")+".env")
4446
for _, epath := range p.EnvFiles {
4547
p.Env = mergeEnv(p.Env, loadEnvFile(normalizeFilePath(p.Cwd, epath)))
46-
p.Env = mergeEnv(p.Env, loadEnvFile(normalizeFilePath(p.Cwd, epath + ".local")))
48+
p.Env = mergeEnv(p.Env, loadEnvFile(normalizeFilePath(p.Cwd, epath+".local")))
4749
}
4850

4951
p.Env = mergeEnv(p.Env, OsEnv())
@@ -58,7 +60,7 @@ func ParseProject(path string) (Project, error) {
5860
return p, nil
5961
}
6062

61-
func loadProjectYaml(path string) (Project, error) {
63+
func loadProjectYAML(path string) (Project, error) {
6264
bytes, err := ioutil.ReadFile(path)
6365
if err != nil {
6466
return Project{}, err
@@ -70,10 +72,10 @@ func loadProjectYaml(path string) (Project, error) {
7072
}
7173

7274
json := gjson.Parse(string(jsonbytes))
73-
return loadProjectJson(json), nil
75+
return loadProjectJSON(json), nil
7476
}
7577

76-
func loadProjectJson(json gjson.Result) Project {
78+
func loadProjectJSON(json gjson.Result) Project {
7779
p := Project{}
7880
if j := json.Get("project"); j.Exists() {
7981
p.Name = j.String()
@@ -111,7 +113,7 @@ func loadProjectJson(json gjson.Result) Project {
111113
p.Tasks = make(map[string]Task)
112114
if j := json.Get("tasks"); j.Exists() {
113115
for k, v := range j.Map() {
114-
p.Tasks[k] = loadTaskJson(k, v)
116+
p.Tasks[k] = loadTaskJSON(k, v)
115117
}
116118
}
117119
return p

0 commit comments

Comments
 (0)