feat(requires): support variable references in enum constraints by vmaerten · Pull Request #2678 · go-task/task

added 6 commits

January 25, 2026 15:17
Add support for referencing variables in enum validation:

```yaml
vars:
  ALLOWED_ENVS: ["dev", "staging", "prod"]

tasks:
  deploy:
    requires:
      vars:
        - name: ENV
          enum:
            ref: .ALLOWED_ENVS
```

This allows enum values to be defined once and reused, or computed
dynamically using template expressions like `| fromYaml`.

Changes:
- Add Enum type with Ref/Value fields in taskfile/ast/requires.go
- Add resolveEnumRefs() to resolve refs at task compilation time
- Add getEnumValues() helper in requires.go
- Only resolve enum refs when shell variables are evaluated

@vmaerten vmaerten marked this pull request as ready for review

February 17, 2026 20:53

@vmaerten

- Check cache.Err() after ResolveRef to surface template parse errors
- Resolve enum refs in all compilation paths (not just evaluateShVars)
- Validate non-empty ref in Enum.UnmarshalYAML to reject empty mappings
- Display enum ref expression in task summary when values are unresolved
- Fix Go template pipeline syntax in docs (use parentheses)
- Update JSON schema to accept enum as object with ref key
- Add test for enum ref to nonexistent variable
Enum refs that use template pipelines like fromJson depend on
shell-derived variables which are only available after sh: evaluation.
Restoring the guard prevents resolution failures in FastCompiledTask.

@vmaerten vmaerten deleted the feat/enum-ref-support branch

March 21, 2026 10:32

vmaerten added a commit that referenced this pull request

Mar 21, 2026

Copilot AI pushed a commit to libor-m/task that referenced this pull request

Mar 27, 2026
…ask#2678)

Co-authored-by: libor-m <1497769+libor-m@users.noreply.github.com>

Copilot AI pushed a commit to libor-m/task that referenced this pull request

Mar 27, 2026
Co-authored-by: libor-m <1497769+libor-m@users.noreply.github.com>