Make envs available in if conditionals (#225)
* Ignore .idea * Add Env to the RunContext vm so we can Evaluate and Interpolate `env.xx` * Make EvalBool support expressions more in line with the github runner * Turns out Boolean(value) is what github is doing after all * Add test for github context as well
This commit is contained in:
@@ -119,6 +119,7 @@ func (rc *RunContext) newVM() *otto.Otto {
|
||||
rc.vmSecrets(),
|
||||
rc.vmStrategy(),
|
||||
rc.vmMatrix(),
|
||||
rc.vmEnv(),
|
||||
}
|
||||
vm := otto.New()
|
||||
for _, configer := range configers {
|
||||
@@ -196,18 +197,18 @@ func (rc *RunContext) vmHashFiles() func(*otto.Otto) {
|
||||
_ = vm.Set("hashFiles", func(path string) string {
|
||||
files, _, err := glob.Glob([]string{filepath.Join(rc.Config.Workdir, path)})
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
logrus.Errorf("Unable to glob.Glob: %v", err)
|
||||
return ""
|
||||
}
|
||||
hasher := sha256.New()
|
||||
for _, file := range files {
|
||||
f, err := os.Open(file.Path)
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
logrus.Errorf("Unable to os.Open: %v", err)
|
||||
}
|
||||
defer f.Close()
|
||||
if _, err := io.Copy(hasher, f); err != nil {
|
||||
logrus.Error(err)
|
||||
logrus.Errorf("Unable to io.Copy: %v", err)
|
||||
}
|
||||
}
|
||||
return hex.EncodeToString(hasher.Sum(nil))
|
||||
@@ -251,6 +252,14 @@ func (rc *RunContext) vmGithub() func(*otto.Otto) {
|
||||
}
|
||||
}
|
||||
|
||||
func (rc *RunContext) vmEnv() func(*otto.Otto) {
|
||||
return func(vm *otto.Otto) {
|
||||
env := rc.GetEnv()
|
||||
log.Debugf("context env => %v", env)
|
||||
_ = vm.Set("env", env)
|
||||
}
|
||||
}
|
||||
|
||||
func (sc *StepContext) vmEnv() func(*otto.Otto) {
|
||||
return func(vm *otto.Otto) {
|
||||
log.Debugf("context env => %v", sc.Env)
|
||||
|
Reference in New Issue
Block a user