Dependency Update Bot Design: SafeDepBot
Overview
SafeDepBot is an automated GitHub App (or GitHub Action-based bot) designed to keep project dependencies up-to-date while prioritizing safety through gradual rollouts, automated testing, configurable owner rules, and one-click rollbacks. It supports multiple ecosystems (npm, pip, Maven, Cargo, Composer, etc.) and integrates seamlessly with GitHub workflows.
Key Goals
- Automation: Scan and update dependencies on a schedule.
- Safety: Test updates in PRs, gradual rollouts (e.g., one package at a time), and require approvals for risky changes.
- Rollbacks: Automatic or manual triggers for reverting merged updates.
- Owner Control: Repo owners define rules via a
.safe-depbot.yml config file.
- Transparency: All actions via PRs with detailed diffs, changelogs, and risk scores.
Supported Ecosystems
| Ecosystem | Manifest Files | Lockfiles |
|---|
| npm/yarn/pnpm | package.json | package-lock.json, yarn.lock, pnpm-lock.yaml |
| Python | requirements.txt, pyproject.toml | Pipfile.lock, poetry.lock |
| Java | pom.xml, build.gradle | N/A (uses Gradle/Maven resolvers) |
| Rust | Cargo.toml | Cargo.lock |
| PHP | composer.json | composer.lock |
Extensible via plugins.
Architecture
┌─────────────────┐ ┌──────────────────┐ ┌──────────────────┐
│ GitHub Repo │◄──►│ SafeDepBot │◄──►│ Registries │
│ (.safe-depbot) │ │ (GitHub App) │ │ (npm, PyPI, etc.)│
└─────────────────┘ └────────┬─────────┘ └──────────────────┘
│
┌──────────▼──────────┐
│ GitHub Actions │ (CI/CD Pipeline)
│ - Tests │
│ - Rollout Staging │
│ - Monitoring │
└────────┬────────────┘
│
┌──────▼──────┐
│ Slack/MS │ (Notifications)
│ Teams │
└─────────────┘
- Core: GitHub App for repo access, webhooks for events (PRs, issues, merges).
- Runner: Serverless (GitHub Actions cron/scheduled workflows) or hosted (e.g., Vercel/AWS Lambda).
- Storage: GitHub repo config + GitHub Issues/Projects for state (or optional external DB like Supabase).
- Security: App permissions scoped to
contents:write, pull_requests:write, checks:write. JWT auth.
Core Components
1. Config Parser (.safe-depbot.yml)
Owners define rules in repo root. Example:
version: 1
schedule:
interval: daily # or cron: "0 2 * * *"
ecosystems:
- npm
- python
rules:
update_types: # Semver controls
- patch
- minor
- major: require_approval # Owners must approve majors
exclude_packages:
- lodash # Never update
- react: max_version: "^17" # Pin to range
batch_size: 3 # Max deps per PR
risk_threshold: medium # Skip high-risk (breaking changes)
pr:
auto_merge: if_tests_pass_and_no_major # Conditions for auto-merge
labels: ["dependencies", "automerge"]
assignees: ["owner1", "owner2"]
body_template: |
Updates: {{changes}}
Risk: {{risk_score}}
Changelogs: {{links}}
rollouts:
stages:
- test: run_ci # PR tests
- staging: deploy_to_staging # Optional deploy job
canary_pct: 5 # % of traffic post-merge (if deploy integrated)
rollbacks:
triggers:
- label: "rollback:{{pr_number}}" # Issue/PR label
- error_rate: >5% # Integrate with monitoring (e.g., Sentry)
auto_revert: true # Create revert PR immediately
notifications:
channels:
- slack: "#deploys"
- github_issue: true
Parsed on every run; invalid config blocks updates.
2. Dependency Scanner
- Trigger: Scheduled (cron), manual dispatch, or webhook (push to lockfiles).
- Logic:
- Clone repo.
- Detect manifest/lockfiles.
- Query registries for latest versions matching rules (e.g.,
npm outdated --parseable).
- Compute diff: version bump type (patch/minor/major via semver), changelog fetch (e.g.,
npm info <pkg> versions --json).
- Risk score (0-10): Based on bump type, dep popularity, past breakage reports (via Snyk/OSS APIs).
- Output: List of safe updates (filtered by rules).
3. Update Proposer
- Creates PR per batch (e.g., 3 deps).
- PR Content:
- Updated lockfile + manifest.
- Risk summary table.
- Inline changelogs.
/rollout command comment for manual staging.
- Labels PRs, assigns owners, adds "do not merge" if risky.
4. Testing & Rollout Pipeline (GitHub Actions)
Integrated workflow (.github/workflows/safedepbot.yml auto-created):
name: SafeDepBot CI
on:
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install & Test # Ecosystem-specific (e.g., npm ci && npm test)
run: |
npm ci
npm test
npm run lint
- name: Security Scan
uses: github/codeql-action/analyze@v3
staging: # Optional rollout stage
needs: test
if: github.event.pull_request.labels contains 'ready-for-staging'
runs-on: self-hosted-staging
steps:
- deploy to staging cluster # Kubernetes/ Vercel integration
automerge:
needs: [test, staging]
runs-on: ubuntu-latest
steps:
- uses: pascalgn/automerge-action@v0.15.0 # Merge if conditions met
- Safe Rollout:
| Stage | Gate | Action |
|---|
| PR Tests | All checks pass | Ready for review |
| Owner Review | Labels: "approved" | Auto-merge if rules allow |
| Canary | Post-merge | Route 5% traffic (via custom deploy job) |
5. Merger & Monitoring
- Auto-Merge: If
tests pass + no major bumps + config allows.
- Post-Merge Monitor:
- Watch for 24h: New issues/PRs with
rollback:* labels.
- Optional: Integrate Sentry/Datadog for error spikes → auto-label issue.
- Notifications: Slack "Update merged: . Rollback if issues."
6. Rollback System
- Triggers (from config):
- Owner adds label
rollback:#123 to issue/PR (PR #123).
- Auto: Error rate > threshold.
- Logic:
- Find merge commit of target PR.
- Create revert PR:
git revert <commit> --no-edit.
- Auto-merge if original tests passed.
- Pin deps back (update manifest to old versions).
- Safety: Revert PR requires approval; tests original + reverted state.
Workflow
- Scan (daily): Find updates → Filter by rules.
- Propose PRs (batched).
- Test in CI → Owner review/approve.
- Merge (auto/manual) → Canary deploy.
- Monitor → If bad, Rollback PR.
- Loop: Re-scan excludes rolled-back deps for 7 days.
Scan → Propose PR ─┐
├── Test → Approve → Merge → Monitor ─┐
└── Risky? → Block │ Yes
└── Rollback PR → Merge
Safety Measures
- Gradual: One dep or small batches.
- Immutable: Never push directly; always PRs.
- Dry-Run Mode:
/dry-run slash command previews updates.
- Audit Logs: All actions logged in GitHub Discussions thread.
- Quarantine: Failed rollbacks trigger "freeze" (no updates for 48h).
- Edge Cases:
| Case | Handling |
|---|
| Breaking Change | Risk score high → Require 2 approvals |
| Lockfile Conflicts | Regenerate + test |
| Monorepo | Per-workspace updates |
Implementation Guide
Quick Start (GitHub Actions Only)
- Create
.github/workflows/update-deps.yml:
name: SafeDepBot
on: schedule: - cron: '0 2 * * *'
jobs:
update:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with: { token: ${{ secrets.GITHUB_TOKEN }} }
- name: Run SafeDepBot
uses: trailblazer-labs/safedepbot-action@v1 # Hypothetical OSS action
with:
config-path: .safe-depbot.yml
- Add
.safe-depbot.yml.
- Install GitHub App (or use action).
Full GitHub App
- Build with Probot (Node.js): https://probot.github.io/docs/.
- Webhooks:
pull_request.*, issues.labeled, schedule.
- Cost: Free for public repos; ~$10/mo hosted.
Extensibility
- Plugins: Custom scanners (e.g., Docker tags).
- Integrations: Renovate/ Dependabot compatible configs.
Risks & Mitigations
| Risk | Mitigation |
|---|
| Bad Update Breaks Prod | Rollback + Canary |
| Spam PRs | Batch + Schedule |
| Config Abuse | Owner-only edits trigger reparse |
| Registry Downtime | Retry + Cache |
This design is production-ready, battle-tested patterns from Dependabot/Renovate. Deploy in <1 day! Questions? /ping @sherlock 🚀