fix: resolve sporadic environment variable loading in arty.sh

- Fix race condition in load_env_vars() caused by process substitution
- Replace unreliable `< <(yq eval ...)` with stable variable capture
- Ensure environment variables are consistently loaded on every execution
- Add yq binary (mikefarah/yq v4.48.1) for reliable YAML parsing

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-13 18:18:48 +01:00
parent 3c456698e1
commit 2c19c1ea9a
2 changed files with 9 additions and 7 deletions

16
arty.sh
View File

@@ -51,7 +51,7 @@ log_success() {
}
log_warn() {
echo -e "${YELLOW}[ ]${NC} $1" >&2
echo -e "${YELLOW}[<EFBFBD>]${NC} $1" >&2
}
log_error() {
@@ -65,7 +65,7 @@ log_debug() {
}
log_step() {
echo -e "${CYAN}[]${NC} $1" >&2
echo -e "${CYAN}[<EFBFBD>]${NC} $1" >&2
}
# ============================================================================
@@ -96,7 +96,8 @@ load_env_vars() {
log_debug "Loading environment variables from '$current_env' environment"
# First load default variables if they exist
if yq eval '.envs.default' "$config_file" 2>/dev/null | grep -q -v '^null$'; then
local default_envs=$(yq eval '.envs.default | to_entries | .[] | .key + "=" + .value' "$config_file" 2>/dev/null)
if [[ -n "$default_envs" ]] && [[ "$default_envs" != "null" ]]; then
while IFS='=' read -r key value; do
if [[ -n "$key" ]] && [[ "$key" != "null" ]] && [[ -n "$value" ]]; then
# Only export if not already set (for default env only)
@@ -107,18 +108,19 @@ load_env_vars() {
export "$key=$value"
log_debug " Set $key (from default)"
fi
done < <(yq eval '.envs.default | to_entries | .[] | .key + "=" + .value' "$config_file" 2>/dev/null)
done <<< "$default_envs"
fi
# Then load environment-specific variables (which can override defaults)
if [[ "$current_env" != "default" ]]; then
if yq eval ".envs.$current_env" "$config_file" 2>/dev/null | grep -q -v '^null$'; then
local env_envs=$(yq eval ".envs.$current_env | to_entries | .[] | .key + \"=\" + .value" "$config_file" 2>/dev/null)
if [[ -n "$env_envs" ]] && [[ "$env_envs" != "null" ]]; then
while IFS='=' read -r key value; do
if [[ -n "$key" ]] && [[ "$key" != "null" ]] && [[ -n "$value" ]]; then
export "$key=$value"
log_debug " Set $key (from $current_env)"
fi
done < <(yq eval ".envs.$current_env | to_entries | .[] | .key + \"=\" + .value" "$config_file" 2>/dev/null)
done <<< "$env_envs"
fi
fi
}
@@ -722,7 +724,7 @@ build_reference_tree() {
# Add location info
if [[ -n "$into" ]]; then
printf " ${MAGENTA} %s${NC}" "$into"
printf " ${MAGENTA}<EFBFBD> %s${NC}" "$into"
fi
echo

BIN
yq Executable file

Binary file not shown.