about summary refs log tree commit diff
path: root/pkgs/by-name/pl
diff options
context:
space:
mode:
authorLaurent Arnoud2024-06-04 15:07:28 +0200
committerLaurent Arnoud2024-07-30 15:15:18 +0200
commit9c5852513f212a6036385f67a36ffef8a0c555dc (patch)
tree146d3bd2e742eddd5d90b41a3f73ac732eae7f3c /pkgs/by-name/pl
parent95521efe3b8903775c5224db2ae23cea60080d0a (diff)
platformsh: add updateScript
Diffstat (limited to 'pkgs/by-name/pl')
-rw-r--r--pkgs/by-name/pl/platformsh/package.nix37
-rwxr-xr-xpkgs/by-name/pl/platformsh/update.sh29
-rw-r--r--pkgs/by-name/pl/platformsh/versions.json19
3 files changed, 63 insertions, 22 deletions
diff --git a/pkgs/by-name/pl/platformsh/package.nix b/pkgs/by-name/pl/platformsh/package.nix
index 23baedfebec2..683e34a87a0b 100644
--- a/pkgs/by-name/pl/platformsh/package.nix
+++ b/pkgs/by-name/pl/platformsh/package.nix
@@ -7,33 +7,25 @@
   platformsh
 }:
 
+let versions = lib.importJSON ./versions.json;
+    arch = if stdenvNoCC.isx86_64 then "amd64"
+           else if stdenvNoCC.isAarch64 then "arm64"
+           else throw "Unsupported architecture";
+    os = if stdenvNoCC.isLinux then "linux"
+         else if stdenvNoCC.isDarwin then "darwin"
+         else throw "Unsupported os";
+    versionInfo = versions."${os}-${arch}";
+    inherit (versionInfo) hash url;
+
+in
 stdenvNoCC.mkDerivation (finalAttrs: {
   pname = "platformsh";
-  version = "5.0.15";
+  inherit (versions) version;
 
   nativeBuildInputs = [ installShellFiles ];
 
-  src =
-    {
-      x86_64-darwin = fetchurl {
-        url = "https://github.com/platformsh/cli/releases/download/${finalAttrs.version}/platform_${finalAttrs.version}_darwin_all.tar.gz";
-        hash = "sha256-G5/T6ZPcvC7dvw82p2CEMEOb7GCTyCAB8xJ2lxV2UXk=";
-      };
-      aarch64-darwin = fetchurl {
-        url = "https://github.com/platformsh/cli/releases/download/${finalAttrs.version}/platform_${finalAttrs.version}_darwin_all.tar.gz";
-        hash = "sha256-G5/T6ZPcvC7dvw82p2CEMEOb7GCTyCAB8xJ2lxV2UXk=";
-      };
-      x86_64-linux = fetchurl {
-        url = "https://github.com/platformsh/cli/releases/download/${finalAttrs.version}/platform_${finalAttrs.version}_linux_amd64.tar.gz";
-        hash = "sha256-0h5Thp9pSp1TgUyNVVAjsEw+kAZVzfbsHzPMXzhZhSk=";
-      };
-      aarch64-linux = fetchurl {
-        url = "https://github.com/platformsh/cli/releases/download/${finalAttrs.version}/platform_${finalAttrs.version}_linux_arm64.tar.gz";
-        hash = "sha256-m0rxC9IfqY1k4Zh027zSkDWCGNv0E0oopFfBC/vYRgU=";
-      };
-    }
-    .${stdenvNoCC.system}
-      or (throw "${finalAttrs.pname}-${finalAttrs.version}: ${stdenvNoCC.system} is unsupported.");
+  # run ./update
+  src = fetchurl { inherit hash url; };
 
   dontConfigure = true;
   dontBuild = true;
@@ -51,6 +43,7 @@ stdenvNoCC.mkDerivation (finalAttrs: {
   '';
 
   passthru = {
+    updateScript = ./update.sh;
     tests.version = testers.testVersion {
       inherit (finalAttrs) version;
       package = platformsh;
diff --git a/pkgs/by-name/pl/platformsh/update.sh b/pkgs/by-name/pl/platformsh/update.sh
new file mode 100755
index 000000000000..a5df69f2970b
--- /dev/null
+++ b/pkgs/by-name/pl/platformsh/update.sh
@@ -0,0 +1,29 @@
+#!/usr/bin/env nix-shell
+#!nix-shell -i bash -p curl jq
+#shellcheck shell=bash
+
+set -eu -o pipefail
+
+version=$(curl -s ${GITHUB_TOKEN:+-u ":$GITHUB_TOKEN"} \
+    https://api.github.com/repos/platformsh/cli/releases/latest | jq -e -r ".tag_name")
+
+linux_arm64_url=https://github.com/platformsh/cli/releases/download/$version/platform_${version}_linux_arm64.tar.gz
+linux_amd64_url=https://github.com/platformsh/cli/releases/download/$version/platform_${version}_linux_amd64.tar.gz
+darwin_all_url=https://github.com/platformsh/cli/releases/download/$version/platform_${version}_darwin_all.tar.gz
+linux_arm64_hash=$(nix hash to-sri --type sha256 $(nix-prefetch-url --type sha256 "$linux_arm64_url"))
+linux_amd64_hash=$(nix hash to-sri --type sha256 $(nix-prefetch-url --type sha256 "$linux_amd64_url"))
+darwin_all_hash=$(nix hash to-sri --type sha256 $(nix-prefetch-url --type sha256 "$darwin_all_url"))
+jq -n \
+    --arg version "$version" \
+    --arg darwin_all_hash "$darwin_all_hash" \
+    --arg darwin_all_url "$darwin_all_url" \
+    --arg linux_amd64_hash "$linux_amd64_hash" \
+    --arg linux_amd64_url "$linux_amd64_url" \
+    --arg linux_arm64_hash "$linux_arm64_hash" \
+    --arg linux_arm64_url "$linux_arm64_url" \
+    '{ "version": $version,
+    "darwin-amd64": { "hash": $darwin_all_hash, "url": $darwin_all_url },
+    "darwin-arm64": { "hash": $darwin_all_hash, "url": $darwin_all_url },
+    "linux-amd64": { "hash": $linux_amd64_hash, "url": $linux_amd64_url },
+    "linux-arm64": { "hash": $linux_arm64_hash, "url": $linux_arm64_url }
+}' > pkgs/by-name/pl/platformsh/versions.json
diff --git a/pkgs/by-name/pl/platformsh/versions.json b/pkgs/by-name/pl/platformsh/versions.json
new file mode 100644
index 000000000000..526d52084d53
--- /dev/null
+++ b/pkgs/by-name/pl/platformsh/versions.json
@@ -0,0 +1,19 @@
+{
+  "version": "5.0.16",
+  "darwin-amd64": {
+    "hash": "sha256-07HuCcR/2MpRbYfszyezZjTO4r8JQif4jdDClKoKsNc=",
+    "url": "https://github.com/platformsh/cli/releases/download/5.0.16/platform_5.0.16_darwin_all.tar.gz"
+  },
+  "darwin-arm64": {
+    "hash": "sha256-07HuCcR/2MpRbYfszyezZjTO4r8JQif4jdDClKoKsNc=",
+    "url": "https://github.com/platformsh/cli/releases/download/5.0.16/platform_5.0.16_darwin_all.tar.gz"
+  },
+  "linux-amd64": {
+    "hash": "sha256-Z9GPvvwNP2FdPUuFkDNPDKT7Pp+H6ymRvrTiPcooe3c=",
+    "url": "https://github.com/platformsh/cli/releases/download/5.0.16/platform_5.0.16_linux_amd64.tar.gz"
+  },
+  "linux-arm64": {
+    "hash": "sha256-3615mSWDq4DJD3554ELkAh+rEIJ/OOtLrdDoojAjZf8=",
+    "url": "https://github.com/platformsh/cli/releases/download/5.0.16/platform_5.0.16_linux_arm64.tar.gz"
+  }
+}