refactor: simplify stack management state

This commit is contained in:
lingkai5wu committed 2026-10-10 16:25:52 +08:00
1 parent fc2504df5a
commit 74b6f8ad74
1 file changed
+10 -27
+10 -27
View File
@@ -88,14 +88,14 @@ validate_name() {
die "invalid $kind name: $value" die "invalid $kind name: $value"
} }
# manage.conf DSL: set the default concurrency for groups without an override. # Set the default concurrency for groups without an override.
max_parallel() { max_parallel() {
[[ $# -eq 1 ]] || die "max_parallel expects exactly one value" [[ $# -eq 1 ]] || die "max_parallel expects exactly one value"
validate_parallel_limit "$1" validate_parallel_limit "$1"
DEFAULT_MAX_PARALLEL="$1" DEFAULT_MAX_PARALLEL="$1"
} }
# manage.conf DSL: declare an ordered group and its stacks. # Declare an ordered group and its stacks.
# Usage: group NAME [--parallel N] STACK... # Usage: group NAME [--parallel N] STACK...
group() { group() {
[[ $# -ge 2 ]] || die "group expects NAME [--parallel N] STACK..." [[ $# -ge 2 ]] || die "group expects NAME [--parallel N] STACK..."
@@ -134,7 +134,7 @@ group() {
CONFIG_GROUP_STACKS+=("$*") CONFIG_GROUP_STACKS+=("$*")
} }
# manage.conf DSL: exclude stacks from all bulk operations. # Exclude stacks from all bulk operations.
exclude() { exclude() {
[[ $# -ge 1 ]] || die "exclude expects at least one stack" [[ $# -ge 1 ]] || die "exclude expects at least one stack"
@@ -152,16 +152,8 @@ exclude() {
load_config() { load_config() {
[[ -f "$CONFIG_FILE" ]] || return 0 [[ -f "$CONFIG_FILE" ]] || return 0
bash -n "$CONFIG_FILE" || die "syntax error in config file: $CONFIG_FILE" # The trusted config calls max_parallel, group, and exclude above.
# This is a trusted Bash configuration file that calls the DSL above. source "$CONFIG_FILE" || die "cannot load config file: $CONFIG_FILE"
source "$CONFIG_FILE"
local legacy
for legacy in WHITELIST BLACKLIST PRIORITY; do
if declare -p "$legacy" >/dev/null 2>&1; then
die "$legacy is no longer supported; migrate $CONFIG_FILE to group/exclude directives"
fi
done
} }
discover_stacks() { discover_stacks() {
@@ -427,27 +419,18 @@ run_all_grouped() {
run_all_sequential() { run_all_sequential() {
local action="$1" local action="$1"
local stack local stack
local -a failed_stacks=()
RUN_SUCCESS=0
RUN_FAILED=0
RUN_FAILED_STACKS=()
RUN_SKIPPED_GROUPS=()
warn_unassigned warn_unassigned
for stack in "${MANAGED_STACKS[@]}"; do for stack in "${MANAGED_STACKS[@]}"; do
if run_stack "$stack" "$action"; then run_stack "$stack" "$action" || failed_stacks+=("$stack")
((RUN_SUCCESS += 1))
else
((RUN_FAILED += 1))
RUN_FAILED_STACKS+=("$stack")
fi
done done
if ((RUN_FAILED > 0)); then if ((${#failed_stacks[@]} > 0)); then
echo echo
echo "Failed stacks: ${RUN_FAILED_STACKS[*]}" >&2 echo "Failed stacks: ${failed_stacks[*]}" >&2
return 1
fi fi
((RUN_FAILED == 0))
} }
list_stacks() { list_stacks() {