Skip to content
Snippets Groups Projects
Commit 9610e71f authored by Joe Burnett's avatar Joe Burnett Committed by Kamil Trzciński
Browse files

pkg/runner: move `proto.StepCall` to `runner.Params`

parent 2e38f684
No related branches found
No related tags found
1 merge request!11Remove unnecessary dir, work dir and step call in proto
......@@ -11,7 +11,6 @@ import (
"gitlab.com/gitlab-org/step-runner/pkg/context"
"gitlab.com/gitlab-org/step-runner/pkg/runner"
"gitlab.com/gitlab-org/step-runner/pkg/step"
"gitlab.com/gitlab-org/step-runner/proto"
)
var Cmd = &cobra.Command{
......@@ -47,9 +46,9 @@ func run(cmd *cobra.Command, args []string) error {
return fmt.Errorf("creating execution: %w", err)
}
stepCall := &proto.StepCall{}
params := &runner.Params{}
result, err := execution.Run(ctx.Background(), stepDefinition, stepCall, globalCtx)
result, err := execution.Run(ctx.Background(), stepDefinition, params, globalCtx)
if err != nil {
return fmt.Errorf("running execution: %w", err)
}
......
......@@ -18,20 +18,25 @@ type Execution struct {
defs cache.Cache
}
type Params struct {
Inputs map[string]*structpb.Value
Env map[string]string
}
func New(defs cache.Cache) (*Execution, error) {
return &Execution{
defs: defs,
}, nil
}
func (e *Execution) createContext(specDefinition *proto.StepDefinition, stepCall *proto.StepCall, globalCtx *context.Global) (*context.Steps, error) {
func (e *Execution) createContext(specDefinition *proto.StepDefinition, params *Params, globalCtx *context.Global) (*context.Steps, error) {
stepsCtx := context.NewSteps(globalCtx)
stepsCtx.Env = stepCall.Env
stepsCtx.Env = params.Env
stepsCtx.Dir = specDefinition.Dir
// Match inputs with definition
for key, value := range specDefinition.Spec.Spec.Inputs {
callValue := stepCall.Inputs[key]
callValue := params.Inputs[key]
if callValue != nil {
stepsCtx.Inputs[key] = callValue
} else if value.Default != nil {
......@@ -42,7 +47,7 @@ func (e *Execution) createContext(specDefinition *proto.StepDefinition, stepCall
}
// Reject invalid inputs
for key, _ := range stepCall.Inputs {
for key, _ := range params.Inputs {
defValue := specDefinition.Spec.Spec.Inputs[key]
if defValue == nil {
return nil, fmt.Errorf("input %q not found", key)
......@@ -52,8 +57,8 @@ func (e *Execution) createContext(specDefinition *proto.StepDefinition, stepCall
return stepsCtx, nil
}
func (e *Execution) Run(ctx ctx.Context, specDefinition *proto.StepDefinition, stepCall *proto.StepCall, globalCtx *context.Global) (*proto.StepResult, error) {
stepsCtx, err := e.createContext(specDefinition, stepCall, globalCtx)
func (e *Execution) Run(ctx ctx.Context, specDefinition *proto.StepDefinition, params *Params, globalCtx *context.Global) (*proto.StepResult, error) {
stepsCtx, err := e.createContext(specDefinition, params, globalCtx)
if err != nil {
return nil, err
}
......@@ -168,29 +173,29 @@ func (e *Execution) runSteps(result *proto.StepResult, ctx ctx.Context, stepsDef
}
func (e *Execution) runStep(ctx ctx.Context, stepReference *proto.Step, stepsCtx *context.Steps) (*proto.StepResult, error) {
stepCall := &proto.StepCall{}
params := &Params{}
// Expand inputs
stepCall.Inputs = make(map[string]*structpb.Value)
params.Inputs = make(map[string]*structpb.Value)
for k, v := range stepReference.Inputs {
res, resErr := expression.Expand(stepsCtx, v)
if resErr != nil {
return nil, fmt.Errorf("Cannot assign input %q due to error: %s", k, resErr.Error())
}
stepCall.Inputs[k] = res
params.Inputs[k] = res
}
// Clone and expand env
stepCall.Env = make(map[string]string)
params.Env = make(map[string]string)
for k, v := range stepsCtx.Env {
stepCall.Env[k] = v
params.Env[k] = v
}
for k, v := range stepReference.Env {
res, resErr := expression.ExpandString(stepsCtx, v)
if resErr != nil {
return nil, fmt.Errorf("Cannot assign env %q due to error: %s", k, resErr.Error())
}
stepCall.Env[k] = res
params.Env[k] = res
}
stepDefinition, err := e.defs.Get(ctx, stepReference.Step)
......@@ -198,7 +203,7 @@ func (e *Execution) runStep(ctx ctx.Context, stepReference *proto.Step, stepsCtx
return nil, fmt.Errorf("getting step %q definition: %w", stepReference.Name, err)
}
result, err := e.Run(ctx, stepDefinition, stepCall, stepsCtx.Global)
result, err := e.Run(ctx, stepDefinition, params, stepsCtx.Global)
if err != nil {
return nil, err
}
......
......@@ -163,9 +163,9 @@ meet joe who is 42 likes {"characters":["sponge bob","patrick star"]} and is hun
globalCtx.Stdout = &log
globalCtx.Stderr = &log
stepCall := &proto.StepCall{}
params := &Params{}
result, err := runner.Run(ctx.Background(), stepDef, stepCall, globalCtx)
result, err := runner.Run(ctx.Background(), stepDef, params, globalCtx)
if c.wantErr != nil {
require.Equal(t, c.wantErr, err)
} else {
......
This diff is collapsed.
......@@ -50,11 +50,6 @@ message StepDefinition {
string dir = 3;
}
message StepCall {
map<string,google.protobuf.Value> inputs = 1;
map<string,string> env = 2;
}
enum InputType {
spec_type_unspecified = 0;
string = 1;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment