diff --git a/package.json b/package.json index e9103c29f9b3..31a4f39f1b0a 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "release:version": "changeset version && pnpm install --lockfile-only", "install:foundry": "curl -L https://foundry.paradigm.xyz | bash && pnpm update:foundry", "update:foundry": "bash ./ops/scripts/install-foundry.sh", + "check:foundry": "bash ./packages/contracts-bedrock/scripts/verify-foundry-install.sh", "install:kontrol": "curl -L https://kframework.org/install | bash && pnpm update:kontrol", "update:kontrol": "kup install kontrol --version v$(jq -r .kontrol < versions.json)", "install:abigen": "go install github.com/ethereum/go-ethereum/cmd/abigen@$(jq -r .abigen < versions.json)", diff --git a/packages/contracts-bedrock/scripts/getting-started/versions.sh b/packages/contracts-bedrock/scripts/getting-started/versions.sh index ef8bfaf6a2ef..79dc55a7e9c5 100755 --- a/packages/contracts-bedrock/scripts/getting-started/versions.sh +++ b/packages/contracts-bedrock/scripts/getting-started/versions.sh @@ -14,23 +14,37 @@ version() { fi } +versionFoundry() { + local string="$1" + local version_regex='forge ([0-9]+\.[0-9]+\.[0-9]+)' + local commit_hash_regex='\(([a-fA-F0-9]+)' + local full_regex="${version_regex} ${commit_hash_regex}" + + if [[ $string =~ $full_regex ]]; then + echo "${BASH_REMATCH[1]} (${BASH_REMATCH[2]})" + else + echo "No version, commit hash, and timestamp found." + fi +} + + # Grab versions ver_git=$(version "$(git --version)") ver_go=$(version "$(go version)") ver_node=$(version "$(node --version)") ver_pnpm=$(version "$(pnpm --version)") -ver_foundry=$(version "$(forge --version)") +ver_foundry=$(versionFoundry "$(forge --version)") ver_make=$(version "$(make --version)") ver_jq=$(version "$(jq --version)") ver_direnv=$(version "$(direnv --version)") # Print versions -echo "Dependency | Minimum | Actual" -echo "git 2 $ver_git" -echo "go 1.21 $ver_go" -echo "node 20 $ver_node" -echo "pnpm 8 $ver_pnpm" -echo "foundry 0.2.0 $ver_foundry" -echo "make 3 $ver_make" -echo "jq 1.6 $ver_jq" -echo "direnv 2 $ver_direnv" +echo "Dependency | Minimum | Actual" +echo "git 2 $ver_git" +echo "go 1.21 $ver_go" +echo "node 20 $ver_node" +echo "pnpm 8 $ver_pnpm" +echo "foundry 0.2.0 (a5efe4f) $ver_foundry" +echo "make 3 $ver_make" +echo "jq 1.6 $ver_jq" +echo "direnv 2 $ver_direnv" diff --git a/packages/contracts-bedrock/scripts/verify-foundry-install.sh b/packages/contracts-bedrock/scripts/verify-foundry-install.sh index 4df76e926c79..b705a3bcde46 100755 --- a/packages/contracts-bedrock/scripts/verify-foundry-install.sh +++ b/packages/contracts-bedrock/scripts/verify-foundry-install.sh @@ -1,11 +1,38 @@ #!/usr/bin/env bash +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +CONTRACTS_BASE=$(dirname "$SCRIPT_DIR") +MONOREPO_BASE=$(dirname "$(dirname "$CONTRACTS_BASE")") +VERSIONS_FILE="${MONOREPO_BASE}/versions.json" + if ! command -v forge &> /dev/null then # shellcheck disable=SC2006 - echo "Is Foundry not installed? Consider installing via `curl -L https://foundry.paradigm.xyz | bash` and then running `foundryup` on a new terminal. For more context, check the installation instructions in the book: https://book.getfoundry.sh/getting-started/installation.html." + echo "Is Foundry not installed? Consider installing via pnpm install:foundry" >&2 exit 1 fi -VERSION=$(forge --version) -echo "Using foundry version: $VERSION" +# Check VERSIONS_FILE has expected foundry property +if ! jq -e '.foundry' "$VERSIONS_FILE" &> /dev/null; then + echo "'foundry' is missing from $VERSIONS_FILE" >&2 + exit 1 +fi + +# Extract the expected foundry version from versions.json +EXPECTED_VERSION=$(jq -r '.foundry' "$VERSIONS_FILE" | cut -c 1-7) +if [ -z "$EXPECTED_VERSION" ]; then + echo "Unable to extract Foundry version from $VERSIONS_FILE" >&2 + exit 1 +fi + +# Extract the installed forge version +INSTALLED_VERSION=$(forge --version | grep -o '[a-f0-9]\{7\}' | head -n 1) + +# Compare the installed timestamp with the expected timestamp +if [ "$INSTALLED_VERSION" = "$EXPECTED_VERSION" ]; then + echo "Foundry version matches the expected version." +else + echo "Mismatch between installed Foundry version ($INSTALLED_VERSION) and expected version ($EXPECTED_VERSION)." + echo "Your version of Foundry may either not be up to date, or it could be a later version." + echo "Running pnpm update:foundry will install the expected version." +fi diff --git a/versions.json b/versions.json index bf10d5825412..cd6951c80119 100644 --- a/versions.json +++ b/versions.json @@ -1,6 +1,6 @@ { "abigen": "v1.10.25", - "foundry": "84d98427e17370ff08ec34f00e3c7e539753a760", + "foundry": "a5efe4f8f425e2f6fb35b0e298f0f46acce11dad", "geth": "v1.13.4", "nvm": "v20.9.0", "slither": "0.10.0",