grim/convey

9d2745690a29
Parents f3f0021b39e0
Children b7459765fff9
Add environment support to metaplans. Fixes CONVEY-185
--- a/REFERENCE.md Thu Dec 23 16:11:49 2021 -0600
+++ b/REFERENCE.md Thu Dec 23 17:11:52 2021 -0600
@@ -113,7 +113,7 @@
| Name | Required | Description |
| ----------- | -------- | ----------- |
-| environment | | A list of environment variables to set. They should be specified in a `NAME` or `NAME=VALUE` format. If no value is provided, the value of the variable from the host will be provided if it is available. These environment variables will be applied on top of any that were set at the config-file level. |
+| environment | | A list of environment variables to set. They should be specified in a `NAME` or `NAME=VALUE` format. If no value is provided, the value of the variable from the host will be provided if it is available. These environment variables will be applied on top of any that were set at the config-file level or a meta-plan that contains this plan. |
| stages | Yes | A list of `stages` to be run as part of this `plan` in the order that they should be run in. |
----
@@ -147,12 +147,15 @@
| Name | Required | Description |
| ----------- | -------- | ----------- |
+| environment | | A list of environment variables to set. They should be specified in a `NAME` or `NAME=VALUE` format. If no value is provided, the value of the variable from the host will be provided if it is available. These environment variables will be applied on top of any that were set at the config-file level. |
| plans | Yes | A list of `plans` to run in the order they should be run in. |
### Example
meta-plans:
world:
+ environment:
+ - BUILD_TYPE=production
plans:
- plan1
- plan2
--- a/convey.yml Thu Dec 23 16:11:49 2021 -0600
+++ b/convey.yml Thu Dec 23 17:11:52 2021 -0600
@@ -101,4 +101,5 @@
meta-plans:
everything:
plans:
+ - clean
- default
--- a/runtime/metaplans.go Thu Dec 23 16:11:49 2021 -0600
+++ b/runtime/metaplans.go Thu Dec 23 17:11:52 2021 -0600
@@ -19,11 +19,14 @@
import (
"context"
"fmt"
+
+ "keep.imfreedom.org/grim/convey/environment"
)
// MetaPlan is a representation of a meta plan.
type MetaPlan struct {
- Plans []string `yaml:"plans"`
+ Plans []string `yaml:"plans"`
+ Environment environment.Environment `yaml:"environment"`
}
// UnmarshalYAML is a custom yaml unmarshaller for MetaPlan's.
@@ -54,7 +57,20 @@
for _, name := range m.Plans {
mp, ok := rt.MetaPlans[name]
if ok {
- if err := mp.Execute(ctx, rt); err != nil {
+ // Store the old config environment from the runtime, copy it,
+ // and then merge the metaplan's environment into it. The
+ // config environment is the toplevel environment in the
+ // config, and that is the only thing the metaplan should be
+ // overwriting.
+ oldenv := rt.ConfigEnvironment
+ rt.ConfigEnvironment = oldenv.Copy().Merge(mp.Environment)
+
+ // Run the metaplan with the merged config environment, and
+ // then reset the runtime's config environment after execution.
+ err := mp.Execute(ctx, rt)
+ rt.ConfigEnvironment = oldenv
+
+ if err != nil {
errChan <- err
return
}