11name : Dependabot Auto-Approve and Auto-Merge
2+
3+ # Auto-merges Dependabot patch/minor updates, narrowed by blast radius:
4+ # github-actions bumps (CI-only, and SHA-pinned per T10) and NuGet packages
5+ # NOT referenced by any shipped src/ project still auto-merge once CI (build)
6+ # passes. NuGet's own dependency-type classification has no test-project
7+ # detection (every NuGet requirement reports as "direct:production" -- see
8+ # Dependabot::Dependency.register_production_check in dependabot-core), so the
9+ # src/ check below is done directly against src/**/*.csproj instead of trusted
10+ # from Dependabot metadata. Majors, dotnet-sdk bumps, docker bumps, and any
11+ # NuGet package referenced by src/ always require a human review and merge.
212on : pull_request
313
414permissions :
@@ -12,20 +22,54 @@ jobs:
1222 steps :
1323 - name : Dependabot metadata
1424 id : metadata
15- uses : dependabot/fetch-metadata@v3.1.0
25+ uses : dependabot/fetch-metadata@25dd0e34f4fe68f24cc83900b1fe3fe149efef98 # v3.1.0
1626 with :
1727 github-token : " ${{ secrets.GITHUB_TOKEN }}"
28+
29+ - uses : actions/checkout@v7
30+ with :
31+ persist-credentials : false
32+
1833 # Only auto-approve/merge patch and minor updates. A major bump can carry
1934 # breaking changes that still compile and pass tests, then ship to consumers
20- # unnoticed -- leave majors for a human to review and merge.
21- - name : Approve a PR
35+ # unnoticed -- leave majors for a human to review and merge. Within
36+ # patch/minor, narrow further by dependency risk (see file header).
37+ - name : Decide auto-merge eligibility
38+ id : eligibility
2239 if : steps.metadata.outputs.update-type == 'version-update:semver-patch' || steps.metadata.outputs.update-type == 'version-update:semver-minor'
40+ env :
41+ ECOSYSTEM : ${{ steps.metadata.outputs.package-ecosystem }}
42+ UPDATED_DEPENDENCIES_JSON : ${{ steps.metadata.outputs.updated-dependencies-json }}
43+ run : |
44+ case "$ECOSYSTEM" in
45+ github_actions)
46+ echo "eligible=true" >> "$GITHUB_OUTPUT"
47+ ;;
48+ nuget)
49+ production_found=false
50+ while IFS= read -r name; do
51+ [ -z "$name" ] && continue
52+ if grep -rqiF "Include=\"$name\"" src/ --include="*.csproj"; then
53+ production_found=true
54+ echo "::notice::src/ references $name -- not auto-merging"
55+ fi
56+ done < <(echo "$UPDATED_DEPENDENCIES_JSON" | jq -r '.[].dependencyName' | sort -u)
57+ echo "eligible=$([ "$production_found" = true ] && echo false || echo true)" >> "$GITHUB_OUTPUT"
58+ ;;
59+ *)
60+ echo "eligible=false" >> "$GITHUB_OUTPUT"
61+ echo "::notice::Not auto-merging -- $ECOSYSTEM ecosystem requires human review"
62+ ;;
63+ esac
64+
65+ - name : Approve a PR
66+ if : steps.eligibility.outputs.eligible == 'true'
2367 run : gh pr review --approve "$PR_URL"
2468 env :
2569 PR_URL : ${{github.event.pull_request.html_url}}
2670 GITHUB_TOKEN : ${{secrets.GITHUB_TOKEN}}
2771 - name : Enable auto-merge for Dependabot PRs
28- if : steps.metadata .outputs.update-type == 'version-update:semver-patch' || steps.metadata.outputs.update-type == 'version-update:semver-minor '
72+ if : steps.eligibility .outputs.eligible == 'true '
2973 run : gh pr merge --auto --merge "$PR_URL"
3074 env :
3175 PR_URL : ${{github.event.pull_request.html_url}}
0 commit comments