summary refs log tree commit diff
path: root/lib/tests/maintainers.nix
diff options
context:
space:
mode:
authorSilvan Mosberger <contact@infinisil.com>2020-03-13 01:51:11 +0100
committerSilvan Mosberger <contact@infinisil.com>2020-04-13 17:28:00 +0200
commitf5795640620b71cd2bb96e298f0c298e4f714842 (patch)
tree068c5ce23c9da34b318b5d1825472b9be353fa08 /lib/tests/maintainers.nix
parenta90d8de242c5124a82302df7628ec9c4fb55bb75 (diff)
downloadnixpkgs-f5795640620b71cd2bb96e298f0c298e4f714842.tar
nixpkgs-f5795640620b71cd2bb96e298f0c298e4f714842.tar.gz
nixpkgs-f5795640620b71cd2bb96e298f0c298e4f714842.tar.bz2
nixpkgs-f5795640620b71cd2bb96e298f0c298e4f714842.tar.lz
nixpkgs-f5795640620b71cd2bb96e298f0c298e4f714842.tar.xz
nixpkgs-f5795640620b71cd2bb96e298f0c298e4f714842.tar.zst
nixpkgs-f5795640620b71cd2bb96e298f0c298e4f714842.zip
lib/maintainer-list: Implement validity checks
Diffstat (limited to 'lib/tests/maintainers.nix')
-rw-r--r--lib/tests/maintainers.nix75
1 files changed, 75 insertions, 0 deletions
diff --git a/lib/tests/maintainers.nix b/lib/tests/maintainers.nix
new file mode 100644
index 00000000000..60d296eecae
--- /dev/null
+++ b/lib/tests/maintainers.nix
@@ -0,0 +1,75 @@
+# to run these tests:
+# nix-build nixpkgs/lib/tests/maintainers.nix
+# If nothing is output, all tests passed
+{ pkgs ? import ../.. {} }:
+
+let
+  inherit (pkgs) lib;
+  inherit (lib) types;
+
+  maintainerModule = { config, ... }: {
+    options = {
+      name = lib.mkOption {
+        type = types.str;
+      };
+      email = lib.mkOption {
+        type = types.str;
+      };
+      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.runCommandNoCC "checked-maintainers-success" {} ">$out";
+
+  failure = pkgs.runCommandNoCC "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