The user wants me to design or describe a "Dependency hygiene bot."
This bot needs to handle four specific areas:
Licenses: Checking dependency licenses (e.g., copyleft vs. permissive).
Vuln scans: Vulnerability scanning (CVEs).
Update PRs: Automating dependency updates via Pull Requests.
Test gates: Ensuring tests pass before merging updates.
The user's prompt is concise and looks like a requirements list or a title. I should respond with a structured solution or architecture for building/configuring such a bot.
Target Audience: Developers, DevOps engineers, or platform teams looking to implement this.
Goal: Provide a comprehensive guide or "architecture blueprint" for a Dependency Hygiene Bot.
Key Components to Address:
Tooling: What existing tools do this? (Dependabot, Renovate, Snyk, etc.)
Workflow: How do these pieces fit together in a CI/CD pipeline?
Configuration: What does the config look like?
Logic/Policies: How to handle the specific requirements (Licenses, Vulns, Tests).
Drafting the Solution:
Introduction: Acknowledge the concept. It's essentially an automated supply chain security workflow.
The "Stack" (Buy vs. Build):
Most people shouldn't build a bot from scratch. They should use Renovate or Dependabot combined with SCA (Static Analysis) tools like Snyk, Checkmarx, or Trivy.
Renovate is generally more flexible for the "Update PRs" part regarding grouping and scheduling.
Addressing the 4 Requirements:
1. Licenses:
Mechanism: A step in the CI pipeline or a check within the bot.
Integration: Block PRs if high/critical CVEs are found.
3. Update PRs:
Mechanism: Automated dependency bumping.
Tools: Renovate (preferred for power users), Dependabot.
Strategy: Group minor patches, separate majors. Automerge if tests pass + low risk.
4. Test Gates:
Mechanism: The CI pipeline running on the automated PR.
Requirement: The bot must trigger CI. CI must pass.
Automerge: If (Tests Pass) AND (Vulns == 0) AND (License == Valid) -> Auto Merge.
Architecture/Workflow Diagram (Mental):
Schedule runs -> Bot checks registry -> Creates PR.
PR triggers CI.
CI Step 1: Build/Install.
CI Step 2: Unit Tests.
CI Step 3: SCA (Vulns).
CI Step 4: License Check.
Branch Protection Rules: Require all checks green.
Implementation Example (Configuration):
I'll provide a renovate.json example because it's the industry standard for this specific "bot" behavior.
I'll provide a GitHub Actions workflow snippet for the "Test Gates" and "Vuln/License" checks.
Refining the content:
Make it modular.
Highlight Automation vs. Notification.
Mention "Automerge" as the ultimate hygiene goal (it keeps the tree clean without human toil).
Self-Correction/Double Check:
Did I miss licenses? No, need to explicitly mention allowed licenses list.
Did I miss test gates? No, that's the CI part.
Is this a "bot" script? I shouldn't write a Python script from scratch unless asked, because tools like Renovate already exist. I will frame it as "Configuring the Bot Ecosystem."
Structure of the Response:
High-Level Architecture: The ecosystem view.
The Engine (Renovate/Dependabot): Handling Update PRs.
The Gatekeeper (CI/CD): Handling Tests, Vulns, Licenses.
Section 1: Tool Selection. Recommend Renovate Bot. It's the most configurable for "Hygiene."
Section 2: The Workflow.
Renovate detects update -> Opens PR.
CI Pipeline runs:
npm install / pip install
npm test / pytest
trivy fs . (Vuln scan)
license-checker (License hygiene)
Section 3: Automerge. The secret sauce. If all checks pass, merge it automatically.
This looks solid. I will generate a markdown guide.
This is a blueprint for building a Dependency Hygiene Bot. While you can write a custom script to do this, the industry standard is to configure Renovate Bot (self-hosted or via the GitHub App) combined with a strict CI pipeline.
Here is the architectural blueprint, configuration examples, and workflow logic.
1. The Architecture
The bot operates on a Pull Request (PR) based workflow. It does not commit directly to main.
Scheduler: Triggers on a cron schedule (e.g., daily/weekly).
Analyzer: Checks registries (npm, PyPI, Maven) for new versions.
PR Creator: Opens a draft PR with the version bump.
The Gatekeeper (CI): Runs the required checks (Vulns, License, Tests).
Merger: If checks pass, the bot auto-merges.
2. The Configuration (The "Brain")
Renovate Bot is the best tool for this because it supports automerging, grouping, and custom managers out of the box.
Create a renovate.json in your repository root:
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"config:base"
],
"dependencyDashboard": true,
"automerge": true,
"platformAutomerge": true,
"prConcurrentLimit": 5,
"branchConcurrentLimit": 10,
"packageRules": [
{
"description": "Group all non-major updates (patch/minor) into one PR",
"matchUpdateTypes": ["patch", "minor"],
"groupName": "Non-Major Dependencies",
"automerge": true
},
{
"description": "Require approval for major version updates",
"matchUpdateTypes": ["major"],
"automerge": false
}
],
"vulnerabilityAlerts": {
"enabled": true,
"automerge": true,
"groupName": "Security Vulnerabilities",
"schedule": ["at any time"]
}
}
3. The Gatekeeper (CI Pipeline)
The bot creates the PR, but your CI pipeline (GitHub Actions, GitLab CI, etc.) acts as the Hygiene Enforcer. The bot will only automerge if ALL of these jobs pass.
Here is a GitHub Actions workflow example (.github/workflows/ci.yml) that enforces the hygiene rules:
name: Dependency Hygiene Gate
on:
pull_request:
branches: [ main ]
jobs:
# 1. CODE QUALITY & BUILD
test-and-build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- run: npm run lint
# Unit tests must pass
- run: npm run test:coverage
# 2. VULNERABILITY SCAN
vulnerability-scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- run: npm ci
# Fail job if CVEs found
- name: Run Audit
run: npm audit --audit-level=high
# OR use a dedicated SCA tool like Trivy/Snyk
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
scan-type: 'fs'
ignore-unfixed: true
format: 'table'
exit-code: '1' # Fail the build
# 3. LICENSE HYGIENE
license-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- run: npm ci
- name: Check Licenses
run: |
# Define allowed licenses (SPDX identifiers)
ALLOWED_LICENSES="MIT;Apache-2.0;BSD-2-Clause;BSD-3-Clause;ISC"
# Use license-checker to validate
npx license-checker --summary
npx license-checker --failOn "GPL;AGPL;LGPL;WTFPL" --onlyAllow "$ALLOWED_LICENSES"
4. Workflow Logic
Here is how the bot handles specific scenarios based on the setup above:
Gatekeeper: Validates that the fix doesn't break tests.
Bot: Auto-merges immediately to patch the hole.
Scenario C: Major Version Update (e.g., v1 -> v2)
Bot: Opens PR.
Gatekeeper: Runs tests.
Outcome 1 (Tests Fail): The PR stays open. The bot labels it update-failed. A human must fix breaking changes.
Outcome 2 (Tests Pass): The bot waits. Because of the config:base rule for major versions, it will not automerge. It requires a human review (Code Owner approval).
Scenario D: "Copyleft" License Introduced
Bot: Opens PR to add a new dep.
Gatekeeper: The license-checker job detects a forbidden license (e.g., GPL).
Result: The CI check fails (Red X).
Bot: The bot sees a failed status check and does not merge. The PR rots until a human reviews why the license check failed.
Summary of Tools
Requirement
Recommended Tool
Why?
Update PRs
Renovate Bot
Faster, more configurable than Dependabot. Supports grouping.
Vuln Scans
Trivy / Snyk
Scans OS packages and language dependencies.
Licenses
license-checker (JS) / pip-licenses (Python)
Programmatically checks SPDX IDs against an allow-list.
Test Gates
GitHub Actions / GitLab CI
The enforcement engine.
Implementation Checklist
Install Renovate App on repo (or self-host).
Create renovate.json (configure grouping).
Add npm audit (or yarn audit / pip-audit) to CI pipeline.
Add License Checker step to CI pipeline.
Enable "Require status checks to pass before merging" in Repository Branch Protection rules.