Files
kevinveenbirkenbachandClaude Opus 5.5 1539bb6698 fix(ci): select only the roles whose rounds really deploy a changed role
PR 2846 changed only web-app-n8n and CI deployed every variant of ten unrelated roles: the disk closure linked each matrix consumer to n8n through matrix's dynamic n8n flag, and a role none of whose variant rounds deploys the seed fell back to all of its variants. The selection now drops such roles and keeps every other role only with the variants whose round deploys a seed. Its prefilter is built from the union of each role's disk, variant and nested services, so service keys only a variant declares (web-app-lam in moodle and openbao) are no longer missed. run_after no longer counts as an include, and a seed without application_id falls back to a full deploy. Checked against the planner's rounds for all 198 app seeds: exact. MEDUSA acceptances: RH005 on both existing raise SystemExit lines (exit contract, the caller maps any non-zero exit to __ALL__).

🎯 Fix: 95 %
💥 Break: 4 %
💸 Tokens: 100 %
⏱️ Velocity: 100 %
🛡️ Security: 100 %
🏆 Score: 91
🚦 Gate: ✅ 90/5, tokens and velocity <= 100, security 100 %

Created-with: https://s.veen.world/skills
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 22:43:42 +00:00

114 lines
3.7 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# Output (single line on stdout):
# __ALL__ full deploy needed. Emitted when:
# * the diff is empty, OR
# * any changed path outside
# roles/<role>/ is neither a
# Markdown or reStructuredText file
# (the `.md`/`.rst` skip-list mirrors
# scripts/meta/resolve/pr/scope.sh's
# `is_markdown_or_rst`) nor under
# tests/, 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).
# <token> [<token> ...] restricted deploy set (whitelist).
# A token is a role id, narrowed to the
# variants that reach a seed where not all
# of them do (`web-app-x#0,2`, see
# utils.github.variant.selection).
#
# Pre-conditions:
# - The host Python interpreter referenced by ${PYTHON:-python3} has the
# project's resolver deps installed (e.g. via `make install`).
# - `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
emit_all() {
echo "__ALL__"
exit 0
}
baseline_remote="$(./scripts/meta/resolve/baseline_remote.sh)"
git fetch --quiet --no-tags --depth=50 "${baseline_remote}" main:refs/remotes/origin/main --force >/dev/null 2>&1 ||
git fetch --quiet --no-tags "${baseline_remote}" main:refs/remotes/origin/main --force
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 | tests/*)
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="$(
"${PYTHON}" -m cli.meta.roles.applications.resolution.affected \
--changed-roles "${seed_list[@]}"
)"
resolver_rc=$?
set -e
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}"