Skip to content
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
go.work.sum -diff
**/go.sum -diff
core/mock/**/*.go -diff
runner-gha/mock/**/*.go -diff
runner-gitea/mock/**/*.go -diff
2 changes: 2 additions & 0 deletions core/mock/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@
//go:generate mockgen -typed -destination=stream/sink.go -source=../pkg/stream/sink.go
//go:generate mockgen -typed -destination=store/git/manager.go -source=../pkg/store/git/manager.go
//go:generate mockgen -typed -destination=store/oci/manager.go -source=../pkg/store/oci/manager.go
//go:generate mockgen -typed -destination=runtime/provider.go -source=../pkg/runtime/provider.go
//go:generate mockgen -typed -destination=runtime/runtime.go -source=../pkg/runtime/runtime.go
package mock
80 changes: 80 additions & 0 deletions core/mock/runtime/provider.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

118 changes: 118 additions & 0 deletions core/mock/runtime/runtime.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 24 additions & 3 deletions core/pkg/executor/action_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import (
"strings"

"drassi.run/core/pkg/model/workflows"
"drassi.run/core/pkg/runtime"
"drassi.run/core/pkg/sandboxer"
"drassi.run/core/pkg/scribe"
"drassi.run/core/pkg/store/git"
"drassi.run/core/util/dig"
"drassi.run/core/util/otel"
"go.opentelemetry.io/otel/trace"
"go.uber.org/dig"
Expand All @@ -40,12 +42,32 @@ func (spec *NodeActionSpec) CreateExecutor(
ctx context.Context, scope *dig.Scope, exec StepExecutor,
) (ActionExecutor, error) {
e := &nodeActionExecutor{spec: spec, sExec: exec}
if err := e.init(ctx, scope); err != nil {
return nil, err
}
return e, nil
}

type nodeActionExecutor struct {
spec *NodeActionSpec
sExec StepExecutor

// injected values
runtime runtime.Runtime
}

func (e *nodeActionExecutor) init(ctx context.Context, scope *dig.Scope) error {
var provider runtime.Provider
if err := xdig.Populate(scope, &provider); err != nil {
return err
}

if rt, err := provider.Get(e.spec.Runtime); err != nil {
return err
} else {
e.runtime = rt
}
return nil
}

func (e *nodeActionExecutor) ActionSpec() ActionSpec {
Expand Down Expand Up @@ -106,7 +128,6 @@ func (e *nodeActionExecutor) execute(stage Stage) ActionRun {

sandbox := e.sExec.Sandbox()
scriptPath := e.computeScriptPath(sandbox.Layout(), stage)
cmd := []string{"node", scriptPath}
inputs := e.sExec.Inputs()

scribe.GroupDetails(ctx, "Run "+e.repr(),
Expand All @@ -123,7 +144,7 @@ func (e *nodeActionExecutor) execute(stage Stage) ActionRun {
paths := e.sExec.JobExecutor().Path()
streams := e.sExec.Streams(ctx, stage)
defer streams.Close()
return sandbox.Execute(ctx, cmd, paths, env, "", streams)
return e.runtime.Run(ctx, scriptPath, paths, env, "", streams)
}
return runActionE(fn)
}
Expand Down Expand Up @@ -160,5 +181,5 @@ func (e *nodeActionExecutor) addSpanAttrs(ctx context.Context, stage Stage) {
}

func (e *nodeActionExecutor) repr() string {
return fmt.Sprintf("node action from %q", gitstore.Location(e.spec.Repo))
return fmt.Sprintf("%s action from %q", e.runtime.Name(), gitstore.Location(e.spec.Repo))
}
62 changes: 62 additions & 0 deletions core/pkg/runtime/provider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* SPDX-FileCopyrightText: (c) 2024 The Drassi Authors
*
* SPDX-License-Identifier: Apache-2.0
*/

package runtime

import (
"fmt"

"drassi.run/core/config"
"drassi.run/core/pkg/sandboxer"
)

type Provider interface {
Get(nameOrAlias string) (Runtime, error)
}

type provider struct {
runtimes map[string]Runtime
aliases map[string]string
}

func NewProvider(sandbox sandboxer.Sandbox, runtimeConfigs map[string]*config.Runtime) (Provider, error) {
p := &provider{
runtimes: make(map[string]Runtime, len(runtimeConfigs)),
aliases: make(map[string]string),
}

for name, cfg := range runtimeConfigs {
if rt, err := NewRuntime(name, sandbox, cfg); err != nil {
return nil, err
} else {
p.runtimes[name] = rt
}

for _, alias := range cfg.Alias {
if existing, ok := p.aliases[alias]; ok {
return nil, fmt.Errorf("duplicate runtime alias %q for %q (already defined in %q)", alias, name, existing)
}
if _, ok := runtimeConfigs[alias]; ok {
return nil, fmt.Errorf("runtime alias %q for %q conflicts with existing runtime name", alias, name)
}
p.aliases[alias] = name
}
}

return p, nil
}

func (p *provider) Get(nameOrAlias string) (Runtime, error) {
name := nameOrAlias
if n, ok := p.aliases[name]; ok {
name = n
}
if rt, ok := p.runtimes[name]; ok {
return rt, nil
}

return nil, fmt.Errorf("unsupported runtime %q", nameOrAlias)
}
Loading