Skip to content

Dependency Updates

Dependency Updates #8

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 "action@github.com"
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