grim/convey

2cf80db56edb
Parents da41a2bdcd7c
Children eff7fbacd5ee
Move the configurations environment into the runtime
--- a/runner/cmd.go Thu Dec 23 10:03:40 2021 -0600
+++ b/runner/cmd.go Thu Dec 23 11:11:39 2021 -0600
@@ -28,7 +28,6 @@
log "github.com/sirupsen/logrus"
"keep.imfreedom.org/grim/convey/config"
- "keep.imfreedom.org/grim/convey/environment"
"keep.imfreedom.org/grim/convey/globals"
"keep.imfreedom.org/grim/convey/logging"
"keep.imfreedom.org/grim/convey/runtime"
@@ -46,22 +45,20 @@
Plans []string `kong:"arg,help='The names of the plans to run',default='default'"`
}
-func (c *RunnerCmd) runPlan(name string, cfg *config.Config, plan runtime.Plan, rt *runtime.Runtime) error {
- configEnv := environment.New(cfg.Environment...)
-
- return plan.Execute(name, configEnv, rt)
+func (c *RunnerCmd) runPlan(name string, plan runtime.Plan, rt *runtime.Runtime) error {
+ return plan.Execute(name, rt)
}
-func (c *RunnerCmd) runPlans(ctx context.Context, cfg *config.Config, rt *runtime.Runtime) error {
+func (c *RunnerCmd) runPlans(ctx context.Context, rt *runtime.Runtime) error {
errChan := make(chan error, 1)
cancelled := false
go func() {
for _, name := range c.Plans {
- plan := cfg.Plans[name]
+ plan := rt.Plans[name]
- if err := c.runPlan(name, cfg, plan, rt); err != nil {
+ if err := c.runPlan(name, plan, rt); err != nil {
errChan <- err
return
}
@@ -122,7 +119,7 @@
ctx, cancel := context.WithCancel(context.Background())
go func(ctx context.Context, cfg *config.Config) {
- errChan <- c.runPlans(ctx, cfg, rt)
+ errChan <- c.runPlans(ctx, rt)
}(ctx, cfg)
for {
--- a/runner/runtime.go Thu Dec 23 10:03:40 2021 -0600
+++ b/runner/runtime.go Thu Dec 23 11:11:39 2021 -0600
@@ -24,8 +24,9 @@
func (c *RunnerCmd) Runtime(configPath string, cfg *config.Config) *runtime.Runtime {
env := environment.New(c.Environment...)
+ configEnv := environment.New(cfg.Environment...)
- rt := runtime.New(env, configPath, c.ForceSequential, c.KeepWorkspace, c.Timeout)
+ rt := runtime.New(env, configPath, configEnv, c.ForceSequential, c.KeepWorkspace, c.Timeout)
rt.Tasks = cfg.Tasks
rt.Plans = cfg.Plans
--- a/runtime/plans.go Thu Dec 23 10:03:40 2021 -0600
+++ b/runtime/plans.go Thu Dec 23 11:11:39 2021 -0600
@@ -24,7 +24,6 @@
log "github.com/sirupsen/logrus"
- "keep.imfreedom.org/grim/convey/environment"
"keep.imfreedom.org/grim/convey/logging"
"keep.imfreedom.org/grim/convey/yaml"
)
@@ -43,12 +42,12 @@
}
// Execute runs the plan.
-func (p *Plan) Execute(path string, configEnv environment.Environment, rt *Runtime) error {
+func (p *Plan) Execute(path string, rt *Runtime) error {
if err := p.Valid(); err != nil {
return err
}
- planEnv := configEnv.Copy().MergeSlice(p.Environment).Merge(rt.Environment)
+ planEnv := rt.ConfigEnvironment.Copy().MergeSlice(p.Environment).Merge(rt.Environment)
p.logger = logging.NewAdapter(path)
--- a/runtime/plans_stages_test.go Thu Dec 23 10:03:40 2021 -0600
+++ b/runtime/plans_stages_test.go Thu Dec 23 11:11:39 2021 -0600
@@ -27,11 +27,11 @@
func runPlan(path string, p Plan, tasks map[string]Task) error {
env := environment.New()
- rt := New(env, "", false, false, 0*time.Second)
+ rt := New(env, "", environment.New(), false, false, 0*time.Second)
rt.Tasks = tasks
defer rt.Shutdown()
- return p.Execute(path, environment.New(), rt)
+ return p.Execute(path, rt)
}
func TestPlanStagesNone(t *testing.T) {
--- a/runtime/runtime.go Thu Dec 23 10:03:40 2021 -0600
+++ b/runtime/runtime.go Thu Dec 23 11:11:39 2021 -0600
@@ -29,7 +29,9 @@
type Runtime struct {
Environment environment.Environment
- ConfigPath string
+ ConfigPath string
+ ConfigEnvironment environment.Environment
+
ForceSequential bool
KeepWorkspace bool
@@ -44,10 +46,13 @@
workspace *fs.Directory
}
-func New(env environment.Environment, configPath string, forceSequential bool, keepWorkspace bool, timeout time.Duration) *Runtime {
+func New(env environment.Environment, configPath string, configEnvironment environment.Environment, forceSequential bool, keepWorkspace bool, timeout time.Duration) *Runtime {
rt := &Runtime{
- Environment: env,
- ConfigPath: configPath,
+ Environment: env,
+
+ ConfigPath: configPath,
+ ConfigEnvironment: configEnvironment,
+
ForceSequential: forceSequential,
KeepWorkspace: keepWorkspace,
Timeout: timeout,
--- a/tasks/import_test.go Thu Dec 23 10:03:40 2021 -0600
+++ b/tasks/import_test.go Thu Dec 23 11:11:39 2021 -0600
@@ -34,7 +34,7 @@
env := environment.New()
// create our runtime
- rt := runtime.New(environment.New(), "", false, false, 0*time.Second)
+ rt := runtime.New(environment.New(), "", environment.New(), false, false, 0*time.Second)
defer rt.Shutdown()
// create our task and run it.