sagiegurari / cargo-make

Rust task runner and build tool.
https://sagiegurari.github.io/cargo-make/
Apache License 2.0
2.56k stars 125 forks source link

Env var evaluation order is wrong #1056

Closed awkure closed 6 months ago

awkure commented 6 months ago

Describe The Bug

As per project README we have the following evaluation order of env variables

Where command line env variables have the highest priority, and the ones loaded from env_files are of higher priority, than the ones, defined in the [env] block. In reality the situation is of the reverse order.

To Reproduce

If you try using this Makefile.toml

env_files = ["./.env"]

[env]
DOCKER_IMAGE_TAG = "inner"

[tasks.current_env]
script = '''
echo Current env:
echo DOCKER_IMAGE_TAG = $DOCKER_IMAGE_TAG
'''

with

$ cat ./.env                           
DOCKER_IMAGE_TAG=file

you get

$ DOCKER_IMAGE_TAG=command-line cargo make current_env
Current env:
DOCKER_IMAGE_TAG = inner

And commenting out [env]

env_files = ["./.env"]

# [env]
# DOCKER_IMAGE_TAG = "inner"

[tasks.current_env]
script = '''
echo Current env:
echo DOCKER_IMAGE_TAG = $DOCKER_IMAGE_TAG
'''

The priority goes to the env file

$ DOCKER_IMAGE_TAG=command-line cargo make current_env
Current env:
DOCKER_IMAGE_TAG = file
sagiegurari commented 6 months ago

I see the issue. will check more...

by the way this is not considered command line DOCKER_IMAGE_TAG=command-line cargo make current_env

command like are via env key on the cargo make cli. while what you did is set it as an env BEFORE cargo make is invoked and is considered current machine env

sagiegurari commented 6 months ago

wwait... everything works as per the docs.

sagiegurari commented 6 months ago

order is not priority. order is order. when things get loaded. naturally last loaded overwrites first loaded.

i'll be closing this issue but if you don't agree or i misunderstood, please reopen.