maintainers: add script and workflows to check sortedness

the script can output a list of sed commands to create the order it
expects to find. this was mainly useful for initially sorting the list,
but we'll keep it here for later reference.

Co-authored-by: Jörg Thalheim <Mic92@users.noreply.github.com>

pennae 4a694fc5 91e49d60

+78
+21
.github/workflows/check-maintainers-sorted.yaml
··· 1 + name: "Check that maintainer list is sorted" 2 + 3 + on: 4 + pull_request: 5 + paths: 6 + - 'maintainers/maintainer-list.nix' 7 + permissions: 8 + contents: read 9 + 10 + jobs: 11 + nixos: 12 + runs-on: ubuntu-latest 13 + if: github.repository_owner == 'NixOS' 14 + steps: 15 + - uses: actions/checkout@v3 16 + - uses: cachix/install-nix-action@v19 17 + with: 18 + # explicitly enable sandbox 19 + extra_nix_config: sandbox = true 20 + - name: Check that maintainer-list.nix is sorted 21 + run: nix-instantiate --eval maintainers/scripts/check-maintainers-sorted.nix
+57
maintainers/scripts/check-maintainers-sorted.nix
··· 1 + let 2 + lib = import ../../lib; 3 + inherit (lib) 4 + add attrNames elemAt foldl' genList length replaceStrings sort toLower trace; 5 + 6 + maintainers = import ../maintainer-list.nix; 7 + simplify = replaceStrings [ "-" "_" ] [ "" "" ]; 8 + compare = a: b: simplify (toLower a) < simplify (toLower b); 9 + namesSorted = 10 + sort 11 + (a: b: a.key < b.key) 12 + (map 13 + (n: let pos = builtins.unsafeGetAttrPos n maintainers; 14 + in assert pos == null -> throw "maintainers entry ${n} is malformed"; 15 + { name = n; line = pos.line; key = toLower (simplify n); }) 16 + (attrNames maintainers)); 17 + before = { name, line, key }: 18 + foldl' 19 + (acc: n: if n.key < key && (acc == null || n.key > acc.key) then n else acc) 20 + null 21 + namesSorted; 22 + errors = foldl' add 0 23 + (map 24 + (i: let a = elemAt namesSorted i; 25 + b = elemAt namesSorted (i + 1); 26 + lim = let t = before a; in if t == null then "the initial {" else t.name; 27 + in if a.line >= b.line 28 + then trace 29 + ("maintainer ${a.name} (line ${toString a.line}) should be listed " 30 + + "after ${lim}, not after ${b.name} (line ${toString b.line})") 31 + 1 32 + else 0) 33 + (genList (i: i) (length namesSorted - 1))); 34 + in 35 + assert errors == 0; "all good!" 36 + 37 + # generate edit commands to sort the list. 38 + # may everything following the last current entry (closing } ff) in the wrong place 39 + # with lib; 40 + # concatStringsSep 41 + # "\n" 42 + # (let first = foldl' (acc: n: if n.line < acc then n.line else acc) 999999999 namesSorted; 43 + # commands = map 44 + # (i: let e = elemAt namesSorted i; 45 + # begin = foldl' 46 + # (acc: n: if n.line < e.line && n.line > acc then n.line else acc) 47 + # 1 48 + # namesSorted; 49 + # end = 50 + # foldl' (acc: n: if n.line > e.line && n.line < acc then n.line else acc) 51 + # 999999999 52 + # namesSorted; 53 + # in "${toString e.line},${toString (end - 1)} p") 54 + # (genList (i: i) (length namesSorted)); 55 + # in map 56 + # (c: "sed -ne '${c}' maintainers/maintainer-list.nix") 57 + # ([ "1,${toString (first - 1)} p" ] ++ commands))