name: Auto-Deploy Changed Stacks on: push: branches: - main jobs: deploy: runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v4 with: fetch-depth: 2 - name: Detect changed stacks and trigger Komodo webhooks run: | set -euo pipefail # --------------------------------------------------------------- # Webhook map: stack-name → Komodo webhook URL # Komodo webhook URLs are self-authenticating (token is embedded # in the URL path). Fill in URLs from: # Komodo UI → Stack → Webhooks tab → copy the full URL # --------------------------------------------------------------- declare -A WEBHOOK_MAP # heimdall stacks WEBHOOK_MAP["5etools"]="TODO" WEBHOOK_MAP["authentik"]="TODO" WEBHOOK_MAP["bentopdf"]="TODO" WEBHOOK_MAP["byparr"]="TODO" WEBHOOK_MAP["convertx"]="TODO" WEBHOOK_MAP["core"]="TODO" WEBHOOK_MAP["docker_registry"]="TODO" WEBHOOK_MAP["gitea"]="TODO" WEBHOOK_MAP["guardian"]="TODO" WEBHOOK_MAP["homelab-registry-mcp"]="TODO" WEBHOOK_MAP["karakeep"]="TODO" WEBHOOK_MAP["kitchenowl"]="TODO" WEBHOOK_MAP["ntfy"]="TODO" WEBHOOK_MAP["overseerr"]="TODO" WEBHOOK_MAP["profilarr"]="TODO" WEBHOOK_MAP["prowlarr"]="TODO" WEBHOOK_MAP["radarr"]="TODO" WEBHOOK_MAP["sabnzbd"]="TODO" WEBHOOK_MAP["snapotter"]="TODO" WEBHOOK_MAP["sonarr"]="TODO" WEBHOOK_MAP["sparkyfitness"]="TODO" WEBHOOK_MAP["tautulli"]="TODO" WEBHOOK_MAP["tracearr"]="TODO" WEBHOOK_MAP["trek"]="TODO" WEBHOOK_MAP["vaultwarden"]="TODO" WEBHOOK_MAP["vscode"]="TODO" WEBHOOK_MAP["weatherchannel"]="TODO" WEBHOOK_MAP["wizarr"]="TODO" WEBHOOK_MAP["zipline"]="TODO" # waldorf stacks WEBHOOK_MAP["immich"]="TODO" WEBHOOK_MAP["openwebui"]="TODO" WEBHOOK_MAP["pinchflat"]="TODO" WEBHOOK_MAP["plex"]="TODO" WEBHOOK_MAP["tunarr"]="TODO" # --------------------------------------------------------------- # Detect changed paths vs the previous commit # --------------------------------------------------------------- CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD) echo "=== Changed files ===" if [[ -z "$CHANGED_FILES" ]]; then echo " (none)" else echo "$CHANGED_FILES" fi echo "" # --------------------------------------------------------------- # Parse changed paths → extract {node} and {stack} # Expected pattern: nodes/{node}/{stack}/... # --------------------------------------------------------------- declare -A SEEN_STACKS declare -a STACKS_TO_DEPLOY declare -a UNMATCHED_PATHS while IFS= read -r filepath; do [[ -z "$filepath" ]] && continue IFS='/' read -ra PARTS <<< "$filepath" # Must start with "nodes" and have at least 4 components # (nodes / {node} / {stack} / file) [[ "${PARTS[0]}" != "nodes" ]] && continue [[ "${#PARTS[@]}" -lt 4 ]] && continue node="${PARTS[1]}" stack="${PARTS[2]}" [[ -z "$stack" ]] && continue # Deduplicate: skip if this stack was already queued [[ -n "${SEEN_STACKS[$stack]+_}" ]] && continue SEEN_STACKS["$stack"]=1 if [[ -n "${WEBHOOK_MAP[$stack]+_}" ]]; then STACKS_TO_DEPLOY+=("$stack") echo " Queued for deploy: $stack (node: $node)" else UNMATCHED_PATHS+=("$filepath (stack: $stack)") fi done <<< "$CHANGED_FILES" echo "" # --------------------------------------------------------------- # Warn about paths that have no webhook entry — not silent # --------------------------------------------------------------- if [[ "${#UNMATCHED_PATHS[@]}" -gt 0 ]]; then echo "=== WARNING: paths with no matching webhook entry ===" for p in "${UNMATCHED_PATHS[@]}"; do echo " - $p" done echo " Add these stack names to WEBHOOK_MAP in this workflow." echo "" fi # --------------------------------------------------------------- # Nothing under nodes/ changed # --------------------------------------------------------------- if [[ "${#STACKS_TO_DEPLOY[@]}" -eq 0 ]]; then echo "No stack changes detected — nothing to deploy." exit 0 fi # --------------------------------------------------------------- # POST to each Komodo webhook # --------------------------------------------------------------- echo "=== Triggering Komodo webhooks ===" FAILED=0 for stack in "${STACKS_TO_DEPLOY[@]}"; do url="${WEBHOOK_MAP[$stack]}" if [[ "$url" == "TODO" ]]; then echo " SKIP: $stack — webhook URL not configured yet (fill in WEBHOOK_MAP)" continue fi echo -n " → $stack ... " HTTP_STATUS=$(curl --silent --show-error --output /dev/null \ --write-out "%{http_code}" \ --max-time 30 \ --request POST "$url" \ --header "Content-Type: application/json" \ --data '{"trigger":"gitea-push"}') if [[ "$HTTP_STATUS" =~ ^2 ]]; then echo "HTTP $HTTP_STATUS OK" else echo "HTTP $HTTP_STATUS FAILED" FAILED=1 fi done echo "" if [[ "$FAILED" -ne 0 ]]; then echo "ERROR: One or more Komodo webhook POSTs returned a non-2xx status." exit 1 fi echo "All webhooks triggered successfully."