Skip to content

Dependency Management #24

Dependency Management

Dependency Management #24

name: Dependency Management
# Explicit permissions for dependency management workflow
permissions:
contents: write # Write to create commits and branches
pull-requests: write # Create and update PRs
actions: read # Read workflow artifacts
checks: read # Read check status
on:
schedule:
# Run weekly on Wednesdays at 10 AM UTC
- cron: '0 10 * * 3'
workflow_dispatch:
# Allow manual triggering
push:
branches: [ main ]
paths:
- 'package*.json'
jobs:
dependency-update:
name: Dependency Updates
runs-on: ubuntu-latest
# Add timeout to prevent runaway jobs
timeout-minutes: 30
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
# Use PAT if available for triggering workflows, fallback to GITHUB_TOKEN
token: ${{ secrets.PAT_TOKEN || secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18.x'
cache: 'npm'
- name: Check for dependency updates
run: |
echo "Checking for dependency updates..."
# Install npm-check-updates
npm install -g npm-check-updates
# Check for updates using valid format
ncu --format group
# Generate update report using valid format
ncu --format group > dependency-updates.txt
# Also create a simple JSON-like output
ncu --jsonUpgraded > dependency-updates.json || echo '{}' > dependency-updates.json
- name: Security-focused updates
run: |
echo "Checking for security updates..."
# Check npm audit and get fixable issues
npm audit --json > audit-report.json || true
# Try to fix security issues automatically
npm audit fix --only=prod || true
# Report what was fixed
if git diff --quiet package*.json; then
echo "No security updates needed"
else
echo "Security updates applied"
git diff package*.json
fi
- name: Create pull request for updates
uses: peter-evans/create-pull-request@v5
if: always()
with:
# Use PAT if available to trigger CI workflows on the created PR
token: ${{ secrets.PAT_TOKEN || secrets.GITHUB_TOKEN }}
commit-message: 'chore: update dependencies for security and maintenance'
title: 'Automated Dependency Updates'
body: |
## 🔧 Automated Dependency Updates
This PR contains automated dependency updates focusing on:
- 🔒 Security vulnerability fixes
- 📦 Maintenance updates for stability
- 🏛️ Government compliance considerations
### Changes Made
- Updated npm dependencies to latest secure versions
- Applied security patches where available
- Maintained compatibility with existing APIs
### ⚠️ Testing Instructions
**Important**: Automated PRs may not trigger CI workflows automatically.
**To validate this PR:**
1. **Manual CI Trigger**: Comment `/test` or push an empty commit to trigger workflows
2. **Local Testing**: Clone the branch and run `npm test` locally
3. **Example Verification**: Test all example files work correctly
**Command to test locally:**
```bash
git fetch origin automated-dependency-updates
git checkout automated-dependency-updates
npm ci
npm test
npm run build
node examples/basic-usage.js
```
### Government Agency Review
Before merging, please ensure:
- [ ] CI/CD pipeline passes (trigger manually if needed)
- [ ] Changes align with agency security policies
- [ ] No breaking changes affect existing integrations
- [ ] Updated dependencies are approved for government use
- [ ] Security scanning passes all checks
### Testing Required
- [ ] All existing tests pass
- [ ] Security scans show no new vulnerabilities
- [ ] Build process completes successfully
- [ ] Examples still function correctly
*This PR was automatically generated by the dependency management workflow.*
branch: automated-dependency-updates
delete-branch: true
- name: Upload dependency reports
uses: actions/upload-artifact@v4
with:
name: dependency-reports
path: |
dependency-updates.txt
dependency-updates.json
audit-report.json
retention-days: 30
vulnerability-monitoring:
name: Vulnerability Monitoring
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18.x'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Monitor for new vulnerabilities
run: |
echo "🛡️ Monitoring for new vulnerabilities..."
# Run comprehensive audit
npm audit --audit-level=info --json > current-vulnerabilities.json || true
# Check for critical/high severity issues
critical_count=$(jq '.metadata.vulnerabilities.critical // 0' current-vulnerabilities.json)
high_count=$(jq '.metadata.vulnerabilities.high // 0' current-vulnerabilities.json)
echo "Critical vulnerabilities: $critical_count"
echo "High vulnerabilities: $high_count"
# Alert if critical vulnerabilities found
if [ "$critical_count" -gt 0 ] || [ "$high_count" -gt 5 ]; then
echo "🚨 High/Critical vulnerabilities detected!"
echo "Government agencies should address these immediately"
# Output vulnerability details
npm audit --audit-level=high
# Create issue for tracking
echo "Creating tracking issue for vulnerabilities..."
exit 1
else
echo "✅ No critical security issues found"
fi
- name: Check for compromised packages
run: |
echo "🔍 Checking for potentially compromised packages..."
# Use npm audit signatures (if available)
npm audit signatures || echo "Signature audit not available"
# Check package integrity
npm ci --package-lock-only
echo "✅ Package integrity check completed"
- name: Government compliance check
run: |
echo "Checking government compliance factors..."
# Check for packages from trusted sources
suspicious_patterns=("@types/" "test" "dev")
# Review production dependencies only
if [ -f package.json ]; then
prod_deps=$(jq -r '.dependencies | keys[]' package.json 2>/dev/null || echo "No dependencies found")
echo "Production dependencies:"
echo "$prod_deps"
else
echo "No package.json found"
fi
# Check for any packages that might need government review
echo "Government compliance check completed"
supply-chain-security:
name: Supply Chain Security
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18.x'
cache: 'npm'
- name: Verify package signatures
run: |
echo "Verifying package signatures and integrity..."
# Install dependencies with integrity checking
npm ci --audit --fund false
echo "Package integrity verified"
- name: Analyze dependency tree
run: |
echo "Analyzing dependency supply chain..."
# Generate comprehensive dependency tree (with error handling)
npm list --all --long > full-dependency-tree.txt 2>/dev/null || echo "Dependency tree generated with warnings"
# Check for deep dependency chains (potential risk) with safer JSON parsing
npm list --depth=0 --json > deps.json 2>/dev/null || echo "{}" > deps.json
max_depth=$(jq -r 'if .dependencies then [.dependencies | to_entries[] | if .value.dependencies then (.value.dependencies | length) else 0 end] | max else 0 end' deps.json 2>/dev/null || echo "0")
echo "Maximum dependency depth: $max_depth"
if [ "$max_depth" -gt 10 ]; then
echo "Warning: Deep dependency chains detected - review for supply chain risks"
else
echo "Dependency depth appears reasonable"
fi
- name: Check package publishers
run: |
echo "Checking package publisher information..."
# Get package info for main dependencies (with error handling)
for pkg in $(jq -r '.dependencies | keys[]' package.json 2>/dev/null || echo ""); do
if [ -n "$pkg" ]; then
echo "Checking publisher for: $pkg"
npm view "$pkg" maintainers --json 2>/dev/null || echo "Could not fetch maintainer info for $pkg"
fi
done
echo "Publisher information review completed"
- name: Upload supply chain report
uses: actions/upload-artifact@v4
with:
name: supply-chain-report
path: |
full-dependency-tree.txt
deps.json
retention-days: 30
compliance-summary:
name: Compliance Summary
runs-on: ubuntu-latest
needs: [dependency-update, vulnerability-monitoring, supply-chain-security]
if: always()
steps:
- name: Generate compliance report
run: |
echo "📋 DEPENDENCY COMPLIANCE REPORT"
echo "==============================="
echo ""
echo "🏛️ Government Dependency Security Assessment"
echo ""
echo "Workflow Status:"
echo "- Dependency Updates: ${{ needs.dependency-update.result }}"
echo "- Vulnerability Monitoring: ${{ needs.vulnerability-monitoring.result }}"
echo "- Supply Chain Security: ${{ needs.supply-chain-security.result }}"
echo ""
echo "Recommendations for Government Agencies:"
echo ""
echo "1. 🔍 Review all dependency updates before approval"
echo "2. 🛡️ Ensure vulnerability monitoring aligns with agency policies"
echo "3. 📋 Verify supply chain security meets organizational requirements"
echo "4. 🏛️ Follow agency-specific dependency approval processes"
echo "5. 📊 Document dependency security review in ATO packages"
echo ""
if [[ "${{ needs.vulnerability-monitoring.result }}" == "failure" ]]; then
echo "🚨 CRITICAL: Vulnerability monitoring detected issues"
echo "Action Required: Address security vulnerabilities immediately"
else
echo "✅ No critical vulnerabilities detected in this scan"
fi
echo ""
echo "Next Steps:"
echo "- Review generated dependency update PR (if created)"
echo "- Schedule regular dependency security reviews"
echo "- Monitor for security advisories"
echo "- Update internal security documentation"