generated from hashblock/solana-cli-program-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-all-dependencies.sh
executable file
·118 lines (106 loc) · 4.52 KB
/
update-all-dependencies.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/env bash
#
# Updates all dependencies in Cargo.toml to their latest versions
#
set -e
# Log file for tracking updates
LOG_FILE="dependency_update.log"
echo "Dependency update log - $(date)" > "$LOG_FILE"
# Trap to handle errors and cleanup
trap 'echo "An error occurred. Rolling back changes..."; git checkout -- Cargo.toml; exit 1' ERR
echo "Updating all dependencies to their latest versions..."
# Function to extract the latest version of a package from cargo search
get_latest_version() {
local package=$1
local latest_version=$(cargo search "^$package$" --limit 1 | head -n 1 | sed -E 's/.*= "([^"]+)".*/\1/')
echo "$latest_version"
}
# Update dependencies using cargo-edit if available
if command -v cargo-upgrade &> /dev/null; then
echo "Using cargo-upgrade to update dependencies..."
cargo upgrade --all
else
echo "cargo-upgrade not found, using manual update method..."
# Update regular dependencies
echo "Updating regular dependencies..."
echo "Found update for $package: $version -> $latest_version"
read -p "Do you want to update $package to $latest_version? (y/n): " confirm
if [[ "$confirm" == "y" ]]; then
echo "Updating $package from $version to $latest_version"
# Detect platform-specific sed in-place flag (GNU vs. BSD sed)
if sed --version >/dev/null 2>&1; then
SED_INPLACE=(-i)
else
SED_INPLACE=(-i '')
fi
if grep -q "$package = { version =" Cargo.toml; then
sed "${SED_INPLACE[@]}" "s/$package = { version = \"$version\"/$package = { version = \"$latest_version\"/" Cargo.toml
else
sed "${SED_INPLACE[@]}" "s/$package = \"$version\"/$package = \"$latest_version\"/" Cargo.toml
fi
echo "$package updated from $version to $latest_version" >> "$LOG_FILE"
else
echo "Skipped updating $package" >> "$LOG_FILE"
fi
# Detect platform-specific sed in-place flag (GNU vs. BSD sed)
if sed --version >/dev/null 2>&1; then
SED_INPLACE=(-i)
else
SED_INPLACE=(-i '')
fi
if grep -q "$package = { version =" Cargo.toml; then
sed "${SED_INPLACE[@]}" "s/$package = { version = \"$version\"/$package = { version = \"$latest_version\"/" Cargo.toml
else
sed "${SED_INPLACE[@]}" "s/$package = \"$version\"/$package = \"$latest_version\"/" Cargo.toml
fi
if [[ "$confirm" == "y" ]]; then
echo "Updating $package from $version to $latest_version"
# Use sed to update the version in Cargo.toml
# Handle both simple dependencies and those with features
if command -v cargo-add &> /dev/null; then
cargo add "$package"@"$latest_version" --quiet
else
echo "cargo-add not found. Please install cargo-edit to safely update dependencies."
exit 1
fi
echo "$package updated from $version to $latest_version" >> "$LOG_FILE"
else
echo "Skipped updating $package" >> "$LOG_FILE"
fi
sed -i "s/$package = { version = \"$version\"/$package = { version = \"$latest_version\"/" Cargo.toml
else
sed -i "s/$package = \"$version\"/$package = \"$latest_version\"/" Cargo.toml
fi
else
echo "Could not find latest version for $package, skipping..."
fi
echo "Found update for $package: $version -> $latest_version"
read -p "Do you want to update $package to $latest_version? (y/n): " confirm
if [[ "$confirm" == "y" ]]; then
echo "Proposed update for $package: $version -> $latest_version" >> "$LOG_FILE"
echo "Please review and test the changes manually before applying them."
else
echo "Skipped updating $package" >> "$LOG_FILE"
fi
# Update dependencies with features
echo "Updating dependencies with features..."
echo "Parsing Cargo.toml using a TOML parser..."
if command -v cargo-upgrade &> /dev/null; then
echo "Using cargo-upgrade to update dependencies with features..."
cargo upgrade --all
else
echo "cargo-upgrade not found. Please install cargo-edit to safely update dependencies."
exit 1
fi
fi
# Special handling for Solana dependencies
echo "Updating Solana dependencies..."
latest_solana_version=$(get_latest_version "solana-sdk")
if [ -n "$latest_solana_version" ]; then
echo "Using Solana version $latest_solana_version"
./update-solana-dependencies.sh "$latest_solana_version"
fi
echo "All dependencies updated to latest versions in Cargo.toml"
echo "Running cargo update to update Cargo.lock..."
cargo update
echo "Done!"