Unverified Commit 36fed389 authored by Philip Taron's avatar Philip Taron Committed by GitHub
Browse files

ci/eval/compare: Expose attrdiff by kernel and platform (#509519)

parents fe43b586 8926c73f
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
@@ -312,6 +312,12 @@ jobs:
          script: |
            const { readFile } = require('node:fs/promises')
            const changed = JSON.parse(await readFile('comparison/changed-paths.json', 'utf-8'))
            const removedByKernel = Object.fromEntries(
              Object.entries(changed.attrdiffByKernel ?? {}).map(([kernel, diff]) => [
                kernel,
                diff.removed.length,
              ]),
            )
            const description =
              'Package: ' + [
                `added ${changed.attrdiff.added.length}`,
@@ -321,7 +327,15 @@ jobs:
              ' — Rebuild: ' + [
                `linux ${changed.rebuildCountByKernel.linux}`,
                `darwin ${changed.rebuildCountByKernel.darwin}`
              ].join(', ') +
              (
                Object.values(removedByKernel).some((count) => count > 0)
                  ? ' — Removed: ' + [
                      `linux ${removedByKernel.linux ?? 0}`,
                      `darwin ${removedByKernel.darwin ?? 0}`
                    ].join(', ')
                  : ''
              )

            const { serverUrl, repo, runId, payload } = context
            const target_url =
+42 −2
Original line number Diff line number Diff line
@@ -74,9 +74,38 @@ let
        {
          attrdiff: {
            added: ["package1"],
            changed: ["package2", "package3"],
            changed: ["package2", "package3", "package4"],
            removed: ["package4"],
          },
          attrdiffByKernel: {
            darwin: {
              added: [],
              changed: ["package2", "package4"],
              removed: ["package4"],
            },
            linux: {
              added: ["package1"],
              changed: ["package3", "package4"],
              removed: [],
            },
          },
          attrdiffByPlatform: {
            aarch64-darwin: {
              added: [],
              changed: ["package2"],
              removed: ["package4"],
            },
            aarch64-linux: {
              added: ["package1"],
              changed: ["package3"],
              removed: [],
            },
            x86_64-linux: {
              added: [],
              changed: ["package4"],
              removed: [],
            },
          },
          labels: {
            "10.rebuild-darwin: 1-10": true,
            "10.rebuild-linux: 1-10": true
@@ -113,6 +142,8 @@ let
  inherit (import ./utils.nix { inherit lib; })
    groupByKernel
    convertToPackagePlatformAttrs
    groupAttrdiffByKernel
    groupAttrdiffByPlatform
    groupByPlatform
    extractPackageNames
    getLabels
@@ -127,6 +158,15 @@ let

  changed-paths =
    let
      attrdiff = lib.mapAttrs (_: extractPackageNames) {
        inherit (diffAttrs) added changed removed;
      };
      attrdiffByPlatform = groupAttrdiffByPlatform {
        inherit (diffAttrs) added changed removed;
      };
      attrdiffByKernel = groupAttrdiffByKernel {
        inherit (diffAttrs) added changed removed;
      };
      rebuildsByPlatform = groupByPlatform rebuildsPackagePlatformAttrs;
      rebuildsByKernel = groupByKernel rebuildsPackagePlatformAttrs;
      rebuildCountByKernel = lib.mapAttrs (
@@ -135,7 +175,7 @@ let
    in
    writeText "changed-paths.json" (
      builtins.toJSON {
        attrdiff = lib.mapAttrs (_: extractPackageNames) { inherit (diffAttrs) added changed removed; };
        inherit attrdiff attrdiffByKernel attrdiffByPlatform;
        inherit
          rebuildsByPlatform
          rebuildsByKernel
+78 −0
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@
}:
let
  fun = import ./maintainers.nix { inherit lib; };
  utils = import ./utils.nix { inherit lib; };

  mockPkgs =
    {
@@ -226,6 +227,83 @@ let
        ];
      };
    };
    testGroupAttrdiffByPlatform = {
      expr = utils.groupAttrdiffByPlatform {
        added = [
          "new-tool.aarch64-linux"
          "new-tool.x86_64-darwin"
        ];
        changed = [
          "updated-tool.x86_64-darwin"
          "shared-tool.x86_64-darwin"
        ];
        removed = [
          "removed-tool.aarch64-darwin"
          "shared-tool.aarch64-darwin"
        ];
      };
      expected = {
        aarch64-darwin = {
          added = [ ];
          changed = [ ];
          removed = [
            "removed-tool"
            "shared-tool"
          ];
        };
        aarch64-linux = {
          added = [ "new-tool" ];
          changed = [ ];
          removed = [ ];
        };
        x86_64-darwin = {
          added = [ "new-tool" ];
          changed = [
            "shared-tool"
            "updated-tool"
          ];
          removed = [ ];
        };
      };
    };
    testGroupAttrdiffByKernel = {
      expr =
        let
          grouped = utils.groupAttrdiffByKernel {
            added = [
              "new-tool.aarch64-linux"
              "new-tool.x86_64-darwin"
            ];
            changed = [
              "updated-tool.x86_64-darwin"
              "shared-tool.x86_64-darwin"
            ];
            removed = [
              "removed-tool.aarch64-darwin"
              "shared-tool.aarch64-darwin"
            ];
          };
        in
        lib.mapAttrs (_: diff: lib.mapAttrs (_: lib.sort lib.lessThan) diff) grouped;
      expected = {
        darwin = {
          added = [ "new-tool" ];
          changed = [
            "shared-tool"
            "updated-tool"
          ];
          removed = [
            "removed-tool"
            "shared-tool"
          ];
        };
        linux = {
          added = [ "new-tool" ];
          changed = [ ];
          removed = [ ];
        };
      };
    };
  };
in
{
+44 −0
Original line number Diff line number Diff line
@@ -150,6 +150,50 @@ rec {
    in
    lib.genAttrs [ "linux" "darwin" ] filterKernel;

  /*
    Group an attrdiff-style mapping by a derived key such as platform or kernel.

    Turns
      {
        added = [ "new-tool.aarch64-linux" "new-tool.x86_64-darwin" ];
        changed = [ "updated-tool.x86_64-darwin" "shared-tool.x86_64-darwin" ];
        removed = [ "removed-tool.aarch64-darwin" "shared-tool.aarch64-darwin" ];
      }
    into
      {
        aarch64-darwin = {
          added = [ ];
          changed = [ ];
          removed = [ "removed-tool" "shared-tool" ];
        };
        aarch64-linux = {
          added = [ "new-tool" ];
          changed = [ ];
          removed = [ ];
        };
        x86_64-darwin = {
          added = [ "new-tool" ];
          changed = [ "shared-tool" "updated-tool" ];
          removed = [ ];
        };
      }
    when used with `groupByPlatform`.
  */
  groupAttrdiffBy =
    grouper: attrdiff:
    let
      groupedByKind = lib.mapAttrs (
        _: packagePlatformPaths:
        grouper (convertToPackagePlatformAttrs (uniqueStrings packagePlatformPaths))
      ) attrdiff;
      groups = uniqueStrings (lib.flatten (map builtins.attrNames (lib.attrValues groupedByKind)));
    in
    lib.genAttrs groups (group: lib.mapAttrs (_: byGroup: byGroup.${group} or [ ]) groupedByKind);

  groupAttrdiffByPlatform = groupAttrdiffBy groupByPlatform;

  groupAttrdiffByKernel = groupAttrdiffBy groupByKernel;

  /*
    Maps an attrs of `kernel - rebuild counts` mappings to an attrs of labels

+10 −0
Original line number Diff line number Diff line
@@ -25,6 +25,16 @@ async function checkTargetBranch({ github, context, core, dry }) {
   *   changed: string[],
   *   removed: string[],
   *  },
   *  attrdiffByKernel: Record<string, {
   *   added: string[],
   *   changed: string[],
   *   removed: string[],
   *  }>,
   *  attrdiffByPlatform: Record<string, {
   *   added: string[],
   *   changed: string[],
   *   removed: string[],
   *  }>,
   *  labels: Record<string, boolean>,
   *  rebuildCountByKernel: Record<string, number>,
   *  rebuildsByKernel: Record<string, string[]>,