Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decode map environment variable overwrites existing one even with env_not_set condition #1018

Open
Bauke opened this issue Jan 11, 2024 · 2 comments · Fixed by #1020
Open
Assignees

Comments

@Bauke
Copy link
Contributor

Bauke commented Jan 11, 2024

Hi, thanks for making and maintaining cargo-make, I really like it! I think I've come across a potential bug with conditionals and the decode map feature for environment variables. Here's an example Makefile.toml:

[tasks.conditional-source]
command = "echo"
args = ["${SOURCE_TEST}"]
env = {
  SOURCE_TEST = {
    condition = { env_not_set = ["SOURCE_TEST"] },
    source = "${SOURCE_IN}",
    default_value = "${SOURCE_IN}",
    mapping = { "one" = "1" }
  }
}

When I run this and don't have SOURCE_TEST set it works as expected and the one gets mapped to a 1. But when a SOURCE_TEST is defined it overwrites that one and again maps it.

$ SOURCE_IN="one" makers conditional-source
[cargo-make] INFO - Execute Command: "echo" "1"
1

$ SOURCE_IN="one" SOURCE_TEST="example" makers conditional-source
[cargo-make] INFO - Execute Command: "echo" "1"
1

# Instead I would expect to get:
[cargo-make] INFO - Execute Command: "echo" "example"
example

This is using version 0.37.5.

@sagiegurari
Copy link
Owner

@Bauke thanks for the feedback.
actually, i don't remember ever adding condition support for decode env vars definition and its not in the docs either.
i've only added it to simple definition and to script defintion.
see decode definition here:
https://github.com/sagiegurari/cargo-make/blob/601361645034c5e088eb337824a868d949ac6e2e/src/lib/types.rs#L453C1-L460C2

and all examples here:
https://github.com/sagiegurari/cargo-make/tree/master?tab=readme-ov-file#example

having said that, i think addition condition to decode env var definition is possible if thats what you are looking for.
would you like to PR that?

@Bauke
Copy link
Contributor Author

Bauke commented Jan 13, 2024

Sure! I'll give it a shot.

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

Successfully merging a pull request may close this issue.

2 participants