Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better API for storing and evaluating variable expressions #155

Open
marshall007 opened this issue Oct 3, 2024 · 1 comment
Open

Better API for storing and evaluating variable expressions #155

marshall007 opened this issue Oct 3, 2024 · 1 comment
Labels
enhancement ✨ New feature or request

Comments

@marshall007
Copy link

It would be nice if we tracked variables in a context.Context object and had an API for evaluating (potentially) templated string values like so:

interface Variable {
  Default() interface{}
  Value(context.Context) interface{} // interpolated value
  String() string // original expression
  IsExpression() bool // `true` if raw value contains `${{ ... }}` syntax
}

I think this interface could work for task/action inputs, environment variables, and eventually outputs.

// before
runner.Run(taskFile, "default", setVariables)

// internally `runner.Run(...)` mutates `action` with templated values:
action, err := utils.TemplateTaskActions(nil, action, action.With, r.variableConfig.GetSetVariables())
if action.If == "true" {
  // ...
}
// after
ctx := context.Background()
run := runner.New(tasksFile, runner.WithContext(ctx), runner.WithEnv(os.Getenv))

task := run.Task("default", inputs) // run task named `default`
task.Outputs() // => map[string]Variable

// internally `run.Task(...)` etc uses API like:
if action.If.Value(ctx) == "true" {
  // ...
}

This is basically what I was trying to do in #117 (see runner.Resolve(taskName)) but it's a very difficult refactor.

Originally posted by @marshall007 in #139 (comment)

@marshall007
Copy link
Author

@zachariahmiller Appreciate the feedback @marshall007. In the interest of our immediate priorities though have to agree with @Racer159. Good tech debt issue or target of that elusive 2.0 we discussed previously that is more fully featured.

@Racer159 Racer159 added the enhancement ✨ New feature or request label Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement ✨ New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants