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

Condition not taken into account when script is present #648

Closed
rbartlensky opened this issue Apr 21, 2022 · 5 comments
Closed

Condition not taken into account when script is present #648

rbartlensky opened this issue Apr 21, 2022 · 5 comments
Assignees
Milestone

Comments

@rbartlensky
Copy link

Small preface: This project is amazing! For every little odd thing that I wanted to do there was a clear way of achieving it -- you thought about everything!

Describe The Bug

Since you can set a default value for an environment variable that is not set, I thought you could achieve the same even when the default value is "taken from" a script.

To Reproduce

# Makefile.toml
[env]
FOO = { value = "default", condition = { env_not_set = ["FOO"] } }
BAR = { script = ["echo 'default'"], condition = { env_not_set = ["BAR"] } }
BAR2 = { script = ["default=default", "echo ${BAR2:-$default}"]}

[tasks.example]
script = '''
echo $FOO
echo $BAR
echo $BAR2
'''

Running the above:

$ cargo-make make --makefile Makefile.toml example
[cargo-make] INFO - cargo make 0.35.10
[cargo-make] INFO - Build File: Makefile.toml
[cargo-make] INFO - Task: example
[cargo-make] INFO - Profile: development
[cargo-make] INFO - Running Task: legacy-migration
[cargo-make] INFO - Running Task: example
default
default
default

gets the expected result, but if I set all variables

$ FOO=foo BAR=foo BAR2=foo cargo-make make --makefile Makefile.toml example
[cargo-make] INFO - cargo make 0.35.10
[cargo-make] INFO - Build File: Makefile.toml
[cargo-make] INFO - Task: example
[cargo-make] INFO - Profile: development
[cargo-make] INFO - Running Task: legacy-migration
[cargo-make] INFO - Running Task: example
foo
default # I expected foo here!
foo

I don't know if this is a bug, or a feature request, or just a discussion, since there is a workaround to my problem! Your input would be much appreciated. My main question is whether what I am trying to do makes sense, or if the workaround I came up with is the way to do it.

@sagiegurari
Copy link
Owner

thanks a lot for the feedback :)
actually I never supported both script and condition at same definition and i never gave such an example. just never thought about it.
I can add it, should be simple enough.

@sagiegurari
Copy link
Owner

@rbartlensky I just pushed a support for this in the dev branch. You can install it from there (0.35.11) and try it out.
tell me if it solves your issue or more changes are needed.

@rbartlensky
Copy link
Author

@sagiegurari That was a very speedy reply and fix! I can confirm it's working now:

$ FOO=bar BAR=bar BAR2=bar ~/cargo-make/./target/release/cargo-make make --makefile Makefile.toml example
[cargo-make] INFO - cargo make 0.35.10
[cargo-make] INFO - Build File: Makefile.toml
[cargo-make] INFO - Task: example
[cargo-make] INFO - Profile: development
[cargo-make] INFO - Running Task: legacy-migration
[cargo-make] INFO - Running Task: example
bar
bar
bar
[cargo-make] INFO - Build Done in 0.37 seconds.

I think the version wasn't bumped in your commit, but I'm pretty sure I'm running 0.35.11 :)

Thank you again for everything!

@sagiegurari
Copy link
Owner

I'm only bumping before releasing. thanks for the idea and for verifying

@sagiegurari
Copy link
Owner

@rbartlensky this is now officially released.

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

No branches or pull requests

2 participants