(t *ast.Task, call *Call, evaluateShVars bool)
| 46 | } |
| 47 | |
| 48 | func (c *Compiler) getVariables(t *ast.Task, call *Call, evaluateShVars bool) (*ast.Vars, error) { |
| 49 | result := env.GetEnviron() |
| 50 | specialVars, err := c.getSpecialVars(t, call) |
| 51 | if err != nil { |
| 52 | return nil, err |
| 53 | } |
| 54 | for k, v := range specialVars { |
| 55 | result.Set(k, ast.Var{Value: v, Secret: false}) |
| 56 | } |
| 57 | |
| 58 | getRangeFunc := func(dir string) func(k string, v ast.Var) error { |
| 59 | return func(k string, v ast.Var) error { |
| 60 | cache := &templater.Cache{Vars: result} |
| 61 | // Replace values |
| 62 | newVar := templater.ReplaceVar(v, cache) |
| 63 | // If the variable should not be evaluated, but is nil, set it to an empty string |
| 64 | // This stops empty interface errors when using the templater to replace values later |
| 65 | // Preserve the Sh field so it can be displayed in summary |
| 66 | if !evaluateShVars && newVar.Value == nil { |
| 67 | result.Set(k, ast.Var{Value: "", Sh: newVar.Sh, Secret: v.Secret}) |
| 68 | return nil |
| 69 | } |
| 70 | // If the variable should not be evaluated and it is set, we can set it and return |
| 71 | if !evaluateShVars { |
| 72 | result.Set(k, ast.Var{Value: newVar.Value, Sh: newVar.Sh, Secret: v.Secret}) |
| 73 | return nil |
| 74 | } |
| 75 | // Now we can check for errors since we've handled all the cases when we don't want to evaluate |
| 76 | if err := cache.Err(); err != nil { |
| 77 | return err |
| 78 | } |
| 79 | // If the variable is already set, we can set it and return |
| 80 | if newVar.Value != nil || newVar.Sh == nil { |
| 81 | result.Set(k, ast.Var{Value: newVar.Value, Secret: v.Secret}) |
| 82 | return nil |
| 83 | } |
| 84 | // If the variable is dynamic, we need to resolve it first |
| 85 | static, err := c.HandleDynamicVar(newVar, dir, env.GetFromVars(result)) |
| 86 | if err != nil { |
| 87 | return err |
| 88 | } |
| 89 | result.Set(k, ast.Var{Value: static, Secret: v.Secret}) |
| 90 | return nil |
| 91 | } |
| 92 | } |
| 93 | rangeFunc := getRangeFunc(c.Dir) |
| 94 | |
| 95 | var taskRangeFunc func(k string, v ast.Var) error |
| 96 | if t != nil { |
| 97 | // NOTE(@andreynering): We're manually joining these paths here because |
| 98 | // this is the raw task, not the compiled one. |
| 99 | cache := &templater.Cache{Vars: result} |
| 100 | dir := templater.Replace(t.Dir, cache) |
| 101 | if err := cache.Err(); err != nil { |
| 102 | return nil, err |
| 103 | } |
| 104 | dir = filepathext.SmartJoin(c.Dir, dir) |
| 105 | taskRangeFunc = getRangeFunc(dir) |
no test coverage detected