about summary refs log tree commit diff
path: root/pkgs/applications/networking/cluster/sonobuoy
diff options
context:
space:
mode:
authorPaul Meyer <49727155+katexochen@users.noreply.github.com>2023-12-09 21:26:14 +0100
committerPaul Meyer <49727155+katexochen@users.noreply.github.com>2023-12-29 20:01:18 +0100
commit5b9fbcd1b2ea338bdf332bbcc044719f49ea9f0b (patch)
treecbef47542de6f71d2078d9c17a8419aa728e5bea /pkgs/applications/networking/cluster/sonobuoy
parentb96fc12835d7dbf9c1bd9275eca036e80cff6b00 (diff)
sonobuoy: add custom update script
Diffstat (limited to 'pkgs/applications/networking/cluster/sonobuoy')
-rw-r--r--pkgs/applications/networking/cluster/sonobuoy/default.nix7
-rwxr-xr-xpkgs/applications/networking/cluster/sonobuoy/update.sh50
2 files changed, 56 insertions, 1 deletions
diff --git a/pkgs/applications/networking/cluster/sonobuoy/default.nix b/pkgs/applications/networking/cluster/sonobuoy/default.nix
index a398eb5f6b135..88387c891791b 100644
--- a/pkgs/applications/networking/cluster/sonobuoy/default.nix
+++ b/pkgs/applications/networking/cluster/sonobuoy/default.nix
@@ -1,7 +1,8 @@
 { lib, buildGoModule, fetchFromGitHub }:
 
 # SHA of ${version} for the tool's help output. Unfortunately this is needed in build flags.
-let rev = "6f9e27f1795f10475c9f6f5decdff692e1e228da";
+# The update script can update this automatically, the comment is used to find the line.
+let rev = "6f9e27f1795f10475c9f6f5decdff692e1e228da"; # update-commit-sha
 in
 buildGoModule rec {
   pname = "sonobuoy";
@@ -27,6 +28,10 @@ buildGoModule rec {
 
   subPackages = [ "." ];
 
+  passthru = {
+    updateScript = ./update.sh;
+  };
+
   meta = with lib; {
     description = "Diagnostic tool that makes it easier to understand the state of a Kubernetes cluster";
     longDescription = ''
diff --git a/pkgs/applications/networking/cluster/sonobuoy/update.sh b/pkgs/applications/networking/cluster/sonobuoy/update.sh
new file mode 100755
index 0000000000000..289069e1919af
--- /dev/null
+++ b/pkgs/applications/networking/cluster/sonobuoy/update.sh
@@ -0,0 +1,50 @@
+#!/usr/bin/env nix-shell
+#!nix-shell -i bash -p nix-update curl jq gnused
+
+set -euo pipefail
+
+# Do the actual update.
+nix-update "${UPDATE_NIX_ATTR_PATH}"
+
+# Get the src metadata.
+src=$(
+    nix-instantiate --json --eval --strict --expr '
+        with import ./. {};
+        {
+            owner = '"${UPDATE_NIX_ATTR_PATH}"'.src.owner;
+            repo = '"${UPDATE_NIX_ATTR_PATH}"'.src.repo;
+            tag = '"${UPDATE_NIX_ATTR_PATH}"'.src.rev;
+        }'
+)
+owner=$(jq -r '.owner' <<< "${src}")
+repo=$(jq -r '.repo' <<< "${src}")
+tag=$(jq -r '.tag' <<< "${src}")
+
+# Curl the release to get the commit sha.
+curlFlags=("-fsSL")
+curlFlags+=(${GITHUB_TOKEN:+-u ":$GITHUB_TOKEN"})
+
+read -r type tag_sha < <(
+    curl "${curlFlags[@]}" "https://api.github.com/repos/${owner}/${repo}/git/ref/tags/${tag}" |
+    jq -j '.object.type, " ", .object.sha, "\n"'
+)
+
+if [[ "${type}" == "commit" ]]; then
+    sha="${tag_sha}"
+else
+    sha=$(
+        curl "${curlFlags[@]}" "https://api.github.com/repos/${owner}/${repo}/git/tags/${tag_sha}" |
+        jq '.object.sha'
+    )
+fi
+
+if [[ -z "${sha}" ]]; then
+    echo "failed to get commit sha of ${owner}/${repo} @ ${tag}" >&2
+    exit 1
+fi
+
+echo "updating commit hash of ${owner}/${repo} @ ${tag} to ${sha}" >&2
+
+cd "$(dirname "$(readlink -f "$0")")"
+
+sed -i "s|\".*\"; # update-commit-sha|${sha}; # update-commit-sha|" default.nix