-
-
Notifications
You must be signed in to change notification settings - Fork 0
99 lines (80 loc) · 3.19 KB
/
npm-update.yml
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
name: 🚀 Dependency Update, Vulnerability Scan, and Test
on:
schedule:
- cron: '0 2 1 * *' # Runs monthly on the 1st day of the month at 2 AM UTC
workflow_dispatch: # Allows manual triggering
push:
branches:
- main # Runs on pushes to the main branch
permissions:
contents: write
jobs:
update-and-scan:
runs-on: ubuntu-latest
steps:
- name: 🛠️ Checkout code
uses: actions/checkout@v4
- name: 🔧 Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: 🗑️ Remove package-lock.json
run: rm -f package-lock.json
- name: 📦 Install npm-check-updates
run: npm install -g npm-check-updates
- name: ⬆️ Update all packages except ESLint
run: |
ncu -x eslint -u # Update all except ESLint
npm install --legacy-peer-deps # Install updated dependencies
npm install eslint@8.57.0 --save-dev # Reinstall specific ESLint version
- name: 📦 Update dependencies with legacy peer deps
run: npm update --legacy-peer-deps
- name: 🧪 Run Tests
run: npm run test
continue-on-error: false
- name: Check Test Results
id: check_tests
run: |
if [ $? -eq 0 ]; then
echo "tests_passed=true" >> $GITHUB_ENV
else
echo "tests_passed=false" >> $GITHUB_ENV
fi
- name: 🐶 Install Husky
run: npx husky install
- name: 🎭 Mask Debricked credentials
run: echo "::add-mask::${{ secrets.DEBRICKED_TOKEN }}"
- name: Install Debricked CLI
run: |
curl -L https://github.com/debricked/cli/releases/latest/download/cli_linux_x86_64.tar.gz | tar -xz debricked
sudo mv debricked /usr/local/bin/debricked
- name: 🛡️ Debricked Vulnerability Scan
id: debricked_scan
continue-on-error: true # Continue even if Debricked finds vulnerabilities
run: |
debricked scan -t ${{ secrets.DEBRICKED_TOKEN }} -r ${{ github.repository }} -c ${{ github.sha }}
- name: Check Debricked Results
id: check_debricked
run: |
if [ $? -eq 0 ]; then
echo "debricked_passed=true" >> $GITHUB_ENV
else
echo "debricked_passed=false" >> $GITHUB_ENV
fi
- name: 📝 Commit changes
if: success() && env.tests_passed == 'true' && env.debricked_passed == 'true'
run: |
git config --local user.name "Debugging Duck 🦆"
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git add .
git status
git diff-index --quiet HEAD || git commit -m "⬆️ update all npm dependencies except ESLint⬆️"
- name: 🚀 Push changes
if: success() && env.tests_passed == 'true' && env.debricked_passed == 'true'
run: git push
- name: ❌ Revert Changes if Tests or Debricked Fail
if: env.tests_passed == 'false' || env.debricked_passed == 'false'
run: |
git reset --hard
git clean -fd
echo "Reverted changes due to failing tests or vulnerabilities found by Debricked."