From e4939cd6866ec39b03393e05cfb9e43246158c2a Mon Sep 17 00:00:00 2001 From: grandizzy Date: Fri, 13 Dec 2024 12:38:33 +0200 Subject: [PATCH 1/7] feat(foundryup): allow multiple installed versions --- foundryup/foundryup | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/foundryup/foundryup b/foundryup/foundryup index 2dc94bfb49d3..f0405ae929e9 100755 --- a/foundryup/foundryup +++ b/foundryup/foundryup @@ -3,6 +3,7 @@ set -eo pipefail BASE_DIR=${XDG_CONFIG_HOME:-$HOME} FOUNDRY_DIR=${FOUNDRY_DIR:-"$BASE_DIR/.foundry"} +FOUNDRY_VERSIONS_DIR="$FOUNDRY_DIR/versions" FOUNDRY_BIN_DIR="$FOUNDRY_DIR/bin" FOUNDRY_MAN_DIR="$FOUNDRY_DIR/share/man/man1" @@ -23,6 +24,8 @@ main() { -r|--repo) shift; FOUNDRYUP_REPO=$1;; -b|--branch) shift; FOUNDRYUP_BRANCH=$1;; -v|--version) shift; FOUNDRYUP_VERSION=$1;; + -l|--list) shift; list;; + -u|--use) shift; FOUNDRYUP_VERSION=$1; use;; -p|--path) shift; FOUNDRYUP_LOCAL_REPO=$1;; -P|--pr) shift; FOUNDRYUP_PR=$1;; -C|--commit) shift; FOUNDRYUP_COMMIT=$1;; @@ -137,15 +140,16 @@ main() { BIN_ARCHIVE_URL="${RELEASE_URL}foundry_${FOUNDRYUP_VERSION}_${PLATFORM}_${ARCHITECTURE}.$EXT" MAN_TARBALL_URL="${RELEASE_URL}foundry_man_${FOUNDRYUP_VERSION}.tar.gz" + mkdir -p $FOUNDRY_VERSIONS_DIR/$FOUNDRYUP_TAG # Download and extract the binaries archive say "downloading latest forge, cast, anvil, and chisel" if [ "$PLATFORM" = "win32" ]; then tmp="$(mktemp -d 2>/dev/null || echo ".")/foundry.zip" ensure download "$BIN_ARCHIVE_URL" "$tmp" - ensure unzip "$tmp" -d "$FOUNDRY_BIN_DIR" + ensure unzip "$tmp" -d "$FOUNDRY_VERSIONS_DIR/$FOUNDRYUP_TAG" rm -f "$tmp" else - ensure download "$BIN_ARCHIVE_URL" | ensure tar -xzC "$FOUNDRY_BIN_DIR" + ensure download "$BIN_ARCHIVE_URL" | ensure tar -xzC "$FOUNDRY_VERSIONS_DIR/$FOUNDRYUP_TAG" fi # Optionally download the manuals @@ -159,6 +163,7 @@ main() { for bin in "${BINS[@]}"; do bin_path="$FOUNDRY_BIN_DIR/$bin" + cp $FOUNDRY_VERSIONS_DIR/$FOUNDRYUP_TAG/$bin $bin_path # Print installed msg say "installed - $(ensure "$bin_path" --version)" @@ -241,6 +246,8 @@ USAGE: OPTIONS: -h, --help Print help information -v, --version Install a specific version from built binaries + -l, --list List versions installed from built binaries + -u, --use Use a specific installed version from built binaries -b, --branch Build and install a specific branch -P, --pr Build and install a specific Pull Request -C, --commit Build and install a specific commit @@ -252,6 +259,39 @@ OPTIONS: EOF } +list() { + if [ -d "$FOUNDRY_VERSIONS_DIR" ]; then + for VERSION in $FOUNDRY_VERSIONS_DIR/*; do + say "${VERSION##*/}" + for bin in "${BINS[@]}"; do + bin_path="$VERSION/$bin" + say "- $(ensure "$bin_path" --version)" + done + done + else + for bin in "${BINS[@]}"; do + bin_path="$FOUNDRY_BIN_DIR/$bin" + say "- $(ensure "$bin_path" --version)" + done + fi + exit 0 +} + +use() { + FOUNDRY_VERSION_DIR="$FOUNDRY_VERSIONS_DIR/$FOUNDRYUP_VERSION" + if [ -d "$FOUNDRY_VERSION_DIR" ]; then + for bin in "${BINS[@]}"; do + bin_path="$FOUNDRY_BIN_DIR/$bin" + cp $FOUNDRY_VERSION_DIR/$bin $bin_path + # Print usage msg + say "use - $(ensure "$bin_path" --version)" + done + exit 0 + else + err "version $FOUNDRYUP_VERSION not installed" + fi +} + say() { printf "foundryup: %s\n" "$1" } From bf24bd9155a42c152d290771f0a0496ada8ee46a Mon Sep 17 00:00:00 2001 From: grandizzy Date: Fri, 13 Dec 2024 14:31:37 +0200 Subject: [PATCH 2/7] Changes after review: new line after version, -v renamed as -i, create version dir on untar --- foundryup/foundryup | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/foundryup/foundryup b/foundryup/foundryup index f0405ae929e9..2c7c91d8c1cc 100755 --- a/foundryup/foundryup +++ b/foundryup/foundryup @@ -23,7 +23,7 @@ main() { -r|--repo) shift; FOUNDRYUP_REPO=$1;; -b|--branch) shift; FOUNDRYUP_BRANCH=$1;; - -v|--version) shift; FOUNDRYUP_VERSION=$1;; + -i|--install) shift; FOUNDRYUP_VERSION=$1;; -l|--list) shift; list;; -u|--use) shift; FOUNDRYUP_VERSION=$1; use;; -p|--path) shift; FOUNDRYUP_LOCAL_REPO=$1;; @@ -140,16 +140,16 @@ main() { BIN_ARCHIVE_URL="${RELEASE_URL}foundry_${FOUNDRYUP_VERSION}_${PLATFORM}_${ARCHITECTURE}.$EXT" MAN_TARBALL_URL="${RELEASE_URL}foundry_man_${FOUNDRYUP_VERSION}.tar.gz" - mkdir -p $FOUNDRY_VERSIONS_DIR/$FOUNDRYUP_TAG + ensure mkdir -p $FOUNDRY_VERSIONS_DIR # Download and extract the binaries archive - say "downloading latest forge, cast, anvil, and chisel" + say "downloading forge, cast, anvil, and chisel for $FOUNDRYUP_TAG version" if [ "$PLATFORM" = "win32" ]; then tmp="$(mktemp -d 2>/dev/null || echo ".")/foundry.zip" ensure download "$BIN_ARCHIVE_URL" "$tmp" ensure unzip "$tmp" -d "$FOUNDRY_VERSIONS_DIR/$FOUNDRYUP_TAG" rm -f "$tmp" else - ensure download "$BIN_ARCHIVE_URL" | ensure tar -xzC "$FOUNDRY_VERSIONS_DIR/$FOUNDRYUP_TAG" + ensure download "$BIN_ARCHIVE_URL" | ensure tar -xz --one-top-level="$FOUNDRY_VERSIONS_DIR/$FOUNDRYUP_TAG" fi # Optionally download the manuals @@ -245,7 +245,7 @@ USAGE: OPTIONS: -h, --help Print help information - -v, --version Install a specific version from built binaries + -i, --install Install a specific version from built binaries -l, --list List versions installed from built binaries -u, --use Use a specific installed version from built binaries -b, --branch Build and install a specific branch @@ -267,6 +267,7 @@ list() { bin_path="$VERSION/$bin" say "- $(ensure "$bin_path" --version)" done + printf "\n" done else for bin in "${BINS[@]}"; do From b561977e0058581fc1782e050ddff75b7b46beee Mon Sep 17 00:00:00 2001 From: grandizzy Date: Tue, 17 Dec 2024 17:42:43 +0200 Subject: [PATCH 3/7] Update foundryup link repo and contribute URL --- foundryup/foundryup | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/foundryup/foundryup b/foundryup/foundryup index 2c7c91d8c1cc..c4063fb9bc49 100755 --- a/foundryup/foundryup +++ b/foundryup/foundryup @@ -357,11 +357,11 @@ banner() { .xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx -Repo : https://github.com/foundry-rs/ +Repo : https://github.com/foundry-rs/foundry Book : https://book.getfoundry.sh/ Chat : https://t.me/foundry_rs/ Support : https://t.me/foundry_support/ -Contribute : https://github.com/orgs/foundry-rs/projects/2/ +Contribute : https://github.com/foundry-rs/foundry/blob/master/CONTRIBUTING.md .xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx From 70f4086772699ab52772af900ca964ee87d1b2bf Mon Sep 17 00:00:00 2001 From: grandizzy Date: Tue, 17 Dec 2024 18:55:48 +0200 Subject: [PATCH 4/7] Fix --one-top-level not avail in bsd tar --- foundryup/foundryup | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/foundryup/foundryup b/foundryup/foundryup index c4063fb9bc49..799eb28db5ca 100755 --- a/foundryup/foundryup +++ b/foundryup/foundryup @@ -149,7 +149,11 @@ main() { ensure unzip "$tmp" -d "$FOUNDRY_VERSIONS_DIR/$FOUNDRYUP_TAG" rm -f "$tmp" else - ensure download "$BIN_ARCHIVE_URL" | ensure tar -xz --one-top-level="$FOUNDRY_VERSIONS_DIR/$FOUNDRYUP_TAG" + tmp="$(mktemp -d 2>/dev/null || echo ".")/foundry.tar.gz" + ensure download "$BIN_ARCHIVE_URL" "$tmp" + ensure mkdir -p $FOUNDRY_VERSIONS_DIR/$FOUNDRYUP_TAG + ensure tar -C "$FOUNDRY_VERSIONS_DIR/$FOUNDRYUP_TAG" -xvf $tmp + rm -f "$tmp" fi # Optionally download the manuals From 2b2ca3419efdbfb347c974547c96ad1620a23b63 Mon Sep 17 00:00:00 2001 From: grandizzy Date: Tue, 17 Dec 2024 18:55:48 +0200 Subject: [PATCH 5/7] Fix --one-top-level not avail in bsd tar --- foundryup/foundryup | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/foundryup/foundryup b/foundryup/foundryup index c4063fb9bc49..e1be3e95fba0 100755 --- a/foundryup/foundryup +++ b/foundryup/foundryup @@ -149,7 +149,13 @@ main() { ensure unzip "$tmp" -d "$FOUNDRY_VERSIONS_DIR/$FOUNDRYUP_TAG" rm -f "$tmp" else - ensure download "$BIN_ARCHIVE_URL" | ensure tar -xz --one-top-level="$FOUNDRY_VERSIONS_DIR/$FOUNDRYUP_TAG" + tmp="$(mktemp -d 2>/dev/null || echo ".")/foundry.tar.gz" + ensure download "$BIN_ARCHIVE_URL" "$tmp" + # Make sure it's a valid tar archive. + ensure tar tf $tmp 1> /dev/null + ensure mkdir -p $FOUNDRY_VERSIONS_DIR/$FOUNDRYUP_TAG + ensure tar -C "$FOUNDRY_VERSIONS_DIR/$FOUNDRYUP_TAG" -xvf $tmp + rm -f "$tmp" fi # Optionally download the manuals From 9b1600e4d606c4c02014b5b422f2e8a9574dde93 Mon Sep 17 00:00:00 2001 From: zerosnacks Date: Wed, 18 Dec 2024 09:01:51 +0100 Subject: [PATCH 6/7] update docs --- foundryup/README.md | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/foundryup/README.md b/foundryup/README.md index 39a53288c001..5504063abfe3 100644 --- a/foundryup/README.md +++ b/foundryup/README.md @@ -2,6 +2,8 @@ Update or revert to a specific Foundry branch with ease. +`foundryup` supports installing and managing multiple versions. + ## Installing ```sh @@ -16,10 +18,22 @@ To install the **nightly** version: foundryup ``` -To install a specific **version** (in this case the `nightly` version): +To **install** a specific **version** (in this case the `nightly` version): + +```sh +foundryup --install nightly +``` + +To **list** all **versions** installed: + +```sh +foundryup --list +``` + +To switch between different versions and **use**: ```sh -foundryup --version nightly +foundryup --use nightly-00efa0d5965269149f374ba142fb1c3c7edd6c94 ``` To install a specific **branch** (in this case the `release/0.1.0` branch's latest commit): @@ -62,6 +76,6 @@ foundryup --path ./git/foundry --- -**Tip**: All flags have a single character shorthand equivalent! You can use `-v` instead of `--version`, etc. +**Tip**: All flags have a single character shorthand equivalent! You can use `-i` instead of `--install`, etc. --- From db02b664f6cddecb13c8e49a5ada3ce5feaaf80f Mon Sep 17 00:00:00 2001 From: grandizzy Date: Thu, 19 Dec 2024 09:32:42 +0200 Subject: [PATCH 7/7] Err if no version provided to use --- foundryup/foundryup | 1 + 1 file changed, 1 insertion(+) diff --git a/foundryup/foundryup b/foundryup/foundryup index e1be3e95fba0..55b0b5a4b053 100755 --- a/foundryup/foundryup +++ b/foundryup/foundryup @@ -285,6 +285,7 @@ list() { } use() { + [ -z "$FOUNDRYUP_VERSION" ] && err "no version provided" FOUNDRY_VERSION_DIR="$FOUNDRY_VERSIONS_DIR/$FOUNDRYUP_VERSION" if [ -d "$FOUNDRY_VERSION_DIR" ]; then for bin in "${BINS[@]}"; do