diff options
| author | tranch <tranch.xiao@gmail.com> | 2026-08-26 10:59:21 +0800 |
|---|---|---|
| committer | tranch <tranch.xiao@gmail.com> | 2026-08-26 10:59:21 +0800 |
| commit | 10411b5e32b78f57b6ad995c434cfc4fc390d689 (patch) | |
| tree | 431b9a7556ebe191314e34ed20bc7a507bfdbd42 /tests/test-dotenv-precedence.sh | |
| parent | c7a47b2ba1cfc17348e729c1b7a6689bd5c9c95d (diff) | |
| download | AeroCore-OS-10411b5e32b78f57b6ad995c434cfc4fc390d689.tar.gz AeroCore-OS-10411b5e32b78f57b6ad995c434cfc4fc390d689.zip | |
fix(config): make local dotenv optional
Load a private .env when present, but keep CI configuration in GitHub
runtime variables and retain the tracked template as a guide.
Diffstat (limited to 'tests/test-dotenv-precedence.sh')
| -rwxr-xr-x | tests/test-dotenv-precedence.sh | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/test-dotenv-precedence.sh b/tests/test-dotenv-precedence.sh new file mode 100755 index 0000000..f2cc760 --- /dev/null +++ b/tests/test-dotenv-precedence.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +set -euo pipefail + +project_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +tmp_dir="$(mktemp -d)" +trap 'rm -rf "${tmp_dir}"' EXIT + +grep -Fqx 'set dotenv-filename := ".env"' "${project_root}/Justfile" +grep -Fqx '.env' "${project_root}/.gitignore" +if rg -F -- '--dotenv-path image-template.env' "${project_root}/.github/workflows"; then + echo 'CI must not load image-template.env as a dotenv file' >&2 + exit 1 +fi + +printf '%s\n' \ + 'set dotenv-load' \ + 'value := env_var("VALUE")' \ + 'show:' \ + ' @echo "{{value}}"' > "${tmp_dir}/justfile" +printf '%s\n' 'VALUE=from-dotenv' > "${tmp_dir}/.env" + +[[ "$(cd "${tmp_dir}" && just show)" == 'from-dotenv' ]] +[[ "$(cd "${tmp_dir}" && VALUE=from-runtime just show)" == 'from-runtime' ]] + +mkdir "${tmp_dir}/without-dotenv" +cp "${tmp_dir}/justfile" "${tmp_dir}/without-dotenv/justfile" +[[ "$(cd "${tmp_dir}/without-dotenv" && VALUE=from-runtime just show)" == 'from-runtime' ]] |
