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
51 changes: 46 additions & 5 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,16 @@ 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"
ensure download "$BIN_ARCHIVE_URL" | ensure tar -xz --one-top-level="$FOUNDRY_VERSIONS_DIR/$FOUNDRYUP_TAG"
fi

# Optionally download the manuals
Expand All @@ -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)"
Expand Down Expand Up @@ -240,7 +245,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 +259,40 @@ 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() {
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
Loading