Files
computer-playbook/scripts/meta/resolve/diff/affected_roles.sh
T
kevinveenbirkenbachandClaude Opus 4.7 9a578952c3 feat(env): SPOT env-pipeline + INFINITO_* namespace
Replace 8 bash env modules with a single Python generator
(cli.meta.env) that materialises env/static.env + runtime context
into a gitignored .env. Each variable lives in its own handler
under utils/env/handlers/; defaults carry inline one-line `# ...`
comments.

Rename to the INFINITO_* schema:
- workflow inputs: APPS, SERVICES_DISABLED, CMD, DEBUG, WHITELIST,
  BUNDLES, FULL_CYCLE, VARIANT, RUN_FLAGS, LIMIT_HOST, PARALLEL
- inventory: INVENTORY_DIR / INVENTORY_FILE / HOST_VARS_FILE,
  PW_FILE -> INVENTORY_PASSWORD_FILE
- venv: VENV_BASE / VENV_FALLBACK / VENV_NAME
- new SPOT defaults: COMPILE_SILENCE, CONTAINER_NO_CA,
  WAIT_HEALTH_TIMEOUT_S, PACKAGE_CACHE_FRONTEND_INIT_IMAGE,
  promoted IMAGE_TAG from GHA-only to general passthrough

compose.yml hardening:
- inline \${VAR:-default} removed; strict \${VAR:?...} everywhere
- new integration lint blocks regressions

Tooling:
- scripts/install/all.sh owns the stamp-file install logic
  (Makefile target delegates)
- scripts/meta/env/load.sh is the single shell entry point;
  8 bash modules deleted
- new shell lint: no INFINITO_* defaults outside env/static.env

Tests:
- 93 new unit tests for utils/env/{builder,parser,runtime,writer}
- restructure tests/lint into repository/ (file-content rules) vs
  filesystem/{shell,python,env}/ (filesystem-shape rules)
- drift + smoke integration tests against the generator

Docs:
- variables.md is now a pointer; per-variable docs live next to
  the key in env/static.env / env/ci.env
- compose.yml.md drops the Default column

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-20 20:40:34 +02:00

131 lines
4.0 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# Compute which roles are affected by the current branch's diff against
# `origin/main`, expanded transitively over run_after + dependencies +
# services edges via cli.meta.roles.applications.resolution.affected.
#
# Output (single line on stdout):
# __ALL__ full deploy needed. Emitted when:
# * the diff is empty, OR
# * any changed path outside
# roles/<role>/ is not a Markdown
# or reStructuredText file (the
# `.md`/`.rst` skip-list mirrors
# scripts/meta/resolve/pr/scope.sh's
# `is_markdown_or_rst`), OR
# * the diff contains only such
# skipped paths and no role seeds
# could be derived, OR
# * any seed role is non-modellable
# in the reverse resolver
# (resolver exit 2), OR
# * the resolver itself errors out
# (any other non-zero exit).
# <role-id> [<role-id> ...] restricted deploy set (whitelist).
#
# Pre-conditions:
# - The container started by `make up` is running (the Python resolver
# is invoked via `docker compose ... exec infinito`, identical to the
# pattern used in scripts/meta/resolve/apps.sh).
# - `git fetch origin main` is reachable (caller already did checkout).
#
# Exit codes:
# 0 in all defined output cases (including the fail-safe __ALL__).
# The script is fail-safe by design: any resolver failure widens the
# deploy matrix to "all", it never narrows it.
set -euo pipefail
PYTHON="${PYTHON:-python3}"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/../../../.." && pwd)"
cd "$REPO_ROOT"
if [[ -f "scripts/meta/env/load.sh" ]]; then
# shellcheck source=scripts/meta/env/load.sh
source "scripts/meta/env/load.sh"
fi
compose_ci_exec() {
local -a compose_args=(docker compose --env-file env/ci.env)
if [[ -f "env.development" ]]; then
compose_args+=(--env-file env.development)
fi
compose_args+=(--profile ci exec -T infinito)
NIX_CONFIG="${NIX_CONFIG:-}" \
INFINITO_DISTRO="${INFINITO_DISTRO}" \
"${compose_args[@]}" "$@"
}
emit_all() {
echo "__ALL__"
exit 0
}
git fetch --quiet --no-tags --prune --depth=50 origin main >/dev/null 2>&1 ||
git fetch --quiet --no-tags --prune origin main
if base="$(git merge-base origin/main HEAD 2>/dev/null)"; then
mapfile -t changed_paths < <(git diff --name-only "${base}" HEAD --)
else
mapfile -t changed_paths < <(git diff --name-only origin/main HEAD --)
fi
if ((${#changed_paths[@]} == 0)); then
emit_all
fi
declare -A seed_roles=()
for path in "${changed_paths[@]}"; do
[[ -z "${path}" ]] && continue
if [[ "${path}" != roles/*/* ]]; then
case "${path}" in
*.md | *.rst)
continue
;;
esac
emit_all
fi
role="${path#roles/}"
role="${role%%/*}"
[[ -z "${role}" ]] && emit_all
seed_roles["${role}"]=1
done
if ((${#seed_roles[@]} == 0)); then
emit_all
fi
mapfile -t seed_list < <(printf '%s\n' "${!seed_roles[@]}" | sort)
set +e
resolved="$(
compose_ci_exec \
"${PYTHON}" -m cli.meta.roles.applications.resolution.affected \
--changed-roles "${seed_list[@]}"
)"
resolver_rc=$?
set -e
# Exit 2 means "non-modellable seed; fall back to full deploy".
# Any other non-zero is a resolver/runtime error; we still fail-safe to
# __ALL__ rather than risk silently shrinking the deploy matrix.
if ((resolver_rc != 0)); then
emit_all
fi
resolved="${resolved//$'\r'/}"
resolved="${resolved#"${resolved%%[![:space:]]*}"}"
resolved="${resolved%"${resolved##*[![:space:]]}"}"
if [[ -z "${resolved}" ]]; then
emit_all
fi
printf '%s\n' "${resolved}"