Skip to content

Commit ccdf349

Browse files
rrrutledgeclaude
andcommitted
Add Dependabot auto-merge and verify-or-revert workflows
Automate Dependabot dependency bumps end to end, gated on the post-merge "Publish to website" deploy that pushes generated content to the innersourcecommons.org repo. - dependabot-auto-merge.yml: auto-approve and enable auto-merge for patch and minor Dependabot bumps; hold major bumps for a human, since majors are what have broken the deploy before. - revert-bump-on-failed-deploy.yml: when the deploy fails on a bump commit, open a revert PR that mentions the learning-path maintainers and enable auto-merge on it (one approval still completes the revert). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018zv3SKYNduHEhVyNWLb3Xh
1 parent 13ef340 commit ccdf349

2 files changed

Lines changed: 98 additions & 0 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Dependabot auto-merge
2+
3+
# Auto-approves and enables auto-merge for Dependabot dependency bumps, scoped to
4+
# patch and minor updates. Major bumps (e.g. asciidoctor 3 -> 4) are held for a
5+
# human, because those are the ones that have broken the "Publish to website"
6+
# deploy in the past. The companion "Revert bump on failed deploy" workflow is the
7+
# safety net for a patch/minor bump that still breaks the deploy after it merges.
8+
#
9+
# Requires the repo setting "Allow auto-merge" to be enabled, and "Allow GitHub
10+
# Actions to create and approve pull requests" (already on for this repo).
11+
12+
on: pull_request_target
13+
14+
permissions:
15+
contents: write
16+
pull-requests: write
17+
18+
jobs:
19+
auto-merge:
20+
if: github.actor == 'dependabot[bot]'
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Fetch Dependabot metadata
24+
id: meta
25+
uses: dependabot/fetch-metadata@v2
26+
with:
27+
github-token: ${{ secrets.GITHUB_TOKEN }}
28+
29+
- name: Approve and enable auto-merge (patch/minor only)
30+
if: >
31+
steps.meta.outputs.update-type == 'version-update:semver-patch' ||
32+
steps.meta.outputs.update-type == 'version-update:semver-minor'
33+
env:
34+
PR_URL: ${{ github.event.pull_request.html_url }}
35+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36+
run: |
37+
gh pr review --approve "$PR_URL"
38+
gh pr merge --auto --squash "$PR_URL"
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Revert bump on failed deploy
2+
3+
# Safety net for the Dependabot auto-merge flow. When "Publish to website" fails on
4+
# a push to main whose commit is a Dependabot bump ("Bump ..."), this opens a PR
5+
# that reverts that commit and @-mentions the maintainers. The revert PR is set to
6+
# auto-merge, but branch protection still requires one approving review, so a
7+
# maintainer clicks approve to complete the revert. That review is also the backstop
8+
# against a false revert: a deploy can fail for a reason unrelated to the bump that
9+
# happened to trigger the run, and the maintainer sees the failing run before
10+
# approving.
11+
#
12+
# To make the revert fully hands-off (no human approval), a GitHub App token acting
13+
# as a second identity could approve the revert PR; today the default token cannot
14+
# approve a PR it opened itself.
15+
16+
on:
17+
workflow_run:
18+
workflows: ["Publish to website"]
19+
types: [completed]
20+
21+
permissions:
22+
contents: write
23+
pull-requests: write
24+
25+
jobs:
26+
revert:
27+
if: >
28+
github.event.workflow_run.event == 'push' &&
29+
github.event.workflow_run.head_branch == 'main' &&
30+
github.event.workflow_run.conclusion == 'failure' &&
31+
startsWith(github.event.workflow_run.head_commit.message, 'Bump ')
32+
runs-on: ubuntu-latest
33+
steps:
34+
- uses: actions/checkout@v7
35+
with:
36+
fetch-depth: 0
37+
38+
- name: Revert the breaking bump and open a PR
39+
env:
40+
SHA: ${{ github.event.workflow_run.head_sha }}
41+
TITLE: ${{ github.event.workflow_run.head_commit.message }}
42+
RUN_URL: ${{ github.event.workflow_run.html_url }}
43+
GH_TOKEN: ${{ github.token }}
44+
run: |
45+
set -euo pipefail
46+
BRANCH="revert-deploy-${SHA:0:8}"
47+
git config user.name "github-actions[bot]"
48+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
49+
git checkout -b "$BRANCH"
50+
if ! git revert --no-edit "$SHA"; then
51+
echo "::error::Revert of $SHA did not apply cleanly; a maintainer must revert by hand."
52+
git revert --abort || true
53+
exit 1
54+
fi
55+
git push origin "$BRANCH"
56+
BODY=$(printf '@InnerSourceCommons/learning-path the **Publish to website** deploy failed after this dependency bump merged to `main`, so it was reverted automatically.\n\nFailed run: %s\nReverted commit: %s\n\nThis revert PR has auto-merge enabled and needs one approving review to complete. Before approving, confirm the failing run was actually caused by this bump (a deploy can fail for an unrelated reason). Once the deploy is healthy again, Dependabot will re-open the bump on its next run.' "$RUN_URL" "$SHA")
57+
gh pr create --base main --head "$BRANCH" \
58+
--title "Revert bump that broke the deploy: $TITLE" \
59+
--body "$BODY"
60+
gh pr merge --auto --squash "$BRANCH" || true

0 commit comments

Comments
 (0)