#!/usr/bin/env sh set -eu manifest="${1:-docs/keycloak-branch-manifest.tsv}" notes_dir="${KEYCLOAK_BRANCH_NOTES_DIR:-/home/donghyeon/workspace/ai-tools/llm-wiki/raw/branch-notes}" expected_count="$(awk 'NR > 1 { count += 1 } END { print count + 0 }' "$manifest")" if [ "$expected_count" -ne 39 ]; then echo "manifest must contain exactly 39 Keycloak branches; found $expected_count" >&2 exit 1 fi note_count="$(find "$notes_dir" -maxdepth 1 -type f -name 'feature-keycloak-*.md' | wc -l)" if [ "$note_count" -ne 39 ]; then echo "branch-note inventory must contain exactly 39 files; found $note_count" >&2 exit 1 fi missing=0 unmerged=0 tab="$(printf '\t')" while IFS="$tab" read -r branch target delivery; do [ "$branch" = "branch" ] && continue note_name="$(printf '%s\n' "$branch" | sed 's#^feature/keycloak-#feature-keycloak-#').md" if [ ! -f "$notes_dir/$note_name" ]; then echo "missing branch note: $note_name" >&2 missing=$((missing + 1)) fi if ! git show-ref --verify --quiet "refs/heads/$branch"; then echo "missing local branch: $branch" >&2 missing=$((missing + 1)) continue fi case "$target" in common) target_branch="develop" ;; ap1) target_branch="develop-keycloak-pattern1" ;; ap2) target_branch="develop-keycloak-pattern2" ;; ap3) target_branch="develop-keycloak-pattern3" ;; ap4) target_branch="develop-keycloak-pattern4" ;; *) echo "unknown target '$target' for $branch ($delivery)" >&2 exit 1 ;; esac if ! git merge-base --is-ancestor "$branch" "$target_branch"; then echo "feature tip is not merged: $branch -> $target_branch" >&2 unmerged=$((unmerged + 1)) fi done < "$manifest" if [ "$missing" -ne 0 ] || [ "$unmerged" -ne 0 ]; then echo "Keycloak branch audit failed: missing=$missing unmerged=$unmerged" >&2 exit 1 fi echo "Keycloak branch audit passed: 39/39 branches exist and are merged"