go-task / task

A task runner / simpler Make alternative written in Go
https://taskfile.dev
MIT License
11.56k stars 616 forks source link

Updated Environment Variables Before Dotenv File #1912

Open DominiqueLade opened 2 weeks ago

DominiqueLade commented 2 weeks ago

I created the following task file:

vars:
  ENVIRONMENT: "dev"

dotenv: [".env.{{.ENVIRONMENT}}"]

tasks:
  ...

When executing any task normally, such as task mytask (without overwriting the variable ENVIRONMENT), everything works as expected, and the environment variables from the .env.dev file are loaded. However, when I overwrite the environment variable with task mytask ENVIRONMENT=prod, the variable is updated to prod within the task, but the .env.dev file is still loaded.

It appears that the variable is overwritten only after the dotenv file is loaded. I would expect the change to be applied beforehand. This would be highly useful for managing the environment on a global level.