Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: go

go:
- "1.12.x"
- "1.23.x"

branches:
only:
Expand Down
59 changes: 0 additions & 59 deletions actions/actions.go

This file was deleted.

2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ clone_folder: c:\gilbert
environment:
GOPATH: c:\gopath
DEPTESTBYPASS501: 1
GOVERSION: 1.12
GOVERSION: 1.23

init:
- git config --global core.autocrlf input
Expand Down
23 changes: 23 additions & 0 deletions cmd/gilbert/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package main

import (
"os"

"github.com/go-gilbert/gilbert/internal/cmd"
)

var (
// These values will override by linker
version = "dev"
commit = "local build"
)

func main() {
app := cmd.NewCmdRoot(cmd.VersionInfo{
Version: version,
Commit: commit,
})

err := app.Run(os.Args)
cmd.Exit(err)
}
2 changes: 2 additions & 0 deletions gilbert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ mixins:
vars:
ext: ''
params:
source: './cmd'
outputPath: '{{buildDir}}/gilbert_{{os}}-{{arch}}{{ext}}'
target:
os: '{{os}}'
Expand Down Expand Up @@ -61,6 +62,7 @@ tasks:
- action: build
description: building project
params:
source: './cmd/...'
variables:
'main.version': '{{ version }}'
'main.commit': '{{ commit }}'
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
github.com/mattn/go-colorable v0.0.9 // indirect
github.com/mattn/go-isatty v0.0.7 // indirect
github.com/mattn/go-runewidth v0.0.4 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/rjeczalik/notify v0.9.2
github.com/stretchr/testify v1.3.0
github.com/urfave/cli v1.20.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
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/rjeczalik/notify v0.9.2 h1:MiTWrPj55mNDHEiIX5YUSKefw/+lCQVoAFmD6oQm5w8=
Expand Down
24 changes: 24 additions & 0 deletions internal/actions/actions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
Package actions contains operations related to action handlers
*/
package actions

import (
"github.com/go-gilbert/gilbert/internal/actions/build"
"github.com/go-gilbert/gilbert/internal/actions/cover"
"github.com/go-gilbert/gilbert/internal/actions/cover/html"
"github.com/go-gilbert/gilbert/internal/actions/pkgget"
"github.com/go-gilbert/gilbert/internal/actions/shell"
"github.com/go-gilbert/gilbert/internal/actions/watch"
"github.com/go-gilbert/gilbert/internal/runner"
)

// BuiltinHandlers contains standard action handlers.
var BuiltinHandlers = runner.ActionHandlers{
"get-package": pkgget.NewAction,
"build": build.NewAction,
"shell": shell.NewAction,
"watch": watch.NewAction,
"cover": cover.NewAction,
"cover:html": html.NewAction,
}
13 changes: 7 additions & 6 deletions actions/build/action.go → internal/actions/build/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@ import (
"os/exec"
"strings"

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

"github.com/go-gilbert/gilbert/support/shell"
"github.com/go-gilbert/gilbert/internal/runner"
"github.com/go-gilbert/gilbert/internal/runner/job"
"github.com/go-gilbert/gilbert/internal/scope"
"github.com/go-gilbert/gilbert/internal/support/shell"
)

// Action represents Gilbert's plugin
type Action struct {
scope sdk.ScopeAccessor
scope *scope.Scope
cmd *exec.Cmd
params Params
}

