-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Put every operation into dedicated source file. Use common naming convention of files. Signed-off-by: Richard Kosegi <richard.kosegi@gmail.com>
- Loading branch information
Showing
18 changed files
with
563 additions
and
434 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
Copyright 2024 Richard Kosegi | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package pipeline | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
// ActionMeta holds action's metadata used by Executor | ||
type ActionMeta struct { | ||
// Name of this step, should be unique within current scope | ||
Name string `yaml:"name,omitempty"` | ||
|
||
// Optional ordinal number that controls order of execution within parent step | ||
Order int `yaml:"order,omitempty"` | ||
|
||
// Optional expression to make execution of this action conditional. | ||
// Execution of this step is skipped when this expression is evaluated to false. | ||
// If value of this field is omitted, then this action is executed. | ||
When *string `yaml:"when,omitempty"` | ||
} | ||
|
||
func (am ActionMeta) String() string { | ||
return fmt.Sprintf("[name=%s,order=%d,when=%s]", am.Name, am.Order, safeStrDeref(am.When)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
Copyright 2024 Richard Kosegi | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package pipeline | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
type ActionSpec struct { | ||
ActionMeta `yaml:",inline"` | ||
// Operations to perform | ||
Operations OpSpec `yaml:",inline"` | ||
// Children element is an optional map of child actions that will be executed | ||
// as a part of this action (after any of OpSpec in Operations are performed). | ||
// Exact order of execution is given by Order field value (lower the value, sooner the execution will take place). | ||
Children ChildActions `yaml:"steps,omitempty"` | ||
} | ||
|
||
func (s ActionSpec) CloneWith(ctx ActionContext) Action { | ||
return ActionSpec{ | ||
ActionMeta: s.ActionMeta, | ||
Operations: s.Operations.CloneWith(ctx).(OpSpec), | ||
Children: s.Children.CloneWith(ctx).(ChildActions), | ||
} | ||
} | ||
|
||
func (s ActionSpec) String() string { | ||
return fmt.Sprintf("ActionSpec[meta=%v]", s.ActionMeta) | ||
} | ||
|
||
func (s ActionSpec) Do(ctx ActionContext) error { | ||
for _, a := range []Action{s.Operations, s.Children} { | ||
if s.When != nil { | ||
if ok, err := ctx.TemplateEngine().EvalBool(*s.When, ctx.Snapshot()); err != nil { | ||
return err | ||
} else if !ok { | ||
return nil | ||
} | ||
} | ||
err := ctx.Executor().Execute(a) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.