Skip to content

fix: preserve dotenv variable order#2855

Open
puneetdixit200 wants to merge 1 commit into
go-task:mainfrom
puneetdixit200:fix/1847-deterministic-dotenv
Open

fix: preserve dotenv variable order#2855
puneetdixit200 wants to merge 1 commit into
go-task:mainfrom
puneetdixit200:fix/1847-deterministic-dotenv

Conversation

@puneetdixit200
Copy link
Copy Markdown

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=1
  • GOMODCACHE=/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

@trulede
Copy link
Copy Markdown
Contributor

trulede commented May 22, 2026

There is already this #2612 which IIRC also gets rid of the dependency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inconsistent Variable Expansion When Using {{.VAR}} in .env Files with Nested Variables

2 participants