-
-
Notifications
You must be signed in to change notification settings - Fork 624
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
Dynamic Variables only calculated once if "sh:" is identical #524
Comments
I'm of the opinion that the second example should work, and that re-initializing a global var in the local scope should be something that is supported. @andreynering would you agree that a global variable re-initialized as a local variable should be a supported feature? If so I can create a new, simpler issue that we can create a PR against. @is-jonreeves I agree that some special variables would be desirable, as mentioned in issue #525. |
Hi @is-jonreeves, and thanks for opening these issues! @SwitchedToGitlab's suggestions make sense, but may not be easy to implement. Note to myself: Another way to fix this would be to allow |
At the very least, dynamic variable caching must take into account the working directory. We have two tasks with different working directories which both use |
go-task doesn’t work properly with dynamic variables in different directories, see: go-task/task#524
See this commit for example problem/fix: Azure/azure-service-operator@f83921d |
* Slight simplification of Taskfile * Don't output RBAC for Crossplane * Disambiguate variables go-task doesn’t work properly with dynamic variables in different directories, see: go-task/task#524 Co-authored-by: Bevan Arps <[email protected]>
I kind of like the idea of an "uncachable" variable, because it would act kind of like a function. Though the solution to this problem may be lazy variables discussed in V4. Basically a variable doesn't get evaluated (nor cached) until the first time it's actually used. Thus, you can define a variable as a global, and it won't even run until it's referenced elsewhere. Though, this example does bring to light that with lazy variables, you may still want eager evaluation, such as in the example below, where you want to know the vars:
PROJECT_DIR:
sh: echo $PWD In V4, I can look at supporting both eager & lazy functionality. I can also look into "uncachable" variables, which would likely not be a default behavior, but interesting none the less. |
This issue is still quite prevalent and annoying but discussion around it seems to have died down. Is there solution in sight, or do we need to wait for V4 for this to be fixed? |
We just ran into this and we found an acceptable workaround. Sharing here in case others come across this ...
|
It seems like Dynamic Variables that share the same verbatim
sh:
line will not get recomputed when run in their new context. For example if a globalvar
is set to the current dir, but then atask
withdir: ../
re-sets it, this value does not update for that task. If you make a slight tweak to thesh:
command, it does work.Example Taskfile showing the issue
Expected:
Actual:
Workaround
If you tweak the
sh:
command to be unique each time its used, then it appears to force it to rerun correctly. So something like this will allow it to work:Side-Note/Feature on Directories
I'll probably open a feature request for this, but the reason that I am jumping through the above hoops is that there doesn't seem to be an official "special variable" to get the Current Working Directory, which would be really handy. For commands that requires a Abs paths like Docker, obtaining these in a cross-platform manner can be annoyingly repetitive to mange. If there was a "special variable" with the current working directory and it was correctly affected by the
dir:
within eachtask
, this would help a lot especially with the "slim-sprig" functions.The text was updated successfully, but these errors were encountered: