summary refs log tree commit diff
path: root/lib/tests/maintainers.nix
blob: 3cbfba569481cbc18fbb3df368c9c796d1b626b3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# to run these tests (and the others)
# nix-build nixpkgs/lib/tests/release.nix
{ # The pkgs used for dependencies for the testing itself
  pkgs
, lib
}:

let
  inherit (lib) types;

  maintainerModule = { config, ... }: {
    options = {
      name = lib.mkOption {
        type = types.str;
      };
      email = lib.mkOption {
        type = types.str;
      };
      matrix = lib.mkOption {
        type = types.nullOr types.str;
        default = null;
      };
      github = lib.mkOption {
        type = types.nullOr types.str;
        default = null;
      };
      githubId = lib.mkOption {
        type = types.nullOr types.ints.unsigned;
        default = null;
      };
      keys = lib.mkOption {
        type = types.listOf (types.submodule {
          options.longkeyid = lib.mkOption { type = types.str; };
          options.fingerprint = lib.mkOption { type = types.str; };
        });
        default = [];
      };
    };
  };

  checkMaintainer = handle: uncheckedAttrs:
  let
      prefix = [ "lib" "maintainers" handle ];
      checkedAttrs = (lib.modules.evalModules {
        inherit prefix;
        modules = [
          maintainerModule
          {
            _file = toString ../../maintainers/maintainer-list.nix;
            config = uncheckedAttrs;
          }
        ];
      }).config;

      checkGithubId = lib.optional (checkedAttrs.github != null && checkedAttrs.githubId == null) ''
        echo ${lib.escapeShellArg (lib.showOption prefix)}': If `github` is specified, `githubId` must be too.'
        # Calling this too often would hit non-authenticated API limits, but this
        # shouldn't happen since such errors will get fixed rather quickly
        info=$(curl -sS https://api.github.com/users/${checkedAttrs.github})
        id=$(jq -r '.id' <<< "$info")
        echo "The GitHub ID for GitHub user ${checkedAttrs.github} is $id:"
        echo -e "    githubId = $id;\n"
      '';
    in lib.deepSeq checkedAttrs checkGithubId;

  missingGithubIds = lib.concatLists (lib.mapAttrsToList checkMaintainer lib.maintainers);

  success = pkgs.runCommand "checked-maintainers-success" {} ">$out";

  failure = pkgs.runCommand "checked-maintainers-failure" {
    nativeBuildInputs = [ pkgs.curl pkgs.jq ];
    outputHash = "sha256:${lib.fakeSha256}";
    outputHAlgo = "sha256";
    outputHashMode = "flat";
    SSL_CERT_FILE = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt";
  } ''
    ${lib.concatStringsSep "\n" missingGithubIds}
    exit 1
  '';
in if missingGithubIds == [] then success else failure