maintainers/scripts: add get-maintainer-pings-between.sh

Sometimes it is useful to see which maintainers your change will ping,
to know who you are going to spam in advance.

authored by

Morgan Jones and committed by
Tristan Ross
0173b120 e5306ea0

+89
+11
maintainers/scripts/README.md
··· 57 57 58 58 [`maintainer-list.nix`]: ../maintainer-list.nix 59 59 60 + ### `get-maintainer-pings-between.sh` 61 + 62 + Gets which maintainers would be pinged between two Nixpkgs revisions. 63 + Outputs a JSON object on stdout mapping GitHub usernames to the attributes 64 + that they would be getting pinged for. 65 + 66 + Example: 67 + 68 + ```sh 69 + maintainers/scripts/get-maintainer-pings-between.sh HEAD^ HEAD 70 + ``` 60 71 61 72 ## Conventions 62 73
+78
maintainers/scripts/get-maintainer-pings-between.sh
··· 1 + #!/usr/bin/env nix-shell 2 + #!nix-shell -i bash -p git jq 3 + 4 + # Outputs a list of maintainers that would be pinged across two nixpkgs revisions. 5 + # Authors: 6 + # Morgan Jones (@numinit) 7 + # Tristan Ross (@RossComputerGuy) 8 + 9 + set -euo pipefail 10 + 11 + if [ $# -lt 2 ]; then 12 + echo "Usage: $0 <rev-from> <rev-to>" >&2 13 + exit 1 14 + fi 15 + 16 + repo="$(git rev-parse --show-toplevel)" 17 + system="$(nix-instantiate --eval --expr builtins.currentSystem)" 18 + rev1="$(git -C "$repo" rev-parse "$1")" 19 + rev2="$(git -C "$repo" rev-parse "$2")" 20 + 21 + echo "Touched files:" >&2 22 + git -C "$repo" diff --name-only "$rev1" "$rev2" \ 23 + | jq --raw-input --slurp 'split("\n")[:-1]' | tee "$TMPDIR/touched-files.json" >&2 24 + 25 + # Runs an eval in the given worktree, outputting the path to $TMPDIR/$1.path. 26 + # $1: The revision SHA. 27 + eval_in_worktree() ( 28 + mkdir -p .worktree 29 + local rev="$1" 30 + local tree=".worktree/$rev" 31 + if [ ! -d "$tree" ]; then 32 + git -C "$repo" worktree add -f -d "$tree" "$rev" >&2 33 + fi 34 + cd "$tree" 35 + 36 + local workdir="$TMPDIR/$rev" 37 + rm -rf "$workdir" 38 + mkdir -p "$workdir" 39 + 40 + nix-build ci -A eval.attrpathsSuperset -o "$workdir/paths" >&2 41 + mkdir -p "$workdir/intermediates" 42 + nix-build ci -A eval.singleSystem \ 43 + --arg evalSystem "$system" \ 44 + --arg attrpathFile "$workdir/paths/paths.json" \ 45 + --arg chunkSize ${CHUNK_SIZE:-10000} \ 46 + -o "$workdir/intermediates/.intermediate-1" >&2 47 + 48 + # eval.combine nix-build needs a directory, not a symlink 49 + cp -RL "$workdir/intermediates/.intermediate-1" "$workdir/intermediates/intermediate-1" 50 + chmod -R +w "$workdir/intermediates/intermediate-1" 51 + rm -rf "$workdir/intermediates/.intermediate-1" 52 + 53 + nix-build ci -A eval.combine \ 54 + --arg resultsDir "$workdir/intermediates" \ 55 + -o "$workdir/result" >&2 56 + ) 57 + 58 + eval_in_worktree "$rev1" & 59 + pid1=$! 60 + eval_in_worktree "$rev2" & 61 + pid2=$! 62 + 63 + wait $pid1 64 + wait $pid2 65 + 66 + path1="$TMPDIR/$rev1" 67 + path2="$TMPDIR/$rev2" 68 + 69 + # Use the repo this script was executed in to get accurate maintainer info 70 + nix-build "$repo/ci" -A eval.compare \ 71 + --arg beforeResultDir "$path1/result" \ 72 + --arg afterResultDir "$path2/result" \ 73 + --arg touchedFilesJson "$TMPDIR/touched-files.json" \ 74 + --arg byName true \ 75 + -o comparison 76 + 77 + echo "Pinged maintainers (check $repo/comparison for more details)" >&2 78 + jq < comparison/maintainers.json