mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-12-06 01:40:19 +00:00
feat(ci): diff-driven app whitelist for deploy tests
Narrow the test-deploy-{server,universal,workstation} matrix to roles
actually impacted by the branch's diff against origin/main, expanded
transitively over run_after + dependencies + shared services.
Why: full-matrix deploy CI on every PR is wasteful; explicit per-PR
whitelisting is error-prone. The resolver derives the affected set
automatically while remaining fail-safe.
Behaviour (in resolve_effective_whitelist.sh precedence order):
- whitelist input "__ALL__" -> empty whitelist (force full deploy)
- whitelist input non-empty -> verbatim
- whitelist input empty -> diff vs origin/main
- empty diff or any path outside roles/<role>/ -> __ALL__
- all paths under roles/<role>/ -> reverse closure
Fail-safe: any seed that is not modellable in CombinedResolver
(no application_id and not referenced by any role's run_after) and
any resolver runtime error MUST trigger a fall-back to __ALL__.
The closure never silently shrinks the deploy matrix.
test-deploy-local.yml is intentionally exempt (local/manual dispatch
keeps explicit whitelist semantics).
Documented in pipeline.md and workflows.md.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
1 parent
196c5bac28
commit
91fadbdcc5
12 files changed
+533
-12
No files matched your search
Executable
+119
@@ -0,0 +1,119 @@
|
||||
#!/usr/bin/env bash
|
||||
# scripts/meta/resolve/diff/affected_roles.sh
|
||||
#
|
||||
# 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.applications.resolution.affected.
|
||||
#
|
||||
# Output (single line on stdout):
|
||||
# __ALL__ full deploy needed. Emitted when:
|
||||
# * the diff is empty, OR
|
||||
# * any changed path lives outside
|
||||
# roles/<role>/, 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/all.sh" ]]; then
|
||||
# shellcheck source=scripts/meta/env/all.sh
|
||||
source "scripts/meta/env/all.sh"
|
||||
fi
|
||||
|
||||
compose_ci_exec() {
|
||||
local -a compose_args=(docker compose --env-file env.ci)
|
||||
|
||||
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
|
||||
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.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}"
|
||||
Reference in new issue
Block a user