aien-architecture-mv
Canonical architecture for the AIEN ecosystem: flows, boundaries, ADRs, and the map from design to implementation repositories.
Brought by drakestapleton
aien-architecture-mv / tools / zero-legacy / portfolio.sh
| 1 | #!/bin/sh |
| 2 | # portfolio.sh LIST OUT ZLBUILD: reproducible source/ELF closure snapshot of many repositories. |
| 3 | # LIST lines are "NAME<TAB>SHA<TAB>ARCHIVED" (aien-dev/NAME at commit SHA). For each line the |
| 4 | # repository is fetched at exactly SHA (depth 1) into OUT/work, ZLBUILD/closure classifies every |
| 5 | # file (transitional inventory mode), ZLBUILD/elfclose classifies every file closure reports as |
| 6 | # ELF, and one row is appended to OUT/summary.tsv. Per-repository rows stay in OUT/rows/NAME.tsv |
| 7 | # and OUT/elf/NAME.tsv. Rerunning with the same LIST reproduces the same rows (only the order of |
| 8 | # lines inside OUT/rows/*.tsv follows the filesystem). A fetch failure gives a FETCH_FAILED row. |
| 9 | # This driver is shell (an outstanding SHELL row under #316); the classification is seeded Omega. |
| 10 | set -u |
| 11 | list=$1; out=$2; zl=$3 |
| 12 | mkdir -p "$out/rows" "$out/elf" |
| 13 | w=$out/work |
| 14 | [ -d "$w/.git" ] || git init -q "$w" |
| 15 | cats="OM C_H RUST PYTHON SHELL OSC HEXASM ELF ARCHIVE DOC OTHER HIDDEN WRAPPER DATA GENERATED EXTERNAL FOREIGN SYMLINK FORGED SKIP MAKE UNREADABLE" |
| 16 | { printf 'repo\tsha\tarchived'; for c in $cats; do printf '\t%s' "$c"; done |
| 17 | printf '\tOUTSTANDING\tUNKNOWN\tELF_FOREIGN\tELF_UNMARKED\tELF_UNKNOWN\n'; } > "$out/summary.tsv" |
| 18 | while IFS=' ' read -r name sha arch; do |
| 19 | case "$name" in ''|'#'*) continue ;; esac |
| 20 | if ! git -C "$w" fetch -q --depth 1 "https://github.com/aien-dev/$name.git" "$sha" 2>"$out/fetch.err" \ |
| 21 | || ! git -C "$w" checkout -q -f --detach FETCH_HEAD 2>>"$out/fetch.err" \ |
| 22 | || [ "$(git -C "$w" rev-parse HEAD)" != "$sha" ]; then |
| 23 | printf '%s\t%s\t%s\tFETCH_FAILED\n' "$name" "$sha" "$arch" >> "$out/summary.tsv"; continue |
| 24 | fi |
| 25 | git -C "$w" clean -q -ffdx |
| 26 | (cd "$w" && "$zl/closure" .) > "$out/rows/$name.tsv" |
| 27 | grep '^ELF ' "$out/rows/$name.tsv" | cut -f2 > "$out/elf.list" |
| 28 | : > "$out/elf/$name.tsv" |
| 29 | if [ -s "$out/elf.list" ]; then |
| 30 | (cd "$w" && tr '\n' '\0' < "$out/elf.list" | xargs -0 "$zl/elfclose" elf) > "$out/elf/$name.tsv" |
| 31 | fi |
| 32 | row=$(printf '%s\t%s\t%s' "$name" "$sha" "$arch") |
| 33 | for c in $cats OUTSTANDING UNKNOWN; do |
| 34 | v=$(sed -n "s/^# $c \([0-9]*\)$/\1/p" "$out/rows/$name.tsv"); row="$row ${v:-0}" |
| 35 | done |
| 36 | for c in FOREIGN UNMARKED UNKNOWN; do |
| 37 | v=$(sed -n "s/^# $c \([0-9]*\)$/\1/p" "$out/elf/$name.tsv"); row="$row ${v:-0}" |
| 38 | done |
| 39 | printf '%s\n' "$row" >> "$out/summary.tsv" |
| 40 | git -C "$w" reflog expire --expire=now --all |
| 41 | git -C "$w" gc -q --prune=now |
| 42 | done < "$list" |
| 43 | echo "PORTFOLIO rows=$(($(wc -l < "$out/summary.tsv") - 1)) failed=$(grep -c FETCH_FAILED "$out/summary.tsv")" |