-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupgrade.sh
More file actions
executable file
·75 lines (55 loc) · 1.81 KB
/
upgrade.sh
File metadata and controls
executable file
·75 lines (55 loc) · 1.81 KB
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
#!/bin/bash
# upgrade.sh - Updates Node.js to latest LTS, updates packages, and tests build
set -e # Exit on any error
echo "🚀 Starting upgrade process..."
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
# Store initial versions for comparison
INITIAL_NODE_VERSION=$(node --version)
# Update Node.js to latest LTS using nvm
echo "📦 Installing latest Node.js LTS version..."
nvm install --lts
nvm use --lts
# Get new Node version
NEW_NODE_VERSION=$(node --version)
# Update .nvmrc with the new LTS version
echo "📝 Updating .nvmrc with latest LTS version..."
node --version | sed 's/^v//' >.nvmrc
# Enable corepack for yarn management
echo "🔧 Enabling corepack..."
corepack enable
# Install latest yarn
echo "📦 Installing latest Yarn..."
corepack prepare yarn@stable --activate
# Upgrade all packages using yarn up
echo "⬆️ Upgrading all packages..."
yarn up "*"
# Test that yarn build still works
echo "🔨 Testing build process..."
yarn build
# If we get here, everything worked
echo "✅ Build test passed!"
# Determine what changed
NODE_CHANGED=false
DEPS_CHANGED=false
if ! git diff --quiet .nvmrc 2>/dev/null; then
NODE_CHANGED=true
fi
if ! git diff --quiet yarn.lock package.json 2>/dev/null; then
DEPS_CHANGED=true
fi
# Build commit message based on what changed
if [ "$NODE_CHANGED" = true ] && [ "$DEPS_CHANGED" = true ]; then
COMMIT_MSG="updated node and dependencies"
elif [ "$NODE_CHANGED" = true ]; then
COMMIT_MSG="updated node"
elif [ "$DEPS_CHANGED" = true ]; then
COMMIT_MSG="updated dependencies"
else
echo "ℹ️ No changes detected - Node.js and packages are already up to date"
exit 0
fi
echo "💾 Committing changes..."
git add .nvmrc yarn.lock package.json
git commit -m "$COMMIT_MSG"
echo "🎉 Upgrade completed and committed!"