-
Notifications
You must be signed in to change notification settings - Fork 1
159 lines (133 loc) · 4.58 KB
/
dependency-updates.yml
File metadata and controls
159 lines (133 loc) · 4.58 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
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
name: Dependency Updates
on:
schedule:
# Run every Monday at 9 AM UTC
- cron: '0 9 * * 1'
workflow_dispatch:
jobs:
# Check for updates
check-updates:
runs-on: ubuntu-latest
name: Check Dependency Updates
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Check for outdated packages
run: |
echo "Checking for outdated packages..."
npm outdated || true
- name: Run security audit
run: |
echo "Running security audit..."
npm audit --audit-level=moderate || true
- name: Generate update report
run: |
echo "# Dependency Update Report" > update-report.md
echo "Generated on: $(date)" >> update-report.md
echo "" >> update-report.md
echo "## Outdated Packages" >> update-report.md
npm outdated --json >> outdated.json || echo "No outdated packages found"
if [ -f outdated.json ]; then
cat outdated.json >> update-report.md
fi
echo "" >> update-report.md
echo "## Security Vulnerabilities" >> update-report.md
npm audit --json >> audit.json || echo "No vulnerabilities found"
if [ -f audit.json ]; then
cat audit.json >> update-report.md
fi
- name: Upload update report
uses: actions/upload-artifact@v4
with:
name: dependency-update-report
path: |
update-report.md
outdated.json
audit.json
# Create update PR (if updates available)
create-update-pr:
runs-on: ubuntu-latest
name: Create Update PR
needs: check-updates
if: github.event_name == 'schedule'
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Download update report
uses: actions/download-artifact@v4
with:
name: dependency-update-report
- name: Check if updates are needed
id: check-updates
run: |
if [ -f outdated.json ] && [ -s outdated.json ]; then
echo "updates_needed=true" >> $GITHUB_OUTPUT
else
echo "updates_needed=false" >> $GITHUB_OUTPUT
fi
- name: Create update branch
if: steps.check-updates.outputs.updates_needed == 'true'
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git checkout -b dependency-updates-$(date +%Y%m%d)
- name: Update dependencies
if: steps.check-updates.outputs.updates_needed == 'true'
run: |
echo "Updating dependencies..."
npm update
npm audit fix --audit-level=moderate || true
- name: Run tests after update
if: steps.check-updates.outputs.updates_needed == 'true'
run: |
npm test
- name: Commit changes
if: steps.check-updates.outputs.updates_needed == 'true'
run: |
git add package.json package-lock.json
git commit -m "chore: update dependencies
- Updated outdated packages
- Fixed security vulnerabilities
- Generated by automated dependency update workflow"
- name: Push changes
if: steps.check-updates.outputs.updates_needed == 'true'
run: |
git push origin dependency-updates-$(date +%Y%m%d)
- name: Create Pull Request
if: steps.check-updates.outputs.updates_needed == 'true'
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
title: "chore: automated dependency updates"
body: |
## Automated Dependency Updates
This PR contains automated dependency updates generated by the GitHub Actions workflow.
### Changes
- Updated outdated packages
- Fixed security vulnerabilities
- All tests passing
### Review Checklist
- [ ] Review updated packages for breaking changes
- [ ] Test the application locally
- [ ] Approve and merge if everything looks good
Generated on: $(date)
head: dependency-updates-$(date +%Y%m%d)
base: main
delete-branch: true