feat: add mise_env tera variable for templates#5002
Conversation
|
Additionally, I'm seeking feedback on the behaviour if an environment isn't specified. The current implementation always sets When a user hasn't specified an environment, the "undefined variables are considered falsy" Tera convention doesn't work as expected, because I think it may be better to not set |
| context.insert("env", &*env::PRISTINE_ENV); | ||
| context.insert("mise_bin", &*env::MISE_BIN); | ||
| context.insert("mise_pid", &*env::MISE_PID); | ||
| context.insert("mise_env", &*env::MISE_ENV.join(",")); |
There was a problem hiding this comment.
I think in this case we probably can keep the array type in the template
Allows the user to query what environment a task is running in.
54e4838 to
b91bee8
Compare
Allows the use of conditionals:
```
{% if mise_env %}
echo {{ mise_env }}
{% endif %}
```
And easier use of other Tera functions:
```
{% if mise_env %}
echo {{ mise_env | last }}
{% endif %}
```
| context.insert("env", &*env::PRISTINE_ENV); | ||
| context.insert("mise_bin", &*env::MISE_BIN); | ||
| context.insert("mise_pid", &*env::MISE_PID); | ||
| if !(&*env::MISE_ENV).is_empty() { |
There was a problem hiding this comment.
I think you need to get this from settings or something because if it's specified as a CLI argument this will miss that (I think, I could be wrong)
There was a problem hiding this comment.
I double checked and it looks like it works:
$ cat <<EOF >mise.toml
[tasks.print]
run = '{% if mise_env %}echo {{mise_env}}{% endif %}'
EOF
$ MISE_ENV=production mise run print
[print] $ echo [production]
[production]
$ mise --env production run print
[print] $ echo [production]
[production]
I believe this is because the environment function in src/env.rs reads from both CLI arguments and environment varables.
There was a problem hiding this comment.
For the sake of completeness, I have added some additional e2e tests (38eb2a6) that cover the different ways the configuration environment can be set.
### 🚀 Features - **(registry)** use aqua for taplo by [@risu729](https://github.com/risu729) in [#4991](#4991) - add mise_env tera variable for templates by [@auxesis](https://github.com/auxesis) in [#5002](#5002) ### 🐛 Bug Fixes - **(env)** fix dotenv files cascading (fix #4688) by [@noirbizarre](https://github.com/noirbizarre) in [#4996](#4996) ### Ci - **(registry)** increaset timeout to 30 mins by [@risu729](https://github.com/risu729) in [#5006](#5006)
Allows the user to query in a template what configuration environment a task is running in:
This can be useful when you want to
mise setan environment variable for the current configuration environment: