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
18 changes: 9 additions & 9 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ name: Check Pull Request
on:
pull_request:
paths:
- '.github/**'
- 'cmd/**'
- 'internal/**'
- 'pkg/**'
- 'go.mod'
- 'go.sum'
- ".github/**"
- "cmd/**"
- "internal/**"
- "pkg/**"
- "go.mod"
- "go.sum"
env:
GOLANGCI_LINT_VERSION: "v1.61.0"
GO_VERSION: "^1.23.0"
GOLANGCI_LINT_VERSION: "v2.12"
GO_VERSION: "^1.26.0"
jobs:
lint:
runs-on: ubuntu-latest
Expand All @@ -30,7 +30,7 @@ jobs:
go-version: ${{ env.GO_VERSION }}
cache-dependency-path: go.sum
- name: golangci-lint
uses: golangci/golangci-lint-action@v6.2.0
uses: golangci/golangci-lint-action@v9
with:
version: ${{ env.GOLANGCI_LINT_VERSION }}
test:
Expand Down
20 changes: 20 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,22 @@
version: "2"
run:
tests: false
linters:
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
paths:
- third_party$
- builtin$
- examples$
formatters:
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
42 changes: 35 additions & 7 deletions docs/testdata/gilbert.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,45 @@ inputs:
type: date
optional: true
dateFormat: "2006-01-02 15:04:05"
items:
type: list
items:
type: int
# items:
# type: list
# items:
# type: int

tasks:
# Task to debug task runner
test:
inputs:
# Test message content
message:
type: string

# Signal name
signal:
type: string
default: mysignal

# Throw error?
fail:
type: bool

steps:
- action: githubMod/actionName
- action: debug/signal
with:
signal: ${{inputs.signal}}
fail: ${{inputs.fail}}
on:
mysignal:
- action: debug/echo
with:
message: "message: ${{inputs.message}}, data: ${{toJSON(event)}}"
error:
- action: debug/echo
with:
message: Error happened
- action: debug/echo
with:
key: value
message: next

# Build builds application
build:
Expand All @@ -52,9 +80,9 @@ tasks:
- action: go/build
if: ${{inputs.version != "invalid"}}
timeout: 30s
continue-on-error: false
strategy:
max-parallel: 2
continue-on-error: false
matrix:
os: [windows, linux, darwin]
arch: [amd64, 386, arm64]
Expand Down
12 changes: 1 addition & 11 deletions docs/todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

**loader**

- yamlloader: pass indents from *ast.LiteralNode into expr.DocumentInfo
- yamlloader: pass indents from \*ast.LiteralNode into expr.DocumentInfo
- yamlloader: check if global input flag is reserved for builtin
- yamlloader: check if task input flag is reserved for builtin or global

Expand All @@ -21,13 +21,3 @@

- Support indents in DocumentInfo
- Consider cel-go as it might support dynamic envs: https://github.com/google/cel-go

**uflag**

- Bug when boolean flag w/o value is near other:

```
$ ./gilbert.sh run build --items=1,2,3 --release

error: invalid argument "--log-level=debug" for "--release" flag: strconv.ParseBool: parsing "--log-level=debug": invalid syntax
```
2 changes: 1 addition & 1 deletion gilbert.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ tasks:
steps:
- action: go/build
timeout: 30s
continue-on-error: false
strategy:
max-parallel: 2
continue-on-error: false
matrix:
os: [windows, linux, darwin]
arch: [amd64, 386, arm64]
Expand Down
2 changes: 1 addition & 1 deletion internal/manifest/file.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package manifest

const (
// FileName is default manifest filename
// FileName is default manifest filename.
FileName = "gilbert.yaml"
)

Expand Down
9 changes: 9 additions & 0 deletions internal/manifest/loader.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package manifest

import (
"errors"
"fmt"
"io/fs"
"os"
"path/filepath"

Expand Down Expand Up @@ -55,6 +57,13 @@ func LoadManifest(path string) (*Manifest, error) {

// FromDirectory loads gilbert.yaml from specified directory
func FromDirectory(dir string) (m *Manifest, err error) {
// Both .yaml and .yml are valid extensions.
location := filepath.Join(dir, FileName)
if _, err := os.Stat(location); err != nil {
if errors.Is(err, fs.ErrNotExist) {
location = filepath.Join(dir, "gilbert.yml")
}
}

return LoadManifest(location)
}
11 changes: 11 additions & 0 deletions internal/v2/actions/debug/actions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Package debug provides actions for debugging the runner.
package debug

import (
"github.com/go-gilbert/gilbert/internal/v2/engine"
)

var Actions = map[string]engine.ActionHandlerConstructor{
"signal": newSignalActionHandler,
"echo": newEchoActionHandler,
}
51 changes: 51 additions & 0 deletions internal/v2/actions/debug/echo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package debug

import (
"context"
"errors"

"github.com/go-gilbert/gilbert/internal/v2/engine"
"github.com/go-gilbert/gilbert/internal/v2/log"
"github.com/go-gilbert/gilbert/internal/v2/manifest"

. "github.com/go-gilbert/gilbert/internal/v2/manifest/argschema"

Check failure on line 11 in internal/v2/actions/debug/echo.go

View workflow job for this annotation

GitHub Actions / lint

ST1001: should not use dot imports (staticcheck)
)

var echoSchema = Struct(
StringField("message", func(dst *echoArgs, val string) error {
if val == "" {
return errors.New("message name is required")
}

dst.message = val
return nil
}).Required(),
)

type echoArgs struct {
message string
}

type echoActionHandler struct {
logger log.Logger
args echoArgs
}

func newEchoActionHandler(ctx context.Context, ref manifest.JobHandlerRef, params engine.ActionParams) engine.HandlerResult {
args, diags := MapArgsToStruct(ctx, params, echoSchema)
if diags.HasError() {
return engine.NewBadActionParamsResult(ref, diags)
}

h := &echoActionHandler{
logger: params.Logger,
args: args,
}

return engine.NewHandlerResult(h, diags)
}

func (h *echoActionHandler) HandleAction(ctx context.Context, emitter engine.SignalEmitter) error {
h.logger.Info(h.args.message)
return nil
}
63 changes: 63 additions & 0 deletions internal/v2/actions/debug/signaltest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package debug

import (
"context"
"errors"

"github.com/go-gilbert/gilbert/internal/v2/engine"
"github.com/go-gilbert/gilbert/internal/v2/log"
"github.com/go-gilbert/gilbert/internal/v2/manifest"

. "github.com/go-gilbert/gilbert/internal/v2/manifest/argschema"

Check failure on line 11 in internal/v2/actions/debug/signaltest.go

View workflow job for this annotation

GitHub Actions / lint

ST1001: should not use dot imports (staticcheck)
)

var signalSchema = Struct(
StringField("signal", func(dst *signalActionArgs, val string) error {
if val == "" {
return errors.New("signal name is required")
}

dst.signalName = val
return nil
}).Required(),
BoolField("fail", func(dst *signalActionArgs, val bool) error {
dst.fail = val
return nil
}),
)

type signalActionArgs struct {
signalName string
fail bool
}

type signalActionHandler struct {
logger log.Logger
args signalActionArgs
}

func newSignalActionHandler(ctx context.Context, ref manifest.JobHandlerRef, params engine.ActionParams) engine.HandlerResult {
args, diags := MapArgsToStruct(ctx, params, signalSchema)
if diags.HasError() {
return engine.NewBadActionParamsResult(ref, diags)
}

h := &signalActionHandler{
logger: params.Logger,
args: args,
}

return engine.NewHandlerResult(h, diags)
}

func (h *signalActionHandler) HandleAction(ctx context.Context, emitter engine.SignalEmitter) error {
if h.args.fail {
return errors.New("test error from action handler")
}

err := emitter.EmitSignal(ctx, h.args.signalName, map[string]any{
"message": "test signal",
})

return err
}
4 changes: 1 addition & 3 deletions internal/v2/actions/golang/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func NewBuildActionHandler(ctx context.Context, ref manifest.JobHandlerRef, para
return engine.NewHandlerResult(h, diags)
}

func (b *BuildActionHandler) HandleAction(ctx context.Context) error {
func (b *BuildActionHandler) HandleAction(ctx context.Context, emitter engine.SignalEmitter) error {
argv, err := b.args.commandArgs()
if err != nil {
return err
Expand Down Expand Up @@ -69,8 +69,6 @@ func (b *BuildActionHandler) HandleAction(ctx context.Context) error {
return fmt.Errorf("failed to start go command: %w", err)
}

b.logger.Infof("building %s", b.args.PackageName)

if err := cmd.Wait(); err != nil {
return executil.FormatExitError(err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/v2/actions/golang/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func NewRunActionHandler(ctx context.Context, ref manifest.JobHandlerRef, params
return engine.NewHandlerResult(h, diags)
}

func (b *RunActionHandler) HandleAction(ctx context.Context) error {
func (b *RunActionHandler) HandleAction(ctx context.Context, emitter engine.SignalEmitter) error {
argv, err := b.args.commandArgs()
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion internal/v2/actions/os/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func NewProcessActionHandler(ctx context.Context, ref manifest.JobHandlerRef, pa
return engine.NewHandlerResult(h, diags)
}

func (h *ProcessActionHandler) HandleAction(ctx context.Context) error {
func (h *ProcessActionHandler) HandleAction(ctx context.Context, emitter engine.SignalEmitter) error {
cmd := exec.CommandContext(ctx, h.args.Path, h.args.Args...)
cmd.Env = executil.MergeEnv(h.args.Env, h.globals.Env)
cmd.Dir = h.globals.Project.WorkDir
Expand Down
2 changes: 1 addition & 1 deletion internal/v2/actions/os/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func NewShellActionHandler(ctx context.Context, ref manifest.JobHandlerRef, para
return engine.NewHandlerResult(h, diags)
}

func (s *ShellActionHandler) HandleAction(ctx context.Context) error {
func (s *ShellActionHandler) HandleAction(ctx context.Context, emitter engine.SignalEmitter) error {
cmd := exec.CommandContext(ctx, s.args.Shell, s.args.ShellCommand, s.args.Command)
cmd.Env = executil.MergeEnv(s.args.Env, s.globals.Env)
cmd.Dir = s.globals.Project.WorkDir
Expand Down
6 changes: 4 additions & 2 deletions internal/v2/actions/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package actions
import (
"context"

"github.com/go-gilbert/gilbert/internal/v2/actions/debug"
"github.com/go-gilbert/gilbert/internal/v2/actions/golang"
"github.com/go-gilbert/gilbert/internal/v2/actions/os"
"github.com/go-gilbert/gilbert/internal/v2/engine"
Expand All @@ -14,8 +15,9 @@ var (
Provider engine.ActionHandlerProvider = ActionHandlerProvider{}

namespaces = map[string]map[string]engine.ActionHandlerConstructor{
"go": golang.Actions,
"os": os.Actions,
"go": golang.Actions,
"os": os.Actions,
"debug": debug.Actions,
}
)

Expand Down
Loading
Loading