1# to run these tests (and the others)
2# nix-build nixpkgs/lib/tests/release.nix
3# These tests should stay in sync with the comment in maintainers/maintainers-list.nix
4{
5 # The pkgs used for dependencies for the testing itself
6 pkgs ? import ../.. { },
7 lib ? pkgs.lib,
8}:
9
10let
11 checkMaintainer =
12 handle: uncheckedAttrs:
13 let
14 prefix = [
15 "lib"
16 "maintainers"
17 handle
18 ];
19 checkedAttrs =
20 (lib.modules.evalModules {
21 inherit prefix;
22 modules = [
23 ./maintainer-module.nix
24 {
25 _file = toString ../../maintainers/maintainer-list.nix;
26 config = uncheckedAttrs;
27 }
28 ];
29 }).config;
30
31 checks =
32 lib.optional (checkedAttrs.github != null && checkedAttrs.githubId == null) ''
33 echo ${lib.escapeShellArg (lib.showOption prefix)}': If `github` is specified, `githubId` must be too.'
34 # Calling this too often would hit non-authenticated API limits, but this
35 # shouldn't happen since such errors will get fixed rather quickly
36 info=$(curl -sS https://api.github.com/users/${checkedAttrs.github})
37 id=$(jq -r '.id' <<< "$info")
38 echo "The GitHub ID for GitHub user ${checkedAttrs.github} is $id:"
39 echo -e " githubId = $id;\n"
40 ''
41 ++
42 lib.optional
43 (checkedAttrs.email == null && checkedAttrs.github == null && checkedAttrs.matrix == null)
44 ''
45 echo ${lib.escapeShellArg (lib.showOption prefix)}': At least one of `email`, `github` or `matrix` must be specified, so that users know how to reach you.'
46 ''
47 ++
48 lib.optional (checkedAttrs.email != null && lib.hasSuffix "noreply.github.com" checkedAttrs.email)
49 ''
50 echo ${lib.escapeShellArg (lib.showOption prefix)}': If an email address is given, it should allow people to reach you. If you do not want that, you can just provide `github` or `matrix` instead.'
51 '';
52 in
53 lib.deepSeq checkedAttrs checks;
54
55 missingGithubIds = lib.concatLists (lib.mapAttrsToList checkMaintainer lib.maintainers);
56
57 success = pkgs.runCommand "checked-maintainers-success" { } ">$out";
58
59 failure =
60 pkgs.runCommand "checked-maintainers-failure"
61 {
62 nativeBuildInputs = [
63 pkgs.curl
64 pkgs.jq
65 ];
66 outputHash = "sha256:${lib.fakeSha256}";
67 outputHAlgo = "sha256";
68 outputHashMode = "flat";
69 SSL_CERT_FILE = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt";
70 }
71 ''
72 ${lib.concatStringsSep "\n" missingGithubIds}
73 exit 1
74 '';
75in
76if missingGithubIds == [ ] then success else failure