Skip to content

Commit

Permalink
Merge pull request #66 from go-gilbert/dev
Browse files Browse the repository at this point in the history
Release: 1.0.0
  • Loading branch information
x1unix authored Jun 11, 2019
2 parents 35e560d + 1cdfca0 commit d3c261a
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 40 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ install: true

before_install:
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.16.0
- curl https://raw.githubusercontent.com/go-gilbert/gilbert/master/install.sh | sh

script:
- go vet ./...
- golangci-lint run
- go test ./...
- go build -o ./gilbert-dev
- ./gilbert-dev run build
- gilbert run cover
- gilbert run build
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

> Build toolchain and task runner for Go
This project is currently in early development stage. Bug reports and pull requests are welcome.

## Features

**Gilbert** is task runner that aims to provide declarative way to define and run tasks like in other projects like _Gradle_, _Maven_ and etc.
Expand Down
18 changes: 1 addition & 17 deletions cli/scaffold/scaffold.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ import (
"io/ioutil"
"os"
"path/filepath"
"strings"

"github.com/go-gilbert/gilbert-sdk"
"github.com/go-gilbert/gilbert/log"

"github.com/go-gilbert/gilbert/manifest"
"github.com/urfave/cli"
"gopkg.in/yaml.v2"
Expand Down Expand Up @@ -54,15 +52,13 @@ var boilerplate = manifest.Manifest{
}

// RunScaffoldManifest handles 'init' command
func RunScaffoldManifest(c *cli.Context) (err error) {
func RunScaffoldManifest(_ *cli.Context) (err error) {
cwd, err := os.Getwd()
if err != nil {
return fmt.Errorf("cannot get current working directory, %s", err)
}

log.Default.Debugf("current working directory is '%s'", cwd)
ensureGoPath(cwd)

out, err := yaml.Marshal(boilerplate)
if err != nil {
return fmt.Errorf("cannot create YAML file: %s", err)
Expand All @@ -78,15 +74,3 @@ func RunScaffoldManifest(c *cli.Context) (err error) {
log.Default.Info("Use 'gilbert run build' to build the project")
return nil
}

func ensureGoPath(cwd string) {
goPath := os.Getenv("GOPATH")
if goPath == "" {
log.Default.Warn("Warning: GOPATH environment variable is not defined")
return
}

if !strings.Contains(cwd, goPath) {
log.Default.Warnf("Current directory is outside GOPATH (%s)", goPath)
}
}
2 changes: 1 addition & 1 deletion gilbert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ imports:

vars:
buildDir: './build'
version: '0.11.0'
version: '1.0.0'
commit: '{% git log --format=%H -n 1 %}'

mixins:
Expand Down
9 changes: 8 additions & 1 deletion log/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,16 @@ const (
)

// consoleLogWriter is console logger
type consoleWriter struct{}
type consoleWriter struct {
noColor bool
}

func (c *consoleWriter) Write(level int, message string) {
if c.noColor {
fmt.Print(message)
return
}

switch level {
case LevelInfo:
color.Blue(message)
Expand Down
4 changes: 2 additions & 2 deletions log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import "github.com/go-gilbert/gilbert-sdk"
var Default sdk.Logger

// UseConsoleLogger bootstraps console logger as default log instance
func UseConsoleLogger(level int) {
func UseConsoleLogger(level int, noColor bool) {
Default = &logger{
level: level,
formatter: &paddingFormatter{},
writer: &consoleWriter{},
writer: &consoleWriter{noColor: noColor},
}
}
30 changes: 21 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,23 @@ var (
commit = "local build"
)

// unfortunately, uface/cli ignores '--verbose' global flag :(
// so it should be defined implicitly in each task
var verboseFlag = cli.BoolFlag{
Name: "verbose",
Usage: "shows debug information, useful for troubleshooting",
Destination: &scope.Debug,
}
// FlagNoColor disables color output
const FlagNoColor = "no-color"

var (
// unfortunately, urfave/cli ignores '--verbose' global flag :(
// so it should be defined implicitly in each task
verboseFlag = cli.BoolFlag{
Name: "verbose",
Usage: "shows debug information, useful for troubleshooting",
Destination: &scope.Debug,
}

noColorFlag = cli.BoolFlag{
Name: FlagNoColor,
Usage: "disable color output in terminal",
}
)

func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
Expand All @@ -50,6 +60,7 @@ func main() {
Before: bootstrap,
Flags: []cli.Flag{
verboseFlag,
noColorFlag,
cli.StringSliceFlag{
Name: tasks.OverrideVarFlag,
},
Expand Down Expand Up @@ -100,13 +111,14 @@ func main() {
}
}

func bootstrap(_ *cli.Context) error {
func bootstrap(c *cli.Context) error {
level := log.LevelInfo
if scope.Debug {
level = log.LevelDebug
}

log.UseConsoleLogger(level)
noColor := c.Bool(FlagNoColor)
log.UseConsoleLogger(level, noColor)
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion runner/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func TestTaskRunner_Run(t *testing.T) {
assert.Truef(t, r.cancel, "task didn't receive cancel callback on deadline")
diff := uint((r.cancelTime.Sub(r.startTime).Seconds()) * 1000)
const deadlineTime = uint(10)
const permMargin = 1 // On some CI's like AppVeyor, cancel signal can take additional second
const permMargin = 2 // On some CI's like AppVeyor, cancel signal can take additional second
if (diff < deadlineTime-permMargin) || diff > (deadlineTime+permMargin) {
t.Fatalf("was canceled too late (%d msec), want %d", diff, deadlineTime)
}
Expand Down
16 changes: 11 additions & 5 deletions storage/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,35 @@ func homeDirEnv() string {
}

func TestHomeDir(t *testing.T) {
t.Log(os.Unsetenv(StoreVarName))
hdir, err := os.UserHomeDir()
if err != nil {
t.Skipf("cannot run test, user dir unavailable: %s", err)
return
}

envName := homeDirEnv()
cases := map[string]struct {
cases := []struct {
name string
err string
want string
mod func()
}{
"return default cache dir": {
{
name: "return default cache dir",
want: filepath.Join(hdir, homeDirName),
},
"override path from env var": {
{
name: "override path from env var",
want: "testdata",
mod: func() {
_ = os.Setenv(StoreVarName, "testdata")
},
},
}

for name, c := range cases {
t.Run(name, func(t *testing.T) {
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
if c.mod != nil {
c.mod()
}
Expand All @@ -64,6 +68,7 @@ func TestHomeDir(t *testing.T) {
}

func TestPath(t *testing.T) {
t.Log(os.Unsetenv(StoreVarName))
t.Log(os.Setenv(StoreVarName, "testdata"))
_, err := Path(Type(48))
assert.Error(t, err)
Expand All @@ -89,6 +94,7 @@ func TestLocalPath(t *testing.T) {
}

func TestDelete(t *testing.T) {
t.Log(os.Unsetenv(StoreVarName))
t.Log(os.Setenv(StoreVarName, "testdata"))
err := Delete(Type(48))
assert.Error(t, err)
Expand Down

0 comments on commit d3c261a

Please sign in to comment.