feat(requires): support variable references in enum constraints#2678
Merged
feat(requires): support variable references in enum constraints#2678
Conversation
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
There was a problem hiding this comment.
Pull request overview
Adds support for referencing variables in requires.vars[].enum via a new ref key, allowing enum constraints to be reused or computed dynamically (including via templating/shell-derived vars), and updates docs/tests accordingly.
Changes:
- Introduce
ast.Enum(with YAML unmarshalling) to support either a static enum list or arefexpression. - Resolve
enum.refduring task compilation (when dynamic vars are evaluated) and validate required vars against the resolved values. - Add docs/examples and golden tests covering enum refs and error cases.
Reviewed changes
Copilot reviewed 11 out of 13 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
taskfile/ast/requires.go |
Adds Enum type and YAML unmarshalling for enum: [...] vs enum: {ref: ...}. |
variables.go |
Resolves enum.ref during compilation to populate enum values for validation. |
requires.go |
Adapts prompting/validation plumbing to use the new Enum structure. |
internal/summary/summary.go |
Updates summary printing to account for enum values being nested under Enum.Value. |
executor_test.go |
Adds executor tests for enum refs (pass/fail/non-list). |
testdata/requires/Taskfile.yml |
Adds variables/tasks used by new enum-ref requires tests. |
testdata/requires/testdata/*.golden |
Golden outputs for the new enum-ref test cases. |
website/src/docs/guide.md |
Documents enum.ref usage, including templating/shell-derived examples. |
website/src/docs/reference/schema.md |
Adds schema reference docs example for enum.ref. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- 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
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add support for variable references in
enumconstraints via a newrefkey, allowing enum values to be defined once and reused or computed dynamically instead of being hardcoded.fixes #2647