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
7 cd $
(readlink
-e $
(dirname "${BASH_SOURCE[0]}"))
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
11 update_pubspec_json
() {
12 local version
; version
="$1"
13 echo "Updating pubspec.lock.json"
16 "https://raw.githubusercontent.com/canonical/multipass/refs/tags/v${version}/src/client/gui/pubspec.lock" \
17 | yj
> pubspec.lock.json
20 # Update the SRI hash of a particular overridden Dart package in the Nix expression
21 update_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"
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
32 # Update the hash of the multipass source code in the Nix expression.
33 update_multipass_source
() {
34 local version
; version
="$1"
35 echo "Updating multipass source"
37 sri_hash
="$(nix-prefetch-github canonical multipass --rev "refs
/tags
/v
${version}" --fetch-submodules | jq -r '.hash')"
39 sed -i "s|version = \".*$|version = \"$version\";|" package.nix
40 sed -i "s|hash = \".*$|hash = \"${sri_hash}\";|" package.nix
43 # Update the version/hash of the grpc source code in the Nix expression.
44 update_grpc_source
() {
45 local version
; version
="$1"
46 echo "Updating grpc source"
48 submodule_info
="https://raw.githubusercontent.com/canonical/multipass/refs/tags/v${version}/3rd-party/submodule_info.md"
49 commit_short
="$(curl -s "${submodule_info}" | grep -Po "CanonicalLtd
/grpc
/compare
/v
[0-9]+\.
[0-9]+\.
[0-9]+\.\.\K
[0-9a-f]+")"
50 commit_hash
="$(curl -s "https
://github.com
/canonical
/grpc
/commits
/${commit_short}" | grep -Po "${commit_short}[0-9a-f]+" | head -n1)"
51 sri_hash
="$(nix-prefetch-github canonical grpc --rev "${commit_hash}" --fetch-submodules | jq -r '.hash')"
53 sed -i "s|rev = \".*$|rev = \"${commit_hash}\";|" multipassd.nix
54 sed -i "s|hash = \".*$|hash = \"${sri_hash}\";|" multipassd.nix
58 LATEST_TAG
="$(curl -s ${GITHUB_TOKEN:+-u ":$GITHUB_TOKEN"} https://api.github.com/repos/canonical/multipass/releases/latest | jq -r '.tag_name')"
59 LATEST_VERSION
="$(expr "$LATEST_TAG" : 'v\(.*\)')"
60 CURRENT_VERSION
="$(grep -Po "version
= \"\K
[^
\"]+" package.nix)"
62 if [[ "$CURRENT_VERSION" == "$LATEST_VERSION" ]]; then
63 echo "multipass is up to date: ${CURRENT_VERSION}"
67 update_pubspec_json
"$LATEST_VERSION"
69 update_dart_pkg_hash dartssh2 andrei-toterman dartssh2
70 update_dart_pkg_hash hotkey_manager_linux andrei-toterman hotkey_manager
71 update_dart_pkg_hash system_info2 andrei-toterman system_info
72 update_dart_pkg_hash tray_menu andrei-toterman tray_menu
73 update_dart_pkg_hash window_size google flutter-desktop-embedding
74 update_dart_pkg_hash xterm levkropp xterm.dart
76 update_multipass_source
"$LATEST_VERSION"
78 update_grpc_source
"$LATEST_VERSION"