Skip to content

Commit 5ea036c

Browse files
authored
Merge pull request #129 from QuantStrategyLab/fix/remove-dependabot-auto
fix: remove --auto from Dependabot auto-merge workflow
2 parents 3450ef9 + f4562fa commit 5ea036c

1 file changed

Lines changed: 25 additions & 8 deletions

File tree

.github/workflows/dependabot_auto_merge.yml

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,19 @@ jobs:
2222
run: |
2323
set -euo pipefail
2424
BRANCH_NAME="${{ github.event.workflow_run.head_branch }}"
25-
PR_NUMBER=$(gh pr list --repo "${GITHUB_REPOSITORY}" --state open --head "${BRANCH_NAME}" --json number --jq '.[0].number // empty')
25+
PR_PAYLOAD=$(gh pr list --repo "${GITHUB_REPOSITORY}" --state open --head "${BRANCH_NAME}" --json number,headRefOid --jq '.[0] // {}')
26+
PR_NUMBER=$(python3 -c 'import json,sys; print(json.load(sys.stdin).get("number", ""))' <<<"${PR_PAYLOAD}")
27+
PR_HEAD_SHA=$(python3 -c 'import json,sys; print(json.load(sys.stdin).get("headRefOid", ""))' <<<"${PR_PAYLOAD}")
2628
if [ -z "${PR_NUMBER}" ]; then
2729
echo "No open Dependabot PR found for ${BRANCH_NAME}." >> "$GITHUB_STEP_SUMMARY"
2830
exit 0
2931
fi
32+
if [ "${PR_HEAD_SHA}" != "${{ github.event.workflow_run.head_sha }}" ]; then
33+
echo "Skipping auto-merge: PR #${PR_NUMBER} head ${PR_HEAD_SHA} does not match completed CI head ${{ github.event.workflow_run.head_sha }}." >> "$GITHUB_STEP_SUMMARY"
34+
exit 0
35+
fi
3036
echo "pr_number=${PR_NUMBER}" >> "$GITHUB_OUTPUT"
37+
echo "head_sha=${PR_HEAD_SHA}" >> "$GITHUB_OUTPUT"
3138
3239
- name: Evaluate merge eligibility
3340
id: merge_guard
@@ -36,7 +43,7 @@ jobs:
3643
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3744
run: |
3845
set -euo pipefail
39-
gh pr view "${{ steps.pr.outputs.pr_number }}" --repo "${GITHUB_REPOSITORY}" --json number,isDraft,author,url,labels > pr.json
46+
gh pr view "${{ steps.pr.outputs.pr_number }}" --repo "${GITHUB_REPOSITORY}" --json number,isDraft,author,url,body,labels > pr.json
4047
python3 - <<'PY'
4148
import json
4249
import os
@@ -45,16 +52,26 @@ jobs:
4552
pr = json.loads(Path("pr.json").read_text(encoding="utf-8"))
4653
author = (pr.get("author") or {}).get("login")
4754
labels = {item.get("name", "") for item in pr.get("labels", [])}
48-
should_merge = author in {"dependabot[bot]", "app/dependabot"} and not pr.get("isDraft")
49-
reason = "ready" if should_merge else "not_dependabot_or_draft"
55+
body = pr.get("body") or ""
56+
is_major = "update-type: version-update:semver-major" in body
57+
dependabot_authors = {"dependabot[bot]", "app/dependabot"}
58+
is_dependabot = author in dependabot_authors and "dependencies" in labels
59+
should_merge = is_dependabot and not pr.get("isDraft") and not is_major
60+
if should_merge:
61+
reason = "ready"
62+
elif is_major:
63+
reason = "major_update"
64+
else:
65+
reason = "not_eligible_dependabot_pr"
5066
5167
summary_lines = [
5268
"## Auto-Merge Gate",
5369
f"- PR: {pr['url']}",
5470
f"- Author: `{author or '<unknown>'}`",
55-
f"- Draft: `{ 'yes' if pr.get('isDraft') else 'no' }`",
56-
f"- Dependabot label: `{ 'yes' if 'dependencies' in labels else 'no' }`",
57-
f"- Final merge decision: `{ 'merge' if should_merge else 'skip' }`",
71+
f"- Draft: `{'yes' if pr.get('isDraft') else 'no'}`",
72+
f"- Dependabot label: `{'yes' if 'dependencies' in labels else 'no'}`",
73+
f"- Major update: `{'yes' if is_major else 'no'}`",
74+
f"- Final merge decision: `{'merge' if should_merge else 'skip'}`",
5875
f"- Reason: `{reason}`",
5976
]
6077
Path("pr-summary.md").write_text("\n".join(summary_lines).strip() + "\n", encoding="utf-8")
@@ -71,4 +88,4 @@ jobs:
7188
if: steps.merge_guard.outputs.should_merge == 'true'
7289
env:
7390
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
74-
run: gh pr merge "${{ steps.pr.outputs.pr_number }}" --repo "${GITHUB_REPOSITORY}" --rebase --delete-branch --auto
91+
run: gh pr merge "${{ steps.pr.outputs.pr_number }}" --repo "${GITHUB_REPOSITORY}" --rebase --delete-branch --match-head-commit "${{ steps.pr.outputs.head_sha }}"

0 commit comments

Comments
 (0)