From dce6feaf7711d623053633ec6e95d3deebae6cff Mon Sep 17 00:00:00 2001 From: Euan Kemp Date: Wed, 21 Jun 2023 23:39:05 +0900 Subject: [PATCH] k3s: update update-script to support multiple minor versions This should let the update bot help us keep old versions up to date. 1.26 update incoming... --- .../networking/cluster/k3s/default.nix | 2 +- .../k3s/{1_27/update.sh => update-script.sh} | 34 ++++++++++++------- 2 files changed, 23 insertions(+), 13 deletions(-) rename pkgs/applications/networking/cluster/k3s/{1_27/update.sh => update-script.sh} (80%) diff --git a/pkgs/applications/networking/cluster/k3s/default.nix b/pkgs/applications/networking/cluster/k3s/default.nix index aec9603bb23..084064c0d04 100644 --- a/pkgs/applications/networking/cluster/k3s/default.nix +++ b/pkgs/applications/networking/cluster/k3s/default.nix @@ -22,6 +22,6 @@ in # 1_27 can be built with the same builder as 1_26 k3s_1_27 = common ((import ./1_27/versions.nix) // { - updateScript = ./1_27/update-script.sh; + updateScript = [ ./update-script.sh "27" ]; }) { }; } diff --git a/pkgs/applications/networking/cluster/k3s/1_27/update.sh b/pkgs/applications/networking/cluster/k3s/update-script.sh similarity index 80% rename from pkgs/applications/networking/cluster/k3s/1_27/update.sh rename to pkgs/applications/networking/cluster/k3s/update-script.sh index 427e2a33d9c..3d10acb83c1 100755 --- a/pkgs/applications/networking/cluster/k3s/1_27/update.sh +++ b/pkgs/applications/networking/cluster/k3s/update-script.sh @@ -3,6 +3,8 @@ set -x -eu -o pipefail +MINOR_VERSION="${1:?Must provide a minor version number, like '26', as the only argument}" + WORKDIR=$(mktemp -d) trap "rm -rf ${WORKDIR}" EXIT @@ -10,12 +12,15 @@ NIXPKGS_ROOT="$(git rev-parse --show-toplevel)"/ NIXPKGS_K3S_PATH=$(cd $(dirname ${BASH_SOURCE[0]}); pwd -P)/ cd ${NIXPKGS_K3S_PATH} +cd 1_${MINOR_VERSION} + + LATEST_TAG_RAWFILE=${WORKDIR}/latest_tag.json curl --silent -f ${GITHUB_TOKEN:+-u ":$GITHUB_TOKEN"} \ https://api.github.com/repos/k3s-io/k3s/releases > ${LATEST_TAG_RAWFILE} LATEST_TAG_NAME=$(jq 'map(.tag_name)' ${LATEST_TAG_RAWFILE} | \ - grep -v -e rc -e engine | tail -n +2 | head -n -1 | sed 's|[", ]||g' | sort -rV | head -n1) + grep -v -e rc -e engine | tail -n +2 | head -n -1 | sed 's|[", ]||g' | sort -rV | grep -E "^v1\.${MINOR_VERSION}\." | head -n1) K3S_VERSION=$(echo ${LATEST_TAG_NAME} | sed 's/^v//') @@ -76,8 +81,9 @@ CNIPLUGINS_VERSION=$(grep 'VERSION_CNIPLUGINS=' ${FILE_SCRIPTS_VERSION} \ CNIPLUGINS_SHA256=$(nix-prefetch-url --quiet --unpack \ "https://github.com/rancher/plugins/archive/refs/tags/v${CNIPLUGINS_VERSION}.tar.gz") -CONTAINERD_VERSION=$(grep 'VERSION_CONTAINERD=' ${FILE_SCRIPTS_VERSION} \ - | cut -d'=' -f2 | sed -e 's/"//g' -e 's/^v//') +# mimics https://github.com/k3s-io/k3s/blob/v1.26.5%2Bk3s1/scripts/version.sh#L25 +CONTAINERD_VERSION=$(grep github.com/containerd/containerd ${FILE_GO_MOD} \ + | head -n1 | awk '{print $4}' | sed -e 's/^v//') CONTAINERD_SHA256=$(nix-prefetch-url --quiet --unpack \ "https://github.com/k3s-io/containerd/archive/refs/tags/v${CONTAINERD_VERSION}.tar.gz") @@ -108,20 +114,24 @@ cat >versions.nix < ${K3S_VERSION}" -fi +# Implement commit +# See https://nixos.org/manual/nixpkgs/stable/#var-passthru-updateScript-commit +OLD_VERSION="$(nix-instantiate --eval -E "with import $NIXPKGS_ROOT. {}; k3s.version or (builtins.parseDrvName k3s.name).version" | tr -d '"')" +cat <