// Call calls a plugin
func (a *Action) Call(ctx sdk.JobContextAccessor, r sdk.JobRunner) (err error) {
func (a *Action) Call(ctx *job.RunContext, _ *runner.TaskRunner) (err error) {
a.cmd, err = a.params.newCompilerProcess(a.scope)
if err != nil {
return err
Expand All @@ -41,7 +42,7 @@ func (a *Action) Call(ctx sdk.JobContextAccessor, r sdk.JobRunner) (err error) {
}

// Cancel cancels build process
func (a *Action) Cancel(ctx sdk.JobContextAccessor) error {
func (a *Action) Cancel(ctx *job.RunContext) error {
if a.cmd != nil {
if err := shell.KillProcessGroup(a.cmd); err != nil {
ctx.Log().Debug(err.Error())
Expand Down
6 changes: 4 additions & 2 deletions actions/build/build.go → internal/actions/build/build.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package build

import (
"github.com/go-gilbert/gilbert-sdk"
"github.com/go-gilbert/gilbert/internal/manifest"
"github.com/go-gilbert/gilbert/internal/runner"
"github.com/go-gilbert/gilbert/internal/scope"
)

// NewAction creates a new build action instance
func NewAction(scope sdk.ScopeAccessor, params sdk.ActionParams) (sdk.ActionHandler, error) {
func NewAction(scope *scope.Scope, params manifest.ActionParams) (runner.ActionHandler, error) {
p := newParams()
if err := params.Unmarshal(&p); err != nil {
return nil, err
Expand Down
14 changes: 7 additions & 7 deletions actions/build/params.go → internal/actions/build/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"runtime"
"strings"

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

"github.com/go-gilbert/gilbert/support"
"github.com/go-gilbert/gilbert/internal/manifest"
"github.com/go-gilbert/gilbert/internal/scope"
"github.com/go-gilbert/gilbert/internal/support"
)

const (
Expand Down Expand Up @@ -53,11 +53,11 @@ type Params struct {
Params LinkerParams
Target CompileTarget
Tags string
Variables sdk.Vars
Variables manifest.Vars
}

// linkerParams generates list of arguments for Go linker
func (p *Params) linkerParams(ctx sdk.ScopeAccessor) (args []string, err error) {
func (p *Params) linkerParams(ctx *scope.Scope) (args []string, err error) {
if p.Params.StripDebugInfo {
args = append(args, "-s", "-w")
}
Expand All @@ -77,7 +77,7 @@ func (p *Params) linkerParams(ctx sdk.ScopeAccessor) (args []string, err error)
}

// buildArgs returns arguments for Go support to build the artifact
func (p *Params) buildArgs(ctx sdk.ScopeAccessor) (args []string, err error) {
func (p *Params) buildArgs(ctx *scope.Scope) (args []string, err error) {
args = []string{"build"}

// Add tags
Expand Down Expand Up @@ -129,7 +129,7 @@ func (p *Params) buildArgs(ctx sdk.ScopeAccessor) (args []string, err error) {
}

// createCompilerProcess creates compiler process to start
func (p *Params) newCompilerProcess(ctx sdk.ScopeAccessor) (*exec.Cmd, error) {
func (p *Params) newCompilerProcess(ctx *scope.Scope) (*exec.Cmd, error) {
args, err := p.buildArgs(ctx)
if err != nil {
return nil, err
Expand Down
31 changes: 15 additions & 16 deletions actions/cover/action.go → internal/actions/cover/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@ import (
"os/exec"
"strings"

"github.com/go-gilbert/gilbert/support/shell"

sdk "github.com/go-gilbert/gilbert-sdk"
"github.com/go-gilbert/gilbert/actions/cover/report"

"github.com/go-gilbert/gilbert/actions/cover/profile"
"github.com/go-gilbert/gilbert/internal/actions/cover/profile"
"github.com/go-gilbert/gilbert/internal/actions/cover/report"
"github.com/go-gilbert/gilbert/internal/log"
"github.com/go-gilbert/gilbert/internal/runner"
"github.com/go-gilbert/gilbert/internal/runner/job"
"github.com/go-gilbert/gilbert/internal/scope"
"github.com/go-gilbert/gilbert/internal/support/shell"
)

// Action is action handler
type Action struct {
scope sdk.ScopeAccessor
scope *scope.Scope
params params
coverFile *os.File
alive bool
}

// Call implements sdk.ActionHandler
func (a *Action) Call(ctx sdk.JobContextAccessor, r sdk.JobRunner) (err error) {
func (a *Action) Call(ctx *job.RunContext, _ *runner.TaskRunner) (err error) {
defer a.clean(ctx)
cmd, err := a.createCoverCommand(ctx)
if err != nil {
Expand Down Expand Up @@ -72,7 +72,7 @@ func (a *Action) Call(ctx sdk.JobContextAccessor, r sdk.JobRunner) (err error) {
return err
}

func (a *Action) printUncoveredItems(l sdk.Logger, fpFmt *report.Formatter) {
func (a *Action) printUncoveredItems(l log.Logger, fpFmt *report.Formatter) {
uncovered, count := fpFmt.UncoveredPackages()
if count == 0 {
l.Debug("cover: no uncovered packages in report")
Expand All @@ -88,7 +88,7 @@ func (a *Action) printUncoveredItems(l sdk.Logger, fpFmt *report.Formatter) {
_, _ = l.Write([]byte(uncovered))
}

func (a *Action) printFailedPackages(l sdk.Logger, fpFmt *report.Formatter) {
func (a *Action) printFailedPackages(l log.Logger, fpFmt *report.Formatter) {
failed, count := fpFmt.FailedTests()
if count == 0 {
l.Debug("cover: no failed tests available in report")
Expand All @@ -100,7 +100,7 @@ func (a *Action) printFailedPackages(l sdk.Logger, fpFmt *report.Formatter) {
_, _ = l.ErrorWriter().Write([]byte(failed))
}

func (a *Action) printReport(ctx sdk.JobContextAccessor, r *profile.Report) {
func (a *Action) printReport(ctx *job.RunContext, r *profile.Report) {
if r.Total <= 0 {
ctx.Log().Warnf("No test files found in packages")
} else {
Expand All @@ -121,7 +121,7 @@ func (a *Action) printReport(ctx sdk.JobContextAccessor, r *profile.Report) {
ctx.Log().Infof("Total coverage: %.2f%%", r.Percentage())
}

func (a *Action) clean(ctx sdk.JobContextAccessor) {
func (a *Action) clean(ctx *job.RunContext) {
if !a.alive {
return
}
Expand All @@ -136,7 +136,7 @@ func (a *Action) clean(ctx sdk.JobContextAccessor) {
ctx.Log().Debugf("cover: removed cover file '%s'", fname)
}

func (a *Action) createCoverCommand(ctx sdk.JobContextAccessor) (*exec.Cmd, error) {
func (a *Action) createCoverCommand(ctx *job.RunContext) (*exec.Cmd, error) {
// pass package names as is, since '-coverpkg' doesn't recognise them in CSV format (go 1.11+)
args := make([]string, 0, len(a.params.Packages)+toolArgsPrefixSize)
args = append(args, "test", "-coverprofile="+a.coverFile.Name(), "-json")
Expand All @@ -156,8 +156,7 @@ func (a *Action) createCoverCommand(ctx sdk.JobContextAccessor) (*exec.Cmd, erro
return cmd, nil
}

// Cancel implements sdk.ActionHandler
func (a *Action) Cancel(ctx sdk.JobContextAccessor) error {
func (a *Action) Cancel(ctx *job.RunContext) error {
a.clean(ctx)
return nil
}
6 changes: 4 additions & 2 deletions actions/cover/cover.go → internal/actions/cover/cover.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import (
"io/ioutil"
"os"

"github.com/go-gilbert/gilbert-sdk"
"github.com/go-gilbert/gilbert/internal/manifest"
"github.com/go-gilbert/gilbert/internal/runner"
"github.com/go-gilbert/gilbert/internal/scope"
)

const coverFilePattern = "gbcover*.out"

// NewAction creates a new cover action handler instance
func NewAction(scope sdk.ScopeAccessor, params sdk.ActionParams) (sdk.ActionHandler, error) {
func NewAction(scope *scope.Scope, params manifest.ActionParams) (runner.ActionHandler, error) {
p := newParams()
if err := params.Unmarshal(&p); err != nil {
return nil, err
Expand Down
Loading