fix: preserve dotenv variable order#2855
Conversation
|
There is already this #2612 which IIRC also gets rid of the dependency. |
|
Thanks for the pointer. I compared #2612: it overlaps the same dotenv resolver path, but this branch is focused on preserving dotenv variable expansion order and keeps the nested Taskfile regression coverage with the current implementation. If you prefer consolidating the fix under #2612 instead, I can close this one. |
|
Hi, I opened #2859 for this. It updates the nfpm destination for the Fish completion file to I included the validation steps I was able to run in the PR description. |
StantonMatt
left a comment
There was a problem hiding this comment.
Reviewed f45c1780 against #1847.
I also checked the overlap with #2612. This branch is the more directly verifiable one from my pass because it keeps the existing godotenv value parsing path and adds a regression for the nested .env template order case.
Local verification on Go 1.26.3:
go test ./... -run TestDotenvNestedTemplatesAreEvaluatedInFileOrder -count=1
go test ./... -count=1
Both passed. I do not see a functional blocker in this patch from the issue behavior; the only maintainer judgment call I noticed is whether the new helper should stay exported as ReadDotenv, since it is only used internally right now.
Fixes #1847.
This keeps dotenv values in file order after parsing, so Task template expansion sees earlier dotenv entries before later nested entries. Both global and task-level dotenv loading now share the ordered reader while still using godotenv for parsing.
Tests run:
GOMODCACHE=/tmp/task-1847-gomodcache GOCACHE=/tmp/task-1847-gocache go test ./... -run TestDotenvNestedTemplatesAreEvaluatedInFileOrder -count=1GOMODCACHE=/tmp/task-1847-gomodcache GOCACHE=/tmp/task-1847-gocache go test ./... -run 'TestDotenv|TestTaskDotenv|TestVarInheritance' -count=1\n-GOMODCACHE=/tmp/task-1847-gomodcache GOCACHE=/tmp/task-1847-gocache go test ./...\n-GOMODCACHE=/tmp/task-1847-gomodcache GOCACHE=/tmp/task-1847-gocache go vet ./...\n-test -z "$(gofmt -l taskfile/dotenv.go variables.go task_test.go)"\n-git diff --cached --check\n\nAI assistance disclosure: I used AI assistance to draft and verify this patch, then reviewed the code and test output before submitting.\n\n- [x] I have read and followed the Contribution Guide\n