@ecp.eth/rivet 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -0
- package/package.json +19 -0
- package/rivet.sh +192 -0
package/README.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Rivet
|
|
2
|
+
|
|
3
|
+
Rivet is a Foundry version manager that ensures the correct Foundry version is installed and used based on a `.foundry-version` file in your project root.
|
|
4
|
+
|
|
5
|
+
**Homebrew installed foundry is not supported**: Foundry installed via homebrew does not support version pinning, please uninstall it before using rivet.
|
|
6
|
+
|
|
7
|
+
## What it does:
|
|
8
|
+
|
|
9
|
+
- Version detection: Searches for a `.foundry-version` file in the current directory and parent directories
|
|
10
|
+
- Installation: Installs Foundry if it's not present
|
|
11
|
+
- Version management: Updates Foundry to the target version if there's a mismatch
|
|
12
|
+
- Command proxy: Acts as a wrapper for Foundry commands (forge, cast, anvil, chisel)
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
Install Rivet as dev dependency in your project, then prefix the foundry commands with `rivet`:
|
|
17
|
+
|
|
18
|
+
```json
|
|
19
|
+
{
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "rivet forge build --sizes --skip test"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
```
|
package/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ecp.eth/rivet",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Rivet is a Foundry version manager that ensures the correct Foundry version is installed",
|
|
5
|
+
"main": "rivet.sh",
|
|
6
|
+
"bin": {
|
|
7
|
+
"rivet": "./rivet.sh"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/ecp-eth/rivet.git"
|
|
12
|
+
},
|
|
13
|
+
"author": "ecp.eth",
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/ecp-eth/rivet/issues"
|
|
17
|
+
},
|
|
18
|
+
"homepage": "https://github.com/ecp-eth/rivet#readme"
|
|
19
|
+
}
|
package/rivet.sh
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# Function to find .foundry-version file in current directory or parent directories
|
|
4
|
+
find_foundry_version_file() {
|
|
5
|
+
local current_dir="$(pwd)"
|
|
6
|
+
|
|
7
|
+
while [ "$current_dir" != "/" ]; do
|
|
8
|
+
local version_file="$current_dir/.foundry-version"
|
|
9
|
+
if [ -f "$version_file" ]; then
|
|
10
|
+
echo "$version_file"
|
|
11
|
+
return 0
|
|
12
|
+
fi
|
|
13
|
+
current_dir="$(dirname "$current_dir")"
|
|
14
|
+
done
|
|
15
|
+
|
|
16
|
+
return 1
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
# Check for version file and get target version
|
|
21
|
+
VERSION_FILE=$(find_foundry_version_file)
|
|
22
|
+
if [ -z "$VERSION_FILE" ]; then
|
|
23
|
+
echo "❌ Error: No .foundry-version file found in current directory or any parent directory" >&2
|
|
24
|
+
echo " Please create a .foundry-version file with the desired foundry version (e.g., 'v1.2.3')" >&2
|
|
25
|
+
echo " Example: echo 'v1.2.3' > .foundry-version" >&2
|
|
26
|
+
exit 1
|
|
27
|
+
fi
|
|
28
|
+
|
|
29
|
+
# Get target version from the file
|
|
30
|
+
TARGET_VERSION=$(cat "$VERSION_FILE" | tr -d '\n\r' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
|
|
31
|
+
if [ -z "$TARGET_VERSION" ]; then
|
|
32
|
+
echo "❌ Error: .foundry-version file is empty: $VERSION_FILE" >&2
|
|
33
|
+
exit 1
|
|
34
|
+
fi
|
|
35
|
+
|
|
36
|
+
# Ensure version starts with 'v' if it doesn't already
|
|
37
|
+
if [[ ! "$TARGET_VERSION" =~ ^v ]]; then
|
|
38
|
+
TARGET_VERSION="v$TARGET_VERSION"
|
|
39
|
+
fi
|
|
40
|
+
|
|
41
|
+
# Show version source
|
|
42
|
+
echo "📋 Using foundry version from: $VERSION_FILE"
|
|
43
|
+
echo "🎯 Target version: $TARGET_VERSION"
|
|
44
|
+
|
|
45
|
+
# Function to check if foundry is installed
|
|
46
|
+
is_foundry_installed() {
|
|
47
|
+
command -v forge >/dev/null 2>&1
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
# Function to check if foundry is installed via homebrew
|
|
51
|
+
is_foundry_homebrew() {
|
|
52
|
+
if is_foundry_installed; then
|
|
53
|
+
forge --version 2>/dev/null | head -n1 | grep -q "\-Homebrew"
|
|
54
|
+
else
|
|
55
|
+
return 1
|
|
56
|
+
fi
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
# Function to get current foundry version
|
|
60
|
+
get_foundry_version() {
|
|
61
|
+
if is_foundry_installed; then
|
|
62
|
+
forge --version 2>/dev/null | head -n1 | grep -o 'v[0-9]\+\.[0-9]\+\.[0-9]\+' | head -n1
|
|
63
|
+
else
|
|
64
|
+
echo ""
|
|
65
|
+
fi
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
# Function to detect user's shell
|
|
69
|
+
is_user_shell_zsh() {
|
|
70
|
+
USER_SHELL=$(basename "${SHELL:-/bin/bash}")
|
|
71
|
+
[ "$USER_SHELL" = "zsh" ] || echo "$SHELL" | grep -q "zsh"
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
# Function to install foundry
|
|
75
|
+
install_foundry() {
|
|
76
|
+
echo "🔧 Foundry not found. Installing foundry..."
|
|
77
|
+
curl -L https://foundry.paradigm.xyz | bash
|
|
78
|
+
|
|
79
|
+
# Detect shell and source appropriate rc file
|
|
80
|
+
# Since this script runs under sh, we need to detect the user's actual shell
|
|
81
|
+
if is_user_shell_zsh; then
|
|
82
|
+
echo "🔧 ZSH detected. Sourcing ~/.zshenv..."
|
|
83
|
+
source ~/.zshenv 2>/dev/null || true
|
|
84
|
+
else
|
|
85
|
+
echo "🔧 BASH detected. Sourcing ~/.bashrc..."
|
|
86
|
+
source ~/.bashrc 2>/dev/null || true
|
|
87
|
+
fi
|
|
88
|
+
|
|
89
|
+
# Check if foundryup is available
|
|
90
|
+
if ! command -v foundryup >/dev/null 2>&1; then
|
|
91
|
+
echo "❌ Failed to install foundry. Please run these commands manually:"
|
|
92
|
+
if is_user_shell_zsh; then
|
|
93
|
+
echo " source ~/.zshenv # or start a new terminal"
|
|
94
|
+
else
|
|
95
|
+
echo " source ~/.bashrc # or start a new terminal"
|
|
96
|
+
fi
|
|
97
|
+
echo " foundryup"
|
|
98
|
+
exit 1
|
|
99
|
+
fi
|
|
100
|
+
|
|
101
|
+
# Run foundryup to complete installation
|
|
102
|
+
foundryup
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
# Function to update foundry to target version
|
|
106
|
+
update_foundry() {
|
|
107
|
+
echo "🔄 Foundry version mismatch. Updating to $TARGET_VERSION..."
|
|
108
|
+
if command -v foundryup >/dev/null 2>&1; then
|
|
109
|
+
foundryup --install "$TARGET_VERSION"
|
|
110
|
+
else
|
|
111
|
+
echo "❌ foundryup not found. Please run: foundryup --version $TARGET_VERSION"
|
|
112
|
+
exit 1
|
|
113
|
+
fi
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
# Main logic
|
|
117
|
+
main() {
|
|
118
|
+
# Check if foundry is installed
|
|
119
|
+
if ! is_foundry_installed; then
|
|
120
|
+
install_foundry
|
|
121
|
+
fi
|
|
122
|
+
|
|
123
|
+
# Check if foundry is installed via homebrew
|
|
124
|
+
if is_foundry_homebrew; then
|
|
125
|
+
echo "❌ Error: Foundry is installed via Homebrew" >&2
|
|
126
|
+
echo " Homebrew does not support rolling back to specific versions" >&2
|
|
127
|
+
echo " Please uninstall foundry via Homebrew (this script will help with installing the correct version):" >&2
|
|
128
|
+
echo " brew uninstall foundry" >&2
|
|
129
|
+
exit 1
|
|
130
|
+
fi
|
|
131
|
+
|
|
132
|
+
# Check version
|
|
133
|
+
CURRENT_VERSION=$(get_foundry_version)
|
|
134
|
+
if [ "$CURRENT_VERSION" != "$TARGET_VERSION" ]; then
|
|
135
|
+
update_foundry
|
|
136
|
+
fi
|
|
137
|
+
|
|
138
|
+
# Verify installation and version
|
|
139
|
+
if ! is_foundry_installed; then
|
|
140
|
+
echo "❌ Foundry installation failed"
|
|
141
|
+
exit 1
|
|
142
|
+
fi
|
|
143
|
+
|
|
144
|
+
FINAL_VERSION=$(get_foundry_version)
|
|
145
|
+
if [ "$FINAL_VERSION" != "$TARGET_VERSION" ]; then
|
|
146
|
+
echo "❌ Failed to update foundry to $TARGET_VERSION. Current version: $FINAL_VERSION"
|
|
147
|
+
exit 1
|
|
148
|
+
fi
|
|
149
|
+
|
|
150
|
+
echo "✅ Foundry $TARGET_VERSION is ready"
|
|
151
|
+
|
|
152
|
+
cleanup() {
|
|
153
|
+
# Kill child process if it exists
|
|
154
|
+
if [ -n "$PID" ]; then
|
|
155
|
+
kill -TERM "$PID" 2>/dev/null
|
|
156
|
+
fi
|
|
157
|
+
exit 1
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
# Set up traps for common signals
|
|
161
|
+
# Note: SIGKILL (9) cannot be trapped
|
|
162
|
+
trap 'cleanup' HUP INT QUIT TERM PIPE
|
|
163
|
+
|
|
164
|
+
# Pass all arguments to the global foundry command
|
|
165
|
+
# Determine which foundry command to use based on the script name or first argument
|
|
166
|
+
if [ "$(basename "$0")" = "forge" ] || [ "$1" = "forge" ]; then
|
|
167
|
+
forge "${@:2}" &
|
|
168
|
+
elif [ "$(basename "$0")" = "cast" ] || [ "$1" = "cast" ]; then
|
|
169
|
+
cast "${@:2}" &
|
|
170
|
+
elif [ "$(basename "$0")" = "anvil" ] || [ "$1" = "anvil" ]; then
|
|
171
|
+
anvil "${@:2}" &
|
|
172
|
+
elif [ "$(basename "$0")" = "chisel" ] || [ "$1" = "chisel" ]; then
|
|
173
|
+
chisel "${@:2}" &
|
|
174
|
+
else
|
|
175
|
+
# Default to forge if no specific command is detected
|
|
176
|
+
forge "$@" &
|
|
177
|
+
fi
|
|
178
|
+
|
|
179
|
+
PID=$!
|
|
180
|
+
|
|
181
|
+
# Wait for the process and capture its exit code
|
|
182
|
+
wait $PID
|
|
183
|
+
EXIT_CODE=$?
|
|
184
|
+
|
|
185
|
+
# Remove traps before exiting
|
|
186
|
+
trap - HUP INT QUIT TERM PIPE
|
|
187
|
+
|
|
188
|
+
exit $EXIT_CODE
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
# Run main function
|
|
192
|
+
main "$@"
|