Unverified Commit 498574f2 authored by Wolfgang Walther's avatar Wolfgang Walther
Browse files

workflows/eval: upload maintainer list of all packages as artifact

This creates a simple mapping of all packages to github ids of all their
maintainers. This is uploaded as an artifact and is then available for
download on the latest commit of each branch with a merge queue. This
will allow scheduled jobs to use this information for setting
maintainer-related labels, to request reviewers and to implement the
merge-bot.

The advantage over querying this information directly via Nix in each
case: The scheduled job does not need to install Nix and does not need
to checkout the target branch.

Compared to obtaining the maintainer information just for a single PR
during Eval, this will allow retroactively changing maintainers for a
package: For example, it allows to request a new maintainer as reviewer
for a PR that was created before they became maintainer, but is still
open - and similarly for maintainer labels and merge-bot rights.

None of these extensions are implemented by this PR, yet.
parent 5c01bd9d
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -194,6 +194,12 @@ jobs:
            --arg diffDir ./diff \
            --out-link combined

      - name: Upload the maintainer list
        uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
        with:
          name: ${{ inputs.artifact-prefix }}maintainers
          path: combined/maintainers.json

      - name: Compare against the target branch
        env:
          AUTHOR_ID: ${{ github.event.pull_request.user.id }}
+10 −0
Original line number Diff line number Diff line
@@ -111,6 +111,7 @@ let
          --option allow-import-from-derivation false \
          --query --available \
          --out-path --json \
          --meta \
          --show-trace \
          --arg chunkSize "$chunkSize" \
          --arg myChunk "$myChunk" \
@@ -204,6 +205,7 @@ let
        fi

        cat "$chunkOutputDir"/result/* | jq -s 'add | map_values(.outputs)' > $out/${evalSystem}/paths.json
        cat "$chunkOutputDir"/result/* | jq -s 'add | map_values(.meta)' > $out/${evalSystem}/meta.json
      '';

  diff = callPackage ./diff.nix { };
@@ -232,6 +234,14 @@ let
          })
        ' > $out/combined-diff.json

        # Combine maintainers from all systems
        cat ${diffDir}/*/maintainers.json | jq -s '
          add | group_by(.package) | map({
            key: .[0].package,
            value: map(.maintainers) | flatten | unique
          }) | from_entries
        ' > $out/maintainers.json

        mkdir -p $out/before/stats
        for d in ${diffDir}/before/*; do
          cp -r "$d"/stats-by-chunk $out/before/stats/$(basename "$d")
+22 −0
Original line number Diff line number Diff line
@@ -76,6 +76,27 @@ let
  afterAttrs = getAttrs after;
  diffAttrs = diff beforeAttrs afterAttrs;
  diffJson = writeText "diff.json" (builtins.toJSON diffAttrs);

  # The maintainer list is not diffed, but just taken as is, to provide a map
  # of maintainers on the target branch. A list of GitHub IDs is sufficient for
  # all our purposes and reduces size massively.
  meta = lib.importJSON "${after}/${evalSystem}/meta.json";
  maintainers = lib.pipe meta [
    (lib.mapAttrsToList (
      k: v: {
        # splits off the platform suffix
        package = lib.pipe k [
          (lib.splitString ".")
          lib.init
          (lib.concatStringsSep ".")
        ];
        maintainers = map (m: m.githubId) v.maintainers or [ ];
      }
    ))
    # Some paths don't have a platform suffix, those will appear with an empty package here.
    (lib.filter ({ package, maintainers }: package != "" && maintainers != [ ]))
  ];
  maintainersJson = writeText "maintainers.json" (builtins.toJSON maintainers);
in
runCommand "diff" { } ''
  mkdir -p $out/${evalSystem}
@@ -86,4 +107,5 @@ runCommand "diff" { } ''
  # the source files to keep the artifacts smaller.
  find $out/before $out/after -iname '*.json' -delete
  cp ${diffJson} $out/${evalSystem}/diff.json
  cp ${maintainersJson} $out/${evalSystem}/maintainers.json
''