Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1#!/usr/bin/env nix-shell 2#!nix-shell -I nixpkgs=./. -i bash -p curl jq nix-prefetch-github yj git 3# shellcheck shell=bash 4 5set -euo pipefail 6 7cd $(readlink -e $(dirname "${BASH_SOURCE[0]}")) 8 9# Download the latest pubspec.lock (which is a YAML file), convert it to JSON and write it to 10# the package directory as pubspec.lock.json 11update_pubspec_json() { 12 local version; version="$1" 13 echo "Updating pubspec.lock.json" 14 15 curl -s \ 16 "https://raw.githubusercontent.com/canonical/multipass/refs/tags/v${version}/src/client/gui/pubspec.lock" \ 17 | yj > pubspec.lock.json 18} 19 20# Update the SRI hash of a particular overridden Dart package in the Nix expression 21update_dart_pkg_hash() { 22 local pkg_name; pkg_name="$1" 23 local owner; owner="$2"; 24 local repo; repo="$3"; 25 echo "Updating dart package hash: $pkg_name" 26 27 resolved_ref="$(jq -r --arg PKG "$pkg_name" '.packages[$PKG].description."resolved-ref"' pubspec.lock.json)" 28 hash="$(nix-prefetch-github --rev "$resolved_ref" "$owner" "$repo" | jq '.hash')" 29 sed -i "s|${pkg_name} = \".*\";|${pkg_name} = $hash;|" gui.nix 30} 31 32# Update the hash of the multipass source code in the Nix expression. 33update_multipass_source() { 34 local version; version="$1" 35 echo "Updating multipass source" 36 37 sri_hash="$(nix-prefetch-github canonical multipass --rev "refs/tags/v${version}" --fetch-submodules | jq -r '.hash')" 38 39 sed -i "s|version = \".*$|version = \"$version\";|" package.nix 40 sed -i "s|hash = \".*$|hash = \"${sri_hash}\";|" package.nix 41} 42 43LATEST_TAG="$(curl -s ${GITHUB_TOKEN:+-u ":$GITHUB_TOKEN"} https://api.github.com/repos/canonical/multipass/releases/latest | jq -r '.tag_name')" 44LATEST_VERSION="$(expr "$LATEST_TAG" : 'v\(.*\)')" 45CURRENT_VERSION="$(grep -Po "version = \"\K[^\"]+" package.nix)" 46 47if [[ "$CURRENT_VERSION" == "$LATEST_VERSION" ]]; then 48 echo "multipass is up to date: ${CURRENT_VERSION}" 49 exit 0 50fi 51 52update_pubspec_json "$LATEST_VERSION" 53 54update_dart_pkg_hash dartssh2 canonical dartssh2 55update_dart_pkg_hash hotkey_manager_linux canonical hotkey_manager 56update_dart_pkg_hash tray_menu canonical tray_menu 57update_dart_pkg_hash window_size google flutter-desktop-embedding 58update_dart_pkg_hash xterm levkropp xterm.dart 59 60update_multipass_source "$LATEST_VERSION" 61