diff --git a/.github/workflows/check-contacts.yml b/.github/workflows/check-contacts.yml index e28cb82..46dfa71 100644 --- a/.github/workflows/check-contacts.yml +++ b/.github/workflows/check-contacts.yml @@ -1,24 +1,27 @@ -name: "Check that users contatains at least 1 point of contact" +name: Check points of contact for users on: - workflow_dispatch: push: paths: - 'users.nix' pull_request_target: paths: - 'users.nix' + workflow_dispatch: jobs: - check-contacts: + check: + name: Run check + runs-on: ubuntu-latest steps: - - name: Checkout + - name: Checkout repository uses: actions/checkout@v4 - - name: Set up Nix - uses: cachix/install-nix-action@v12 + - name: Install Nix + uses: cachix/install-nix-action@v26 - - name: Check users list - run: nix-instantiate --eval checks/one-contacts.nix + - name: Evaluate checks + run: | + nix eval --show-trace --file checks/check-contacts.nix diff --git a/checks/check-contacts.nix b/checks/check-contacts.nix new file mode 100644 index 0000000..1b7ff6d --- /dev/null +++ b/checks/check-contacts.nix @@ -0,0 +1,40 @@ +let + users = import ../users.nix; + + # This is how many contact points a user should have + # besides GitHub + requiredContactPoints = 1; + + # attrset -> attrset + # We remove the GitHub attribute from all users, as we don't consider it + # as a point of contact + removeGH = userInfo: builtins.removeAttrs userInfo [ "github" ]; + + # attrset -> int + # Count the number of attributes in a set + # This is how we count the points of contact + attrsLength = attrs: builtins.length (builtins.attrValues attrs); + + # attrset -> bool + # Check to see if a set of user information attributes has the + # number of contact points we require + hasEnoughContacts = userInfo: attrsLength (removeGH userInfo) >= requiredContactPoints; + + # attrset -> attrset + # This will check the contacts for a user and throw an evaluation + # error if they don't meet our number of required contacts + checkContact = + userName: userInfo: + if (!(hasEnoughContacts userInfo)) then + throw "${userName} has less than ${toString requiredContactPoints} contact point(s)!" + else + userInfo; + + # This will run our contact check on each user + checkContacts = builtins.mapAttrs checkContact users; + + # string -> string + # This will evaluate our checks and display the message you give it if all goes well + evalContactsThen = builtins.deepSeq checkContacts; +in +evalContactsThen "All users have at least ${toString requiredContactPoints} contact point(s)!" diff --git a/checks/one-contact.nix b/checks/one-contact.nix deleted file mode 100644 index b7ad3c8..0000000 --- a/checks/one-contact.nix +++ /dev/null @@ -1,32 +0,0 @@ -let - lib = (import { }).lib; - - inherit (lib.lists) length any; - inherit (lib.attrsets) filterAttrs attrValues mapAttrs; - - users = import ./users.nix; - - # we remove the GitHub attribute from all users, this is beacuse we don't - # consider GitHub to be a point of contact for the user. - removeGh = user: filterAttrs (n: _: n != "github") user; - - # convert the user attribute set to a list of values - userAttrs = user: attrValues (removeGh user); - - # we now create an error if the user attribute set is empty - error = user: (length (userAttrs user)) == 0; - - # we iterate over all users and create a new attribute for each user - # the attribute will be wether there is an error with the user or not - iterUsers = users: mapAttrs (_: data: error data) users; - - # test all values in the list are false - # if any are true this means that there was an error - testAllFalse = arr: any (x: x) arr; - - # if we have any errors in the users, we will return an error - errors = testAllFalse (attrValues (iterUsers users)); - - # invert argument for readability - pass = !errors; -in assert pass; "PASS" diff --git a/flake.nix b/flake.nix index 55235eb..6d79825 100644 --- a/flake.nix +++ b/flake.nix @@ -1,19 +1,26 @@ { - description = - "A project to declaratively add people to GitHub and their related SIG teams"; + description = "A project to declaratively add people to GitHub and their related SIG teams"; inputs.nixpkgs.url = "github:auxolotl/nixpkgs/nixos-unstable"; - outputs = { nixpkgs, ... }: + outputs = + { nixpkgs, ... }: let - systems = - [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ]; - forAllSystems = nixpkgs.lib.genAttrs systems; - pkgsFor = nixpkgs.legacyPackages; - in { - devShells = forAllSystems - (system: { default = pkgsFor.${system}.callPackage ./shell.nix { }; }); + systems = [ + "x86_64-linux" + "x86_64-darwin" + "aarch64-linux" + "aarch64-darwin" + ]; - formatter = forAllSystems (system: pkgsFor.${system}.nixfmt); + forAllSystems = + function: nixpkgs.lib.genAttrs systems (system: function nixpkgs.legacyPackages.${system}); + in + { + devShells = forAllSystems (pkgs: { + default = pkgs.callPackage ./shell.nix { }; + }); + + formatter = forAllSystems (pkgs: pkgs.nixfmt-rfc-style); }; } diff --git a/memberships.nix b/memberships.nix index 185fef7..372c890 100644 --- a/memberships.nix +++ b/memberships.nix @@ -1,27 +1,33 @@ let sigs = import ./sigs.nix; users = import ./users.nix; -in [{ - sig = sigs.documentation; - leaders = [ users.coded users.minion ]; - members = [ - users.axel - users.isabel - users.ircurry - users."8bitbuddhist" - users.trespaul - users.imadnyc - users.aprl - users.dfh - users.vera - users.nova - users.blue - users.deivpaukst - users.tau - users.srestegosaurio - users.jacab - users.liketechnik - users.angryant - users.raf - ]; -}] +in +[ + { + sig = sigs.documentation; + leaders = [ + users.coded + users.minion + ]; + members = [ + users.axel + users.isabel + users.ircurry + users."8bitbuddhist" + users.trespaul + users.imadnyc + users.aprl + users.dfh + users.vera + users.nova + users.blue + users.deivpaukst + users.tau + users.srestegosaurio + users.jacab + users.liketechnik + users.angryant + users.raf + ]; + } +] diff --git a/shell.nix b/shell.nix index d593881..35215c4 100644 --- a/shell.nix +++ b/shell.nix @@ -1,4 +1,2 @@ -{ mkShell, python3, ... }: -mkShell { - packages = [ (python3.withPackages (pyPkgs: [ pyPkgs.pydiscourse ])) ]; -} +{ mkShellNoCC, python3, ... }: +mkShellNoCC { packages = [ (python3.withPackages (pyPkgs: [ pyPkgs.pydiscourse ])) ]; } diff --git a/users.nix b/users.nix index 26ada06..faabb11 100644 --- a/users.nix +++ b/users.nix @@ -171,9 +171,19 @@ forum = "aria"; github = "tcmal"; }; - ircurry = { forum = "ircurry"; }; - aprl = { forum = "aprl"; }; - deivpaukst = { forum = "deivpaukst"; }; - tau = { forum = "tau"; }; - srestegosaurio = { forum = "srestegosaurio"; }; + ircurry = { + forum = "ircurry"; + }; + aprl = { + forum = "aprl"; + }; + deivpaukst = { + forum = "deivpaukst"; + }; + tau = { + forum = "tau"; + }; + srestegosaurio = { + forum = "srestegosaurio"; + }; }