@@ -24,12 +24,52 @@ jobs:
24
24
with :
25
25
node-version : 20 # or your project's version
26
26
27
- - name : 📦 Upgrade dependencies
27
+ - name : 📦 Upgrade dependencies (Fail-Safe)
28
28
run : |
29
+ set -e # Exit on any error
30
+
31
+ echo "🔍 Backing up original package.json..."
32
+ cp package.json package.json.backup
33
+
34
+ echo "📋 Installing npm-check-updates..."
29
35
npm install -g npm-check-updates
36
+
37
+ echo "🔄 Upgrading dependencies..."
30
38
ncu -u
31
- npm install
32
- npm audit fix --force || true
39
+
40
+ echo "🧪 Testing npm install after upgrades..."
41
+ if npm install; then
42
+ echo "✅ npm install succeeded after upgrades"
43
+ else
44
+ echo "❌ npm install failed after upgrades - reverting changes"
45
+ cp package.json.backup package.json
46
+ echo "🧹 Cleaning up backup..."
47
+ rm -f package.json.backup
48
+ exit 1
49
+ fi
50
+
51
+ echo "🔒 Running npm audit fix..."
52
+ if npm audit fix; then
53
+ echo "✅ npm audit fix completed"
54
+ else
55
+ echo "⚠️ npm audit fix had issues, but continuing..."
56
+ fi
57
+
58
+ echo "🧪 Final verification with npm install..."
59
+ if npm install; then
60
+ echo "✅ Final npm install verification passed"
61
+ else
62
+ echo "❌ Final verification failed - reverting changes"
63
+ cp package.json.backup package.json
64
+ npm install
65
+ echo "⚠️ Skipping commit due to dependency conflict"
66
+ echo "🧹 Cleaning up backup..."
67
+ rm -f package.json.backup
68
+ exit 0
69
+ fi
70
+
71
+ echo "🧹 Cleaning up backup..."
72
+ rm -f package.json.backup
33
73
34
74
- name : 🧠 Commit and Push changes
35
75
env :
39
79
git config user.email "github-actions[bot]@users.noreply.github.com"
40
80
41
81
if [ -n "$(git status --porcelain)" ]; then
82
+ echo "📝 Changes detected, committing..."
42
83
git add .
43
84
git commit -m "chore: 🔄 auto-dependency upgrade"
44
85
git push origin ${{ github.ref_name }}
86
+ echo "✅ Successfully pushed dependency updates"
45
87
else
46
88
echo "✅ No changes to commit"
47
89
fi
0 commit comments