Skip to content

Commit 8744909

Browse files
committed
feat: enhance auto-dependency updater with fail-safe checks and backup mechanism
1 parent 5d713fb commit 8744909

File tree

1 file changed

+45
-3
lines changed

1 file changed

+45
-3
lines changed

.github/workflows/auto-update.yml

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,52 @@ jobs:
2424
with:
2525
node-version: 20 # or your project's version
2626

27-
- name: 📦 Upgrade dependencies
27+
- name: 📦 Upgrade dependencies (Fail-Safe)
2828
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..."
2935
npm install -g npm-check-updates
36+
37+
echo "🔄 Upgrading dependencies..."
3038
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
3373
3474
- name: 🧠 Commit and Push changes
3575
env:
@@ -39,9 +79,11 @@ jobs:
3979
git config user.email "github-actions[bot]@users.noreply.github.com"
4080
4181
if [ -n "$(git status --porcelain)" ]; then
82+
echo "📝 Changes detected, committing..."
4283
git add .
4384
git commit -m "chore: 🔄 auto-dependency upgrade"
4485
git push origin ${{ github.ref_name }}
86+
echo "✅ Successfully pushed dependency updates"
4587
else
4688
echo "✅ No changes to commit"
4789
fi

0 commit comments

Comments
 (0)