-
Notifications
You must be signed in to change notification settings - Fork 179
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
Env variables don't work in if-else-endif templates #488
Comments
@AtomToast It's in the code at |
On my system, env.HOME substitutes correctly. Ubuntu 24.04 and
|
Please correct me if I'm wrong but to me this is again only the variable substitution part of the code. This works for me. |
@AtomToast Good point. I haven't tested it, but the |
For me this is 100% reproducable. The code you linked is part of the |
@AtomToast You are correct. Just below
|
That alone seems to not have done it for me. Is there perhaps something else missing? |
This issue has been labeled as stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
@rasa Hey, sorry for the bother but the bot marked this as stale. Have you managed to make this work? |
@AtomToast No sorry, I haven't. Hopefully @TheLocehiliosan can un-stale this, as I can't. |
@AtomToast Does these changes fixes for you? https://github.com/soraxas/yadm/pull/1/files diff --git a/yadm b/yadm
index bfbcd81..a61f37f 100755
--- a/yadm
+++ b/yadm
@@ -432,20 +432,23 @@ function replace_vars() {
}
function condition_helper(label, value) {
gsub(/[\\.^$(){}\[\]|*+?]/, "\\\\&", value)
- return sprintf("yadm\\.%s" blank "*==" blank "*\"%s\"", label, value)
+ return sprintf("%s" blank "*==" blank "*\"%s\"", label, value)
}
function conditions() {
pattern = ifs blank "+("
+ for (label in ENVIRON) {
+ pattern = sprintf("%s%s|", pattern, condition_helper("env\\." label, ENVIRON[label]));
+ }
for (label in c) {
if (label != "class") {
value = c[label]
- pattern = sprintf("%s%s|", pattern, condition_helper(label, value));
+ pattern = sprintf("%s%s|", pattern, condition_helper("yadm\\." label, value));
}
}
split(classes, cls_array, "\n")
for (idx in cls_array) {
value = cls_array[idx]
- pattern = sprintf("%s%s|", pattern, condition_helper("class", value));
+ pattern = sprintf("%s%s|", pattern, condition_helper("yadm\\." "class", value));
}
sub(/\|$/, ")" blank "*%}$", pattern)
return pattern (I shall note that the current template replacement seems pretty inefficient as it needs to loop-through all class/envars everytime; though its still "fast enough" and the operation would be rare) |
@soraxas Unfortunately no :/ Does it work for you with those changes? |
I first directly edited the yadm binary in /bin. When using the cloned repo I called yadm with an absolute path. |
The awk script now performs all processing in the BEGIN block using an implementation that is capable of handling nested if statements. This fixes issue yadm-dev#436. Includes are now handled in the same way as the main file which means that recursive includes and if statements in includes works as expected. This fixes yadm-dev#406. All variables are handled in the same way now so it's now possible to use env variables in if statements. This fixes yadm-dev#488. Also add support for != in addition to == (fixes yadm-dev#358). Thus it's now e.g. possible to check if a variable is set (yadm-dev#477) by doing: {% if yadm.class != ""%} Class is set to {{ yadm.class }} {% endif %} Possible breaking change: An error will be issued if a non-existent yadm or env variable is referenced in an if statement or in a variable substitution.
The awk script now performs all processing in the BEGIN block using an implementation that is capable of handling if statements which contain nested if statments (fixes yadm-dev#436). To make nested ifs look better, if, else and endif lines can now have optional whitespace before {%. Includes are now handled in the same way as the main file which means that included files can both include other files and have if statements in addition to variables (fixes yadm-dev#406). Include lines can now also have optional whitespace before {%. All variables are handled in the same way now so it's now possible to use env variables in if statements (fixes yadm-dev#488). Also add support for != in addition to == (fixes yadm-dev#358). Thus it's now e.g. possible to check if a variable is set (yadm-dev#477) by doing: {% if yadm.class != ""%} Class is set to {{ yadm.class }} {% endif %} Possible breaking change: An error will be issued if a non-existent yadm or env variable is referenced in an if statement or in a variable substitution.
Describe the bug
Similarly to #486, trying to use env variables in
{% if env.EXAMPLE == "example" %}
with the default template processor does not work.To reproduce
Can this be reproduced with the yadm/testbed docker image: Yes
script.gz
Steps to reproduce the behavior:
export TEST=testing
yadm add test.txt##template
cat test.txt
Expected behavior
The file should contain
success
, however instead it uses thefail
branch.Environment
Additional context
From a brief look at the code, it seems that this is actually just not implemented right now?
The text was updated successfully, but these errors were encountered: