这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@walteh
Copy link
Owner

@walteh walteh commented Aug 5, 2025

Summary

  • inject defined tasks into HCL evaluation context
  • replace task("name") calls with task. references and exec function
  • test task references in deps and cmds including invalid references

Testing

  • go test ./...

Prompt

Task 12: Injected Task References

Purpose:
Support direct use of defined tasks as variable-like references inside expressions or function calls, replacing the previous task("...") function syntax with native injected task references.


Requirements:

  • All defined tasks must be injected into the evaluation context as top-level variables using their name.
  • Referencing task.test inside expressions or interpolations must resolve to a Task reference object.
  • Only top-level tasks should be injected; no support for substructures or introspection yet.
  • The previous task("name") function must be removed or deprecated in favor of direct references.

Example:

task "scoped" {
  deps = [
    task.test,
    task.delayed,
  ]

  cmds = [
    exec(task.test),
    exec(task.delayed, {
      DATE3 = sh("date")
    }),
  ]
}

Implementation Hints (Do Not Copy Code):

  • During parsing, all task blocks should be registered into a global context map.
  • That map is injected as variables into the evaluation context (e.g. EvalContext).
  • A synthetic cty.ObjectVal (or similar) may be needed to support task.<name> resolution.
  • Errors should occur if undefined tasks are referenced.

Validation:

  • Add test case for a task referencing another via task.<name> in both deps and cmds.
  • Ensure fallback to task("name") is removed.
  • Invalid usage like task.unknown should return a proper error message with file/line context.
  • Add scenario to HCLE2ETest with a task that uses two others as dependencies and references them inside exec.

https://chatgpt.com/codex/tasks/task_e_68925996cff08330a85d203a67b21ec5

@walteh walteh merged commit e7a5fc4 into codex/hcl-alt Aug 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants