The user wants a guide or a blueprint for creating a dependency update bot.
The key requirements are:
PRs (Pull Requests): The bot needs to check for updates and create PRs.
Tests: The bot needs to run tests to verify the update doesn't break anything.
Rollback: There needs to be a mechanism to revert changes if things go wrong after merging.
Exceptions: There needs to be a way to ignore specific dependencies or versions.
This is a complex automation task. I shouldn't just describe what it is; I should explain how to build one or configure existing tools to behave this way. Since building from scratch is rarely the best approach nowadays (unless for a very specific internal system), the most practical answer involves configuring existing popular tools (like Dependabot or Renovate) and adding custom workflows (GitHub Actions) to handle the specific requirements like "Rollback" and "Tests".
Tool Selection:
Dependabot: Good, native to GitHub, but configuration options are somewhat limited compared to Renovate. It handles PRs and tests (via Actions) well. Rollback and exceptions are possible but sometimes rigid.
Renovate Bot: Highly configurable, supports almost everything requested natively (grouping, automerge, limit PRs, pinning/ignoring). It's the best candidate for a "custom" feeling bot without writing raw code.
Approach:
I will structure the response as a guide to setting up a robust pipeline using Renovate Bot (as the engine) and GitHub Actions (for the CI/CD logic), as this combination offers the most flexibility for the specific requirements (especially Rollback and custom exceptions).
Step-by-Step Plan:
Architecture Overview: Briefly explain the components.
The Engine (Renovate): Why Renovate? (Because it allows JSON configuration for almost everything).
Configuration (The "Code"):
PRs: How to schedule and group them.
Exceptions: How to ignore packages or freeze versions.
Tests: How to define automerge rules based on test status.
Rollback Strategy: This is the tricky part. Automated rollback is dangerous.
Strategy A (Git Revert): A manual trigger workflow.
Strategy B (Version Pinning): Renovate detecting a regression and pinning the old version (complex).
Recommendation: A GitHub Action that allows a "One-Click Revert" via workflow dispatch or comment interaction. Let's go with a "Comment-based Revert" action for ease of use.
Testing Strategy: Emphasize lockfiles and CI checks.
Example Configuration Files: Provide actual code snippets (JSON for Renovate, YAML for GitHub Actions).
Refining the "Rollback" Requirement:
Users usually mean "If I merge it and production breaks, fix it fast."
Option 1: Revert the Merge Commit. (Standard Git).
Option 2: Pin the old version in a new PR.
Option 3: Automerge with a "watch period" (too complex for general use).
Selected Solution: I will provide a GitHub Action script that listens for a comment like /rollback on a merged PR to automate the revert process.
Refining "Exceptions":
This means ignoreDeps in Renovate or ignore in Dependabot.
Drafting the Content:
Intro: Define the stack (Renovate + GitHub Actions).
Step 1: Configuring the Bot (Renovate).
Show renovate.json.
Show packageRules for grouping.
Show ignoreDeps for exceptions.
Step 2: Testing Integration.
Renovate creates the PR -> GitHub Actions runs CI.
Renovate configures "Automerge" only if CI passes.
Step 3: The Rollback Mechanism.
I need to write a custom GitHub Action for this.
Logic: Trigger on issue_comment. If comment is /rollback and user has write access, run git revert -m 1 HEAD.
Self-Correction during thought process:
Writing a bot from scratch in Python/Go is overkill and prone to errors (API rate limits, parsing lockfiles). I must recommend configuring an existing tool. I will focus on Renovate because its configuration-as-code approach fits the prompt "Create a dependency update bot" better than Dependabot's YAML-based config.
Final Structure:
System Architecture: Renovate (bot) + GitHub Actions (orchestrator).
1. PRs & Exceptions (Configuration): The renovate.json file.
2. Testing (Automation): Automerge rules based on CI status.
3. Rollback (Emergency Response): A custom workflow for reverting bad merges.
Summary.
Let's write the code snippets mentally to ensure they work.
Rollback Action:
Needs on: issue_comment. Check if issue is a PR. Check comment content. API call to get PR commit. git push --force or revert. Wait, git revert is safer.
Actually, a generic "Rollback" button in the GitHub UI is "Revert" on the PR. I should script a way to trigger this via API or chat-ops if the user wants automation.
I'll provide a "ChatOps" style action for rollback to make it feel like a "bot" feature.
Let's go.
To build a robust Dependency Update Bot, the industry standard is to configure Renovate Bot paired with GitHub Actions (or GitLab CI). Renovate is open-source, highly configurable, and handles the complex logic of parsing lockfiles and creating PRs better than a custom script.
Below is a complete architecture and configuration guide to building this system with Automated Testing, Rollback mechanisms, and Exception Handling.
System Architecture
The Engine: Renovate Bot (runs via GitHub Actions or as a hosted app).
The Validator: CI Pipeline (runs build, lint, and test on every PR).
The Safety Net: Automerge (only if tests pass) + Revert Logic (manual or automated).
1. Configuration: PRs and Exceptions
We define the rules in a renovate.json file at the root of your repository. This handles the "PRs" and "Exceptions" requirements.
File:renovate.json
json
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": ["config:base"],
// 1. PR Logic: Group all non-major updates into one PR to reduce noise
"packageRules": [
{
"matchUpdateTypes": ["patch", "minor"],
"groupName": "non-major dependencies",
"automerge": true // Auto-merge if tests pass (see section 2)
},
// 2. Exception Logic: Pin specific versions or ignore packages
{
"matchPackageNames": ["problematic-package"],
"enabled": false
},
{
"matchPackageNames": ["react", "react-dom"],
"allowedVersions": "<19.0.0" // Prevent breaking major bumps
}
],
// Schedule updates for weekends to avoid disrupting work
"schedule": ["every weekend"]
}
2. Automated Testing (The Gatekeeper)
The bot creates the PR, but your CI system acts as the gatekeeper. We ensure that strict tests are run automatically.
File:.github/workflows/ci.yml
yaml
name: CI
on:
pull_request:
branches: [ main ]
jobs:
verify:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
cache: 'npm'
- name: Install Dependencies
run: npm ci
# The crucial step: If this fails, the Bot WILL NOT merge.
- name: Run Tests
run: npm test -- --coverage
- name: Build Check
run: npm run build
Note: In renovate.json above, we set "automerge": true. Renovate is smart enough to wait until the verify job in this workflow passes before merging.
3. The Rollback Strategy
If a dependency is merged and causes a production issue (e.g., a runtime error not caught by unit tests), you need a rollback.
There are two ways to handle this:
Method A: The "Revert" Button (Recommended)
Renovate preserves the git history. If main breaks after an auto-merge:
Go to the merged PR in GitHub.
Click "Revert".
This creates a new PR that undoes the dependency change.
Merge the Revert PR.
Method B: Automated Lockfile Rollback (Advanced)
If you want a custom script to reset dependencies to the last known good state, you can create a manual trigger workflow.
File:.github/workflows/rollback.yml
yaml
name: Emergency Rollback
on:
workflow_dispatch:
inputs:
commit_sha:
description: 'The SHA of the last known good commit'
required: true
jobs:
rollback:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.GH_TOKEN }} # Needs write access
- name: Reset to previous state
run: |
# Checkout the old lockfile
git checkout ${{ github.event.inputs.commit_sha }} -- package-lock.json
# Commit the revert
git config --global user.name "Rollback Bot"
git config --global user.email "bot@example.com"
git commit -am "chore: rollback dependencies to ${{ github.event.inputs.commit_sha }}"
git push origin main
4. How to Deploy
Install Renovate App: Go to the GitHub Marketplace and install the Renovate app on your repository.
Configure: Add the renovate.json file from Section 1 to your repo.
Enable GitHub Branch Protection:
Go to Repo Settings -> Branches -> Add Rule for main.
Check "Require status checks to pass before merging".
Select your CI job (verify).
This prevents Renovate from auto-merging if tests fail.
Summary of Features
PRs: Renovate creates PRs automatically on weekends.
Tests: GitHub Actions runs npm test on every PR.
Rollback:
Soft: Use GitHub's "Revert" button on the merged PR.
Hard: Use the rollback.yml workflow to reset lockfiles to a specific SHA.
Exceptions:
ignoredPackages: Disables updates for specific libraries.
allowedVersions: Pins packages to specific ranges (e.g., prevent Python 4).