Unverified Commit 69151f76 authored by Sefa Eyeoglu's avatar Sefa Eyeoglu
Browse files

pnpm_{8,9,10}: add updateScript

parent bb3980ab
Loading
Loading
Loading
Loading
+26 −1
Original line number Diff line number Diff line
{
  lib,
  stdenvNoCC,
  writeScript,
  callPackages,
  fetchurl,
  installShellFiles,
@@ -10,7 +11,9 @@
  version,
  hash,
}:

let
  majorVersion = lib.versions.major version;
in
stdenvNoCC.mkDerivation (finalAttrs: {
  pname = "pnpm";
  inherit version;
@@ -71,10 +74,32 @@ stdenvNoCC.mkDerivation (finalAttrs: {
    in
    {
      inherit (fetchDepsAttrs) fetchDeps configHook;
      inherit majorVersion;

      tests.version = lib.optionalAttrs withNode (
        testers.testVersion { package = finalAttrs.finalPackage; }
      );
      updateScript = writeScript "pnpm-update-script" ''
        #!/usr/bin/env nix-shell
        #!nix-shell -i bash -p curl jq common-updater-scripts
        set -eou pipefail

        curl_github() {
            curl -L ''${GITHUB_TOKEN:+" -u \":$GITHUB_TOKEN\""} "$@"
        }

        latestTag=$(curl_github https://api.github.com/repos/pnpm/pnpm/releases?per_page=100 | jq -r --arg major "v${majorVersion}" '[.[].tag_name | select(startswith($major))][0]')

        # Exit if there is no tag with this major version
        if [ "$latestTag" = "null" ]; then
          echo "No releases starting with v${majorVersion}"
          exit 0
        fi

        latestVersion="''${latestTag#v}"

        update-source-version pnpm_${majorVersion} "$latestVersion" --file=./pkgs/development/tools/pnpm/default.nix
      '';
    };

  meta = {