-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Workflow bundling for runtime #4
Changes from all commits
5735492
3f564b4
50a4181
9cdfb8c
04fbe28
c1c9572
83a0118
b86fc17
900fc48
abc4b39
4a5ae01
aeff3ce
f3e0344
c544d0f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -23,8 +23,44 @@ type ( | |||||||||||||||||||||||||||||||||||
Context map[string]interface{} `json:"context"` | ||||||||||||||||||||||||||||||||||||
ExitResult interface{} `json:"exit_result"` | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
introspectedExport struct { | ||||||||||||||||||||||||||||||||||||
value interface{} | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
introspectionResult struct { | ||||||||||||||||||||||||||||||||||||
exports map[string]introspectedExport | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
// HasExport implements runtime_registry.IntrospectedExport. | ||||||||||||||||||||||||||||||||||||
func (i introspectedExport) HasExport() bool { | ||||||||||||||||||||||||||||||||||||
return i.value != nil | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
// Value implements runtime_registry.IntrospectedExport. | ||||||||||||||||||||||||||||||||||||
func (i introspectedExport) Value() interface{} { | ||||||||||||||||||||||||||||||||||||
return i.value | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
// ValueAsMap implements runtime_registry.IntrospectedExport. | ||||||||||||||||||||||||||||||||||||
func (i introspectedExport) ValueAsMap() map[string]interface{} { | ||||||||||||||||||||||||||||||||||||
if i.value == nil { | ||||||||||||||||||||||||||||||||||||
return map[string]interface{}{} | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
return i.value.(map[string]interface{}) | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
Comment on lines
+45
to
+51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider safer type assertion in ValueAsMap method The Consider using a type assertion with the func (i introspectedExport) ValueAsMap() map[string]interface{} {
if i.value == nil {
return map[string]interface{}{}
}
- return i.value.(map[string]interface{})
+ if m, ok := i.value.(map[string]interface{}); ok {
+ return m
+ }
+ return map[string]interface{}{}
} Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
// GetExport implements runtime_registry.IntrospectionResult. | ||||||||||||||||||||||||||||||||||||
func (i introspectionResult) GetExport(name string) runtimesRegistry.IntrospectedExport { | ||||||||||||||||||||||||||||||||||||
return i.exports[name] | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
func (i introspectionResult) recordExport(name string, value interface{}) { | ||||||||||||||||||||||||||||||||||||
i.exports[name] = introspectedExport{ | ||||||||||||||||||||||||||||||||||||
value: value, | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
// GetConsoleError implements runtime_registry.Result. | ||||||||||||||||||||||||||||||||||||
func (a *actionResult) GetConsoleError() []interface{} { | ||||||||||||||||||||||||||||||||||||
return a.ConsoleError | ||||||||||||||||||||||||||||||||||||
|
@@ -82,69 +118,46 @@ func newGojaRunner() runtimesRegistry.Runner { | |||||||||||||||||||||||||||||||||||
return &runner | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
func (e *gojaRunnerV1) Execute(ctx context.Context, workflow runtimesRegistry.WorkflowDescriptor, startOptions runtimesRegistry.StartOptions) (runtimesRegistry.Result, error) { | ||||||||||||||||||||||||||||||||||||
// Introspect implements runtime_registry.Runner. | ||||||||||||||||||||||||||||||||||||
func (e *gojaRunnerV1) Introspect(ctx context.Context, workflow runtimesRegistry.WorkflowDescriptor, options runtimesRegistry.IntrospectionOptions) (runtimesRegistry.IntrospectionResult, error) { | ||||||||||||||||||||||||||||||||||||
vm := goja.New() | ||||||||||||||||||||||||||||||||||||
_, returnErr := setupVM(ctx, vm, e, workflow) | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
registry.Enable(vm) | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
e.maxExecutionTimeout(ctx, vm, workflow.Limits.MaxExecutionDuration) | ||||||||||||||||||||||||||||||||||||
vm.SetTimeSource(func() time.Time { return time.Now() }) //static time source | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
executionResult := &actionResult{ | ||||||||||||||||||||||||||||||||||||
ConsoleLog: []interface{}{}, | ||||||||||||||||||||||||||||||||||||
ConsoleError: []interface{}{}, | ||||||||||||||||||||||||||||||||||||
Context: map[string]interface{}{}, | ||||||||||||||||||||||||||||||||||||
if returnErr != nil { | ||||||||||||||||||||||||||||||||||||
return nil, returnErr | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
module := vm.Get("module").ToObject(vm) | ||||||||||||||||||||||||||||||||||||
exports := module.Get("exports").ToObject(vm) | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
for name, binding := range workflow.Bindings.GlobalModules { | ||||||||||||||||||||||||||||||||||||
if module, ok := availableModules[name]; ok { | ||||||||||||||||||||||||||||||||||||
module(e, vm, vm.NewObject(), executionResult, binding) | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
introspectionResult := introspectionResult{ | ||||||||||||||||||||||||||||||||||||
exports: map[string]introspectedExport{}, | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
vm.Set("kinde", vm.NewObject()) | ||||||||||||||||||||||||||||||||||||
for name, binding := range workflow.Bindings.KindeAPIs { | ||||||||||||||||||||||||||||||||||||
kindeMountPoint := vm.Get("kinde").(*goja.Object) | ||||||||||||||||||||||||||||||||||||
if apiFunc, ok := kindeAPIs[name]; ok { | ||||||||||||||||||||||||||||||||||||
kindeMountPoint.Set(name, e.callRegisteredAPI(binding, apiFunc)) | ||||||||||||||||||||||||||||||||||||
for _, exportToIntrospect := range options.Exports { | ||||||||||||||||||||||||||||||||||||
exportIntrospect := exports.Get(exportToIntrospect) | ||||||||||||||||||||||||||||||||||||
if exportIntrospect != nil { | ||||||||||||||||||||||||||||||||||||
mapped := exportIntrospect.Export() | ||||||||||||||||||||||||||||||||||||
introspectionResult.recordExport(exportToIntrospect, mapped) | ||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||
introspectionResult.recordExport(exportToIntrospect, nil) | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
workflowHash := workflow.GetHash() | ||||||||||||||||||||||||||||||||||||
program, err := e.Cache.cacheProgram(workflowHash, func() (*goja.Program, error) { | ||||||||||||||||||||||||||||||||||||
ast, err := goja.Parse("main", string(workflow.ProcessedSource.Source)) | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||
return nil, fmt.Errorf("error parsing %w", err) | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
program, err := goja.CompileAST(ast, false) | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||
return nil, fmt.Errorf("error compiling %w", err) | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
return introspectionResult, nil | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
return program, nil | ||||||||||||||||||||||||||||||||||||
func (e *gojaRunnerV1) Execute(ctx context.Context, workflow runtimesRegistry.WorkflowDescriptor, startOptions runtimesRegistry.StartOptions) (runtimesRegistry.ExecutionResult, error) { | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||||||||
vm := goja.New() | ||||||||||||||||||||||||||||||||||||
executionResult, returnErr := setupVM(ctx, vm, e, workflow) | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||
return nil, err | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
_, err = vm.RunProgram(program) | ||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||
return nil, fmt.Errorf("%v", err.Error()) | ||||||||||||||||||||||||||||||||||||
if returnErr != nil { | ||||||||||||||||||||||||||||||||||||
return executionResult, returnErr | ||||||||||||||||||||||||||||||||||||
Comment on lines
+154
to
+155
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure consistent error handling between Introspect and Execute methods In the Apply this diff to standardize error handling: if returnErr != nil {
- return executionResult, returnErr
+ return nil, returnErr
} Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
module := vm.Get("module").ToObject(vm) | ||||||||||||||||||||||||||||||||||||
exports := module.Get("exports").ToObject(vm) | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
settingsExport := exports.Get("workflowSettings") | ||||||||||||||||||||||||||||||||||||
if settingsExport != nil { | ||||||||||||||||||||||||||||||||||||
executionResult.Context["workflowSettings"] = settingsExport.Export() | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
defaultExport := exports.Get("default") | ||||||||||||||||||||||||||||||||||||
if defaultExport == nil { | ||||||||||||||||||||||||||||||||||||
return nil, fmt.Errorf("no default export") | ||||||||||||||||||||||||||||||||||||
|
@@ -196,6 +209,61 @@ func (e *gojaRunnerV1) Execute(ctx context.Context, workflow runtimesRegistry.Wo | |||||||||||||||||||||||||||||||||||
return executionResult, nil | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
func setupVM(ctx context.Context, vm *goja.Runtime, runner *gojaRunnerV1, workflow runtimesRegistry.WorkflowDescriptor) (*actionResult, error) { | ||||||||||||||||||||||||||||||||||||
registry.Enable(vm) | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
runner.maxExecutionTimeout(ctx, vm, workflow.Limits.MaxExecutionDuration) | ||||||||||||||||||||||||||||||||||||
vm.SetTimeSource(func() time.Time { return time.Now() }) | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
executionResult := &actionResult{ | ||||||||||||||||||||||||||||||||||||
ConsoleLog: []interface{}{}, | ||||||||||||||||||||||||||||||||||||
ConsoleError: []interface{}{}, | ||||||||||||||||||||||||||||||||||||
Context: map[string]interface{}{}, | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
for name, binding := range workflow.Bindings.GlobalModules { | ||||||||||||||||||||||||||||||||||||
if module, ok := availableModules[name]; ok { | ||||||||||||||||||||||||||||||||||||
module(runner, vm, vm.NewObject(), executionResult, binding) | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
vm.Set("kinde", vm.NewObject()) | ||||||||||||||||||||||||||||||||||||
for name, binding := range workflow.Bindings.KindeAPIs { | ||||||||||||||||||||||||||||||||||||
kindeMountPoint := vm.Get("kinde").(*goja.Object) | ||||||||||||||||||||||||||||||||||||
if apiFunc, ok := kindeAPIs[name]; ok { | ||||||||||||||||||||||||||||||||||||
kindeMountPoint.Set(name, runner.callRegisteredAPI(binding, apiFunc)) | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
workflowHash := workflow.GetHash() | ||||||||||||||||||||||||||||||||||||
program, err := runner.Cache.cacheProgram(workflowHash, func() (*goja.Program, error) { | ||||||||||||||||||||||||||||||||||||
ast, err := goja.Parse("main", string(workflow.ProcessedSource.Source)) | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||
return nil, fmt.Errorf("error parsing %w", err) | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
program, err := goja.CompileAST(ast, false) | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||
return nil, fmt.Errorf("error compiling %w", err) | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
return program, nil | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||
return nil, err | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
_, err = vm.RunProgram(program) | ||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||
return nil, fmt.Errorf("%v", err.Error()) | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
return executionResult, nil | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
func (*gojaRunnerV1) maxExecutionTimeout(ctx context.Context, vm *goja.Runtime, maxExecutionDuration time.Duration) { | ||||||||||||||||||||||||||||||||||||
go func() { | ||||||||||||||||||||||||||||||||||||
timer := time.NewTimer(maxExecutionDuration) | ||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix YAML syntax for the "Run tests" step.
The current syntax for the "Run tests" step is incorrect. The
run
key should be at the same indentation level as thename
key.Please apply the following change to fix the YAML syntax:
📝 Committable suggestion
🧰 Tools
actionlint