#!/bin/sh # The packages a change touches, and every package that depends on them, # one per line: what CI checks and tests on a pull request. # # scripts/affected.sh [BASE] (default: origin/main) # # A package is a top-level directory holding a louise.toml. Dependencies # are its path dependencies, dev-dependencies included (`gen`). A change # outside every package (scripts, workflows, this README) affects them all. set -eu cd "$(dirname "$0")/.." base="${1:-origin/main}" packages() { for m in */louise.toml; do dirname "$m"; done } # The packages `$1` depends on by path, by their directory names. deps() { sed -n 's/.*path *= *"\.\.\/\([A-Za-z0-9_-]*\)".*/\1/p' "$1/louise.toml" } # Committed and uncommitted changes since the branch left `base`, and new # files. changed=$( { git diff --name-only "$(git merge-base "$base" HEAD)"; git ls-files --others --exclude-standard; } | sort -u) if [ -z "$changed" ]; then exit 0 fi all=$(packages) touched="" for f in $changed; do top=${f%%/*} if [ "$top" = "$f" ] || ! printf '%s\n' "$all" | grep -qx "$top"; then printf '%s\n' "$all" exit 0 fi touched="$touched $top" done # Close over the reverse dependencies. selected=$(printf '%s\n' $touched | sort -u) while :; do more="$selected" for p in $all; do for d in $(deps "$p"); do if printf '%s\n' "$selected" | grep -qx "$d"; then more="$more $p" fi done done more=$(printf '%s\n' "$more" | sort -u) [ "$more" = "$selected" ] && break selected="$more" done printf '%s\n' "$selected"