Skip to content

Commit

Permalink
Update nns and sns extensions pinned version (#350)
Browse files Browse the repository at this point in the history
# Motivation

We haven't updated the version of the `nns` and `sns` extensions we use
in some time.
It's not possible to upgrade an extension, so we used to be stuck with
one version but now it's at least possible to uninstall and reinstall.

# Changes

1. Add `bin/dfx-software-dfx-extension-install` to hold the shared code
between `bin/dfx-software-dfx-extension-nns-install` and
`bin/dfx-software-dfx-extension-sns-install`.
2. Check the current installed version and uninstall if it's different
from the desired version.

Note that when the "latest" version is requested, we don't ask for a
specific version but take what we get. We don't know ahead of time what
we'll get so in this case we always uninstall first.

# Tested

Tested manually by installing with `--version 0.2.1`, with `--version
latest` and `--version pinned`.
  • Loading branch information
dskloetd authored May 16, 2024
1 parent d13fe5d commit b89ac10
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 36 deletions.
51 changes: 51 additions & 0 deletions bin/dfx-software-dfx-extension-install
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env bash
set -euo pipefail

SOURCE_DIR="$(dirname "${BASH_SOURCE[0]}")"
PATH="$SOURCE_DIR:$PATH"

print_help() {
cat <<-EOF
Installs a dfx extension.
EOF
}

# Source the clap.bash file ---------------------------------------------------
source "$SOURCE_DIR/clap.bash"
# Define options
clap.define short=e long=extension desc="The extension to install." variable=EXTENSION default=""
clap.define short=v long=version desc="The version of the extension to install" variable=VERSION default="latest"
# Source the output file ----------------------------------------------------------
source "$(clap.build)"

if [[ -z "$EXTENSION" ]]; then
echo "Error: --extension must be set. For example to 'nns' or 'sns'." >&2
exit 1
fi

if [[ "$VERSION" = "latest" ]]; then
VERSION_ARGS=()
else
VERSION_ARGS=("--version" "$VERSION")
fi

is_installed() {
dfx extension list | grep -w "$EXTENSION"
}

get_current_version() {
jq -r .version "$(dfx cache show)/extensions/$EXTENSION/extension.json"
}

if is_installed; then
current_version="$(get_current_version)"
if [[ "$current_version" = "$VERSION" ]]; then
echo "$EXTENSION extension version $VERSION is already installed."
exit 0
fi
echo "Uninstalling current $EXTENSION extension version $current_version."
dfx extension uninstall "$EXTENSION"
fi

dfx extension install "$EXTENSION" "${VERSION_ARGS[@]}"
echo "Installed $EXTENSION dfx extension version $(get_current_version)"
18 changes: 1 addition & 17 deletions bin/dfx-software-dfx-extension-nns-install
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,4 @@ if [[ "$VERSION" = "pinned" ]]; then
VERSION="$DFX_NNS_EXTENSION_VERSION"
fi

if [[ "$VERSION" = "latest" ]]; then
VERSION_ARGS=()
else
VERSION_ARGS=("--version" "$VERSION")
fi

is_installed() {
dfx extension list | grep -w nns
}

if is_installed; then
: "Unfortunately there is currently no way to check which version is installed or to upgrade to a different version."
echo "nns extension is already installed" >&2
exit 0
fi

dfx extension install nns "${VERSION_ARGS[@]}"
dfx-software-dfx-extension-install --extension nns --version "$VERSION"
18 changes: 1 addition & 17 deletions bin/dfx-software-dfx-extension-sns-install
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,4 @@ if [[ "$VERSION" = "pinned" ]]; then
VERSION="$DFX_SNS_EXTENSION_VERSION"
fi

if [[ "$VERSION" = "latest" ]]; then
VERSION_ARGS=()
else
VERSION_ARGS=("--version" "$VERSION")
fi

is_installed() {
dfx extension list | grep -w sns
}

if is_installed; then
: "Unfortunately there is currently no way to check which version is installed or to upgrade to a different version."
echo "sns extension is already installed" >&2
exit 0
fi

dfx extension install sns "${VERSION_ARGS[@]}"
dfx-software-dfx-extension-install --extension sns --version "$VERSION"
4 changes: 2 additions & 2 deletions bin/versions.bash
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ QUILL_VERSION=0.4.0
IDL2JSON_VERSION=0.8.5
BINSTALL_VERSION=1.3.0
IC_WASM_VERSION=0.6.0
DFX_NNS_EXTENSION_VERSION=0.2.1
DFX_SNS_EXTENSION_VERSION=0.2.1
DFX_NNS_EXTENSION_VERSION=0.4.0
DFX_SNS_EXTENSION_VERSION=0.4.0

0 comments on commit b89ac10

Please sign in to comment.