Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(foundryup): allow multiple installed versions #9551

Merged
merged 9 commits into from
Dec 19, 2024
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;;
zerosnacks marked this conversation as resolved.
Show resolved Hide resolved
-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"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have to test this works OK on Win

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tested and files properly inflated / unzipped, plus also asking to confirm if you want to replace / skip file for already installed versions

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
Copy link
Member

@zerosnacks zerosnacks Dec 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nits:

not a regression but running --install without comments silently fails (this is expected but ideally should raise an error):

foundryup --install

ideally --use without an argument should display foundryup: version not installed, right now it panics with cp: cannot stat '/home/zerosnacks/.foundry/versions//forge': No such file or directory

foundryup --use

-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)"
zerosnacks marked this conversation as resolved.
Show resolved Hide resolved
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
Loading