Skip to content

Commit

Permalink
feat(foundryup): allow multiple installed versions (#9551)
Browse files Browse the repository at this point in the history
* feat(foundryup): allow multiple installed versions

* Changes after review: new line after version, -v renamed as -i, create version dir on untar

* Update foundryup link repo and contribute URL

* Fix --one-top-level not avail in bsd tar

* Fix --one-top-level not avail in bsd tar

* update docs

* Err if no version provided to use

---------

Co-authored-by: zerosnacks <[email protected]>
  • Loading branch information
grandizzy and zerosnacks authored Dec 19, 2024
1 parent a263a92 commit af52b80
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 10 deletions.
20 changes: 17 additions & 3 deletions foundryup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

Update or revert to a specific Foundry branch with ease.

`foundryup` supports installing and managing multiple versions.

## Installing

```sh
Expand All @@ -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):
Expand Down Expand Up @@ -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.

---
62 changes: 55 additions & 7 deletions foundryup/foundryup
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -22,7 +23,9 @@ 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;;
-P|--pr) shift; FOUNDRYUP_PR=$1;;
-C|--commit) shift; FOUNDRYUP_COMMIT=$1;;
Expand Down Expand Up @@ -137,15 +140,22 @@ main() {
BIN_ARCHIVE_URL="${RELEASE_URL}foundry_${FOUNDRYUP_VERSION}_${PLATFORM}_${ARCHITECTURE}.$EXT"
MAN_TARBALL_URL="${RELEASE_URL}foundry_man_${FOUNDRYUP_VERSION}.tar.gz"

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_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"
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
Expand All @@ -159,6 +169,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)"
Expand Down Expand Up @@ -240,7 +251,9 @@ 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
-P, --pr Build and install a specific Pull Request
-C, --commit Build and install a specific commit
Expand All @@ -252,6 +265,41 @@ 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
printf "\n"
done
else
for bin in "${BINS[@]}"; do
bin_path="$FOUNDRY_BIN_DIR/$bin"
say "- $(ensure "$bin_path" --version)"
done
fi
exit 0
}

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
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"
}
Expand Down Expand Up @@ -316,11 +364,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
Expand Down

0 comments on commit af52b80

Please sign in to comment.