Skip to content

Commit 9e46a61

Browse files
committed
chore(ci): handle disabled auto-merge gracefully
1 parent 822c635 commit 9e46a61

3 files changed

Lines changed: 26 additions & 3 deletions

File tree

.github/workflows/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ For the full CI/CD design and release model, see `docs/design/cicd.md`.
2525
4. `release.yml` is the only release orchestrator.
2626
5. `publish.yml` is publish-only and never computes versions.
2727
6. Ruleset on `main` should require `Commit`, `Check`, `Verify` (all jobs), and `Security` before merge.
28+
7. `automerge.yml` only auto-enables Dependabot squash merge when repository auto-merge is enabled; otherwise it emits a warning and leaves the PR for manual merge.

.github/workflows/automerge.yml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,19 @@ jobs:
116116
github-token: ${{ secrets.GITHUB_TOKEN }}
117117
script: |
118118
try {
119+
const repository = await github.rest.repos.get({
120+
owner: context.repo.owner,
121+
repo: context.repo.repo
122+
})
123+
124+
if (!repository.data.allow_auto_merge) {
125+
core.warning(
126+
"Skipping auto-merge: repository auto-merge is disabled. " +
127+
"Enable repository auto-merge in Settings > General to restore this step."
128+
)
129+
return
130+
}
131+
119132
await github.graphql(
120133
`mutation($pullRequestId: ID!) {
121134
enablePullRequestAutoMerge(input: {pullRequestId: $pullRequestId, mergeMethod: SQUASH}) {
@@ -125,9 +138,18 @@ jobs:
125138
{ pullRequestId: context.payload.pull_request.node_id }
126139
)
127140
} catch (error) {
141+
const msg = String(error.message || "")
142+
if (msg.includes("Auto merge is not allowed for this repository")) {
143+
core.warning(
144+
"Skipping auto-merge: repository auto-merge is disabled. " +
145+
"Enable repository auto-merge in Settings > General to restore this step."
146+
)
147+
return
148+
}
149+
128150
core.setFailed(
129151
"Could not enable auto-merge. Ensure repository auto-merge is enabled and branch protections are satisfied.\n" +
130-
error.message
152+
msg
131153
)
132154
}
133155

docs/design/cicd.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ sequenceDiagram
162162
1. `[4e]` `verify.yml / Artifact Install Verify`.
163163
1. `[4f]` `security.yml / Dependency and Secret Scan`.
164164
1. `[5]` `automerge.yml` job runs only when `github.actor == 'dependabot[bot]'`.
165-
1. `[6a]/[7a]` Eligible (pip patch or GHA patch/minor): auto-merge enabled with SQUASH method.
165+
1. `[6a]/[7a]` Eligible (pip patch or GHA patch/minor): auto-merge is enabled with SQUASH when repository auto-merge is enabled; otherwise the workflow logs a warning and leaves the PR on the manual merge path.
166166
1. `[6b]/[7b]` Not eligible: manual merge path stays active.
167167
1. `[8]` Merge requested against Ruleset.
168168
1. `[9a]/[10a]` Required checks green → merge to `main`.
@@ -213,7 +213,7 @@ Configure via **Settings → Actions → General**.
213213

214214
Configure via **Settings → General**.
215215

216-
- Enabled at repository level (required for Dependabot auto-merge path).
216+
- Enabled at repository level to activate the automatic merge path. If disabled, the workflow skips the enable step and warns instead of failing.
217217

218218
### PyPI environment
219219

0 commit comments

Comments
 (0)