From 10411b5e32b78f57b6ad995c434cfc4fc390d689 Mon Sep 17 00:00:00 2001 From: tranch Date: Wed, 26 Aug 2026 10:59:21 +0800 Subject: 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. --- tests/test-dotenv-precedence.sh | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 tests/test-dotenv-precedence.sh (limited to 'tests') 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' ]] -- cgit v1.2.3