feat: Dependabot with auto-merge on CI success#3
Conversation
Co-authored-by: Jamie-BitFlight <25075504+Jamie-BitFlight@users.noreply.github.com>
|
please check the ci pipeline errors @copilot |
There was a problem hiding this comment.
Pull request overview
This PR adds automated dependency management via Dependabot with automatic merging once CI passes. It introduces weekly dependency updates for Python packages and GitHub Actions, and implements a workflow that auto-approves and enables auto-merge for Dependabot PRs.
Changes:
- Adds Dependabot configuration for weekly updates of pip dependencies and GitHub Actions
- Implements auto-merge workflow that approves Dependabot PRs and enables auto-merge when CI passes
- Configures appropriate labels for dependency PRs
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
.github/dependabot.yml |
Configures Dependabot for weekly pip and github-actions updates with labeled PRs |
.github/workflows/dependabot-auto-merge.yml |
Workflow to auto-approve and enable auto-merge for Dependabot PRs after CI success |
| @@ -0,0 +1,26 @@ | |||
| name: Dependabot Auto-Merge | |||
|
|
|||
| on: pull_request | |||
There was a problem hiding this comment.
The workflow trigger is missing branch filters. All other workflows in this repository use explicit branch filters (e.g., branches: ["main"] for push, branches: ["**"] for pull_request). This trigger will run on all pull requests to any branch, which may not be the intended behavior. Consider adding branch filters consistent with other workflows to limit when this workflow runs.
| on: pull_request | |
| on: | |
| pull_request: | |
| branches: ["**"] |
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| auto-merge: | ||
| name: Auto-merge Dependabot PRs | ||
| runs-on: ubuntu-latest | ||
| if: github.actor == 'dependabot[bot]' |
There was a problem hiding this comment.
The workflow-level permissions declaration is inconsistent with other workflows in this repository. All other workflows (ci.yml, zizmor.yml) use permissions: {} at the workflow level and declare specific permissions at the job level. This creates a potential security risk by granting broad permissions to all jobs. Consider following the established pattern: set permissions: {} at the workflow level and declare permissions: with contents: write and pull-requests: write at the job level instead.
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| auto-merge: | |
| name: Auto-merge Dependabot PRs | |
| runs-on: ubuntu-latest | |
| if: github.actor == 'dependabot[bot]' | |
| permissions: {} | |
| jobs: | |
| auto-merge: | |
| name: Auto-merge Dependabot PRs | |
| runs-on: ubuntu-latest | |
| if: github.actor == 'dependabot[bot]' | |
| permissions: | |
| contents: write | |
| pull-requests: write |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Enable auto-merge | ||
| run: gh pr merge --auto --squash "$PR_URL" | ||
| env: | ||
| PR_URL: ${{ github.event.pull_request.html_url }} | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
There was a problem hiding this comment.
The approval step may fail with a "cannot review your own pull request" error. GitHub Actions' GITHUB_TOKEN is tied to the github-actions[bot] account, but Dependabot PRs are authored by dependabot[bot]. While these are different bot accounts, the approval may still be rejected if GitHub treats them as the same entity or if branch protection rules require human approval. Consider testing this behavior or using a GitHub App token with proper permissions, or document that branch protection must allow bot approvals.
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Enable auto-merge | |
| run: gh pr merge --auto --squash "$PR_URL" | |
| env: | |
| PR_URL: ${{ github.event.pull_request.html_url }} | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| GH_TOKEN: ${{ secrets.DEPENDABOT_AUTOMERGE_TOKEN }} | |
| - name: Enable auto-merge | |
| run: gh pr merge --auto --squash "$PR_URL" | |
| env: | |
| PR_URL: ${{ github.event.pull_request.html_url }} | |
| GH_TOKEN: ${{ secrets.DEPENDABOT_AUTOMERGE_TOKEN }} |
| - name: Enable auto-merge | ||
| run: gh pr merge --auto --squash "$PR_URL" | ||
| env: | ||
| PR_URL: ${{ github.event.pull_request.html_url }} | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
There was a problem hiding this comment.
The auto-merge step lacks error handling and doesn't verify that approval succeeded first. If the previous approval step fails but continues, this step will attempt to enable auto-merge on an unapproved PR, which will fail. The workflow should either fail fast on approval errors or check if approval succeeded before attempting auto-merge. Consider adding a conditional check or proper error handling between these steps.
| jobs: | ||
| auto-merge: | ||
| name: Auto-merge Dependabot PRs | ||
| runs-on: ubuntu-latest | ||
| if: github.actor == 'dependabot[bot]' | ||
|
|
||
| steps: | ||
| - name: Approve PR | ||
| run: gh pr review --approve "$PR_URL" | ||
| env: | ||
| PR_URL: ${{ github.event.pull_request.html_url }} | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Enable auto-merge | ||
| run: gh pr merge --auto --squash "$PR_URL" | ||
| env: | ||
| PR_URL: ${{ github.event.pull_request.html_url }} | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
There was a problem hiding this comment.
The workflow is missing security filtering for Dependabot PR types. Currently, it will auto-approve and auto-merge all Dependabot PRs regardless of whether they are patch, minor, or major version updates. Major version updates can introduce breaking changes. Consider adding logic to filter by update type (e.g., only auto-merge patch and minor updates) or by dependency criticality. You can access this information via github.event.pull_request.labels or by parsing the PR title/body.
| version: 2 | ||
| updates: | ||
| - package-ecosystem: "pip" | ||
| directory: "/" | ||
| schedule: | ||
| interval: "weekly" | ||
| labels: | ||
| - "dependencies" | ||
| - "python" | ||
|
|
||
| - package-ecosystem: "github-actions" | ||
| directory: "/" | ||
| schedule: | ||
| interval: "weekly" | ||
| labels: | ||
| - "dependencies" | ||
| - "github-actions" |
There was a problem hiding this comment.
The Dependabot configuration should include additional security settings. The configuration is missing important fields like open-pull-requests-limit (defaults to 5, which may overwhelm CI), rebase-strategy (to handle conflicts), and versioning-strategy (important for GitHub Actions). Consider adding these for better control. For example, limiting open PRs to 3, and for the github-actions ecosystem, consider adding versioning-strategy: "increase" to ensure SHA-pinned actions are updated correctly.
| - package-ecosystem: "pip" | ||
| directory: "/" | ||
| schedule: | ||
| interval: "weekly" |
There was a problem hiding this comment.
The pip ecosystem configuration should include a groups specification. Looking at pyproject.toml, the project uses dependency groups (dev group with tools like pytest, mypy, ruff). Without the groups field, Dependabot will only update runtime dependencies, not dev dependencies. Add groups: ["dev"] to ensure dev dependencies are also kept up to date.
| interval: "weekly" | |
| interval: "weekly" | |
| groups: | |
| - "dev" |
…orkflow Co-authored-by: Jamie-BitFlight <25075504+Jamie-BitFlight@users.noreply.github.com>
Fixed in e59bd67. There were three zizmor findings causing the CI failure:
|
|
please do another pass over the failing ci pipelines @copilot |
Co-authored-by: Jamie-BitFlight <25075504+Jamie-BitFlight@users.noreply.github.com>
Fixed in 1ab55b5. The remaining zizmor CI failure was
|
.github/dependabot.ymlforpipandgithub-actionsecosystems, weekly schedule.github/workflows/dependabot-auto-merge.ymlwith auto-approve and squash auto-mergeerror[bot-conditions](HIGH): usegithub.event.pull_request.user.login+ fork guardhelp[dependabot-cooldown]:default-daysset to 7 (zizmor minimum); simplified cooldown to singledefault-days: 7open-pull-requests-limit: 5to both ecosystemspermissions: {}at workflow level, specific at job levelbranches: ["**"]trigger filter (consistent with other workflows)fetch-metadatastep + skip approve/auto-merge for semver-major updatesOriginal prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.