# Set Up Dependabot Auto-merge with GitHub Actions

Yes. An agent adds a workflow that approves and auto-merges Dependabot's minor and patch PRs once your checks pass, scoped to the groups you define.

[Run this on Rush](https://cloud.getrush.ai/run/add-dependabot-auto-merge/github-actions/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent first reads how Dependabot is already configured, because auto-merge should follow the grouping the repository has chosen rather than invent one. In a repository like actions/typescript-action, `.github/dependabot.yml` has two ecosystems on a weekly schedule: `github-actions` with an `actions-minor` group for minor and patch updates, and `npm` with an `npm-development` group for minor and patch dev dependencies and an `npm-production` group for patch updates of production dependencies. There is no auto-merge workflow and nothing in the README mentions one. The agent also reads `.github/workflows/ci.yml`, which runs `npm ci`, `npm run format:check`, `npm run lint` and `npm run ci-test` on Node from `.node-version` (24.4.0) and then runs the action itself with `uses: ./`, and `.github/workflows/check-dist.yml`, which rebuilds `dist/` with `npm run bundle` and fails if the checked-in bundle differs.

That second workflow decides the design. A TypeScript action ships its compiled `dist/index.js` in git, so a Dependabot bump of a production dependency such as `@actions/core` changes `package-lock.json` but not `dist/`, and `check-dist` fails on that pull request until someone rebuilds. Auto-merging it would be wrong, and so would merging a dev-dependency bump that changes the Rollup or TypeScript output. The agent therefore writes `.github/workflows/dependabot-auto-merge.yml` on `pull_request` with `if: github.actor == 'dependabot[bot]'`, reads the update with `dependabot/fetch-metadata` to get `update-type` and `package-ecosystem`, and enables auto-merge only for the `github-actions` ecosystem and for npm updates whose type is `version-update:semver-minor` or `version-update:semver-patch`. Production npm dependencies are left for a person, matching the narrower `npm-production` group the repository already chose.

The merge itself is `gh pr merge --auto --squash "$PR_URL"` with `GH_TOKEN` set to `secrets.GITHUB_TOKEN`, preceded by `gh pr review --approve` so a branch protection rule that needs one approval is satisfied. The job declares `permissions: contents: write` and `pull-requests: write` and nothing else. Because `--auto` only queues the merge, GitHub still waits for the required checks, `ci.yml`, `check-dist.yml`, `linter.yml`, `codeql-analysis.yml` and `licensed.yml`, to pass, and merges only then. The agent pins the `fetch-metadata` action to a release tag the same way the repository's other workflows pin theirs, and keeps the file free of a `pull_request_target` trigger, since the job runs no code from the pull request.

Before it pushes, the agent runs `actionlint` on the new file (the repository already has `actionlint.yml` for its linter workflow) and checks the YAML against the `.yaml-lint.yml` rules. It cannot open a Dependabot pull request from the sandbox, so the pull request description says exactly which conditions enable the merge, which repository settings the reader must turn on, namely "Allow auto-merge" in the repository's general settings and a branch protection or ruleset on `main` that requires the existing checks, and what a Dependabot update of a production npm package will still require by hand.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Add Dependabot auto-merge to this repository and open a pull request. Read .github/dependabot.yml and every workflow under .github/workflows first, and note that check-dist.yml fails when a dependency bump changes the compiled dist/ output. Write .github/workflows/dependabot-auto-merge.yml that runs only for pull requests by dependabot[bot], uses dependabot/fetch-metadata pinned to a release to read the update type and ecosystem, approves and enables squash auto-merge with gh for github-actions updates and for npm minor and patch updates of development dependencies, and leaves production dependency bumps for a person. Declare only the permissions the job needs. Do not use pull_request_target. Run actionlint on the new file. In the description list the repository settings the reader must enable for auto-merge to work and the cases the workflow deliberately does not merge.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

What comes back is a pull request that adds one file, `.github/workflows/dependabot-auto-merge.yml`. It triggers on `pull_request`, gates on the Dependabot actor, reads the update with `fetch-metadata`, and approves and queues a squash merge for the cases the prompt allows. `dependabot.yml`, `ci.yml` and `check-dist.yml` are unchanged, and no secret beyond the job's `GITHUB_TOKEN` is needed.

The description quotes the `actionlint` output from the sandbox, lists the two repository settings to turn on and names the checks the merge waits for. It states plainly which updates still need a person: production npm dependencies, and any update whose checks fail, because `--auto` never merges a red pull request.

Before merging, a reviewer confirms that "Allow auto-merge" is enabled on the repository, that the ruleset on `main` requires the five existing workflows so a merge cannot happen before `check-dist` runs, and that an approval from `github-actions[bot]` is acceptable under their review policy. If it is not, they remove the approve step and keep the auto-merge, which then waits for a human approval instead.

## Run it on every repository with Dependabot and no auto-merge

An organization that maintains many actions or libraries starts one `POST /o/{org}/sessions` per repository with this prompt and the repository in `resources`. `GET /o/{org}/github` lists every repository the installation reaches; a short script clones each, checks for `.github/dependabot.yml` without a matching auto-merge workflow, and starts a run for those. Each run reads that repository's own groups and checks, so a repository without a `check-dist` step gets a workflow that also merges production patch updates, and one whose CI is a single job gets a workflow that waits for that job.

Set a webhook URL on the API key and Rush POSTs `run.completed` or `run.failed` when each turn ends, with `session_url` to read the pull request link. Send a fresh UUID as `request_id` with each request so a retried call returns the run already started.

## Why run it on Rush?

The hard part of auto-merge is not the YAML, it is knowing which updates are safe to merge in this repository, and that comes from reading its other workflows. In its own sandbox the agent reads `dependabot.yml`, every workflow and the lockfile, notices that a compiled `dist/` makes production bumps unsafe to merge unattended, and encodes exactly that into the conditions. The reasoning is in the pull request, and `actionlint` output from the sandbox is kept in the run's record.

Done by hand this is a file copied from a blog post and adjusted after the first bad merge. Done on Rush it is one request per repository, each read on its own terms, each ending in a pull request with the settings checklist a reviewer needs.

## Frequently asked questions

### Why not auto-merge every Dependabot pull request?

Because in a TypeScript action a production dependency bump changes `package-lock.json` without rebuilding `dist/`, and `check-dist.yml` will fail until someone runs `npm run bundle` and commits the result. Merging those unattended is not possible anyway, and the agent would rather say so than enable a merge that never fires. Repositories without a committed build output can include production patches.

### Does this need a personal access token?

No. `gh pr review --approve` and `gh pr merge --auto` work with the job's `GITHUB_TOKEN` when the job has `pull-requests: write` and `contents: write`. One caveat: a merge performed with `GITHUB_TOKEN` does not trigger other workflows on the resulting push, which is usually what you want for a dependency bump.

### Will it merge before CI finishes?

No. `--auto` enables GitHub's auto-merge, which waits for every required check on the base branch's ruleset and merges only when they pass. That is why the description tells you to require `ci.yml`, `check-dist.yml` and the other existing workflows on `main`; without a ruleset there is nothing to wait for.

### What about grouped updates?

The workflow reads `fetch-metadata`'s `update-type`, which for a grouped pull request is the highest type in the group, so a group mixing minor and patch updates reads as minor and still qualifies. The agent keeps the groups you defined in `dependabot.yml` and does not add new ones.

## More GitHub Actions jobs

- [Add Dependency Review to Pull Requests with GitHub Actions](https://getrush.ai/run/add-dependency-review/github-actions/)
- [Add a Job Summary to a GitHub Action](https://getrush.ai/run/add-job-summary/github-actions/)
- [Add timeout-minutes to Every GitHub Actions Job](https://getrush.ai/run/add-job-timeouts/github-actions/)

## More jobs like this: Hand off a long task

- [Add Dependabot to an Elixir Library](https://getrush.ai/run/add-dependabot/elixir/)
- [Set Up Dependabot for a Streamlit App](https://getrush.ai/run/add-dependabot/streamlit/)
- [Add Dependency Verification to a Gradle Build](https://getrush.ai/run/add-dependency-verification/gradle/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
