Skip to content

Commit ef3ded9

Browse files
authored
fix(gateway-contracts): improve forge version checking with range support (#1748)
* fix(gateway-contracts): improve forge version checking with range support Replace hardcoded list of allowed forge versions with flexible min/max range check. This makes the script more maintainable and allows any forge version between 1.3.1 and 1.5.1. Changes: - Add 'packaging' library import for version comparison - Replace ALLOWED_FORGE_VERSIONS list with MIN_FORGE_VERSION and MAX_FORGE_VERSION - Extract numeric version from forge version string using regex - Use semantic version comparison instead of string matching This allows the script to accept any forge version within the specified range without requiring hardcoded version strings for each patch release. * refactor(gateway-contracts): use tuple comparison for version checking Remove external `packaging` dependency in favor of simple tuple comparison for semver validation. This is cleaner and has zero external dependencies while correctly handling version comparisons like 1.10.0 > 1.9.0. Changes: - Remove `packaging` library import - Define MIN/MAX_FORGE_VERSION as tuples instead of strings - Add simple parse_semver() helper function - Use direct tuple comparison for version range check * refactor(gateway-contracts): accept all forge 1.x versions >= 1.3.1 Change version check to accept any forge version >= 1.3.1 and < 2.0.0. This reduces maintenance burden as new forge releases won't require updating the script, while still protecting against major version breaking changes.
1 parent b3352e3 commit ef3ded9

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

gateway-contracts/scripts/bindings_update.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@
1717
GW_MOCKS_DIR = GW_CONTRACTS_DIR.joinpath("mocks")
1818

1919
# To update forge to the latest version locally, run `foundryup`
20-
ALLOWED_FORGE_VERSIONS = ["1.3.1-v1.3.1", "1.3.1-stable", "1.3.2-stable"]
20+
MIN_FORGE_VERSION = (1, 3, 1)
21+
MAX_FORGE_VERSION = (2, 0, 0) # Exclusive upper bound
22+
23+
24+
def parse_semver(version_str: str) -> tuple:
25+
"""Parses a semver string (e.g., '1.3.1') into a tuple of integers."""
26+
return tuple(int(x) for x in version_str.split("."))
2127

2228

2329
def init_cli() -> ArgumentParser:
@@ -95,7 +101,7 @@ def _check_forge_installed():
95101
log_error("ERROR: forge is not installed.")
96102
sys.exit(ExitStatus.FORGE_NOT_INSTALLED.value)
97103

98-
forge_version = (
104+
forge_version_str = (
99105
subprocess.run(
100106
["forge", "--version"],
101107
capture_output=True,
@@ -104,11 +110,23 @@ def _check_forge_installed():
104110
.stdout.splitlines()[0]
105111
.lstrip("forge Version: ")
106112
)
107-
if forge_version not in ALLOWED_FORGE_VERSIONS:
113+
114+
# Extract version number from format like "1.3.1-stable" or "1.3.1-v1.3.1"
115+
version_match = re.match(r'^(\d+\.\d+\.\d+)', forge_version_str)
116+
if not version_match:
117+
log_error(
118+
f"ERROR: Could not parse forge version '{forge_version_str}'."
119+
)
120+
sys.exit(ExitStatus.WRONG_FORGE_VERSION.value)
121+
122+
forge_version = parse_semver(version_match.group(1))
123+
124+
if not (MIN_FORGE_VERSION <= forge_version < MAX_FORGE_VERSION):
125+
min_str = ".".join(map(str, MIN_FORGE_VERSION))
126+
max_str = ".".join(map(str, MAX_FORGE_VERSION))
108127
log_error(
109-
"ERROR: Required forge version to be one of these: "
110-
f"`{ALLOWED_FORGE_VERSIONS}` but '{forge_version}' is "
111-
"currently installed."
128+
f"ERROR: Forge version must be >= {min_str} and < {max_str}, "
129+
f"but '{forge_version_str}' is currently installed."
112130
)
113131
sys.exit(ExitStatus.WRONG_FORGE_VERSION.value)
114132

0 commit comments

Comments
 (0)