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.

@puneetdixit200
Copy link
Copy Markdown
Author

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.

@Legimity
Copy link
Copy Markdown
Contributor

Hi, I opened #2859 for this.

It updates the nfpm destination for the Fish completion file to /usr/share/fish/vendor_completions.d/task.fish, following the current Fish documentation for third-party vendor completions.

I included the validation steps I was able to run in the PR description.

Copy link
Copy Markdown

@StantonMatt StantonMatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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

4 participants