Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@ updates:
prefix: ci
include: scope
labels: [dependencies]
open-pull-requests-limit: 5
groups:
actions:
patterns: ["*"]
update-types: ["minor", "patch"]
actions-major:
patterns: ["*"]
update-types: ["major"]

- package-ecosystem: pip
directory: /
Expand All @@ -36,9 +41,14 @@ updates:
prefix: build
include: scope
labels: [dependencies]
open-pull-requests-limit: 5
groups:
dev-tools:
patterns: ["*"]
update-types: ["minor", "patch"]
dev-tools-major:
patterns: ["*"]
update-types: ["major"]

# The demo images must stay at the versions CI tests with the pinned binaries
# (tests/test_demo.py), so new versions are bumped by hand. Version updates are ignored
Expand All @@ -54,6 +64,7 @@ updates:
prefix: build
include: scope
labels: [dependencies]
open-pull-requests-limit: 5
ignore:
- dependency-name: "*"
update-types: ["version-update:semver-major", "version-update:semver-minor", "version-update:semver-patch"]
Expand Down
77 changes: 77 additions & 0 deletions .github/workflows/dependabot-automerge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Approves Dependabot's patch and minor updates and turns on auto-merge (squash); GitHub merges
# once the required checks pass. Majors, 0.x minors and updates without a semver type (image
# digests) stay for a manual review. The update types come from the metadata block of
# Dependabot's commit message, the same source dependabot/fetch-metadata reads.
name: dependabot-automerge

on:
pull_request:
Comment thread
ItsPaulAT marked this conversation as resolved.
Resolved
types: [opened, synchronize, reopened]

permissions: {}

concurrency:
group: dependabot-automerge-${{ github.event.pull_request.number }}
cancel-in-progress: true

jobs:
automerge:
name: automerge
if: >-
github.event.pull_request.user.login == 'dependabot[bot]' &&
github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-24.04
timeout-minutes: 5
permissions:
contents: write
pull-requests: write
steps:
- name: Approve and enable auto-merge for patch and minor updates
env:
GH_TOKEN: ${{ github.token }}
REPO: ${{ github.repository }}
PR_NUMBER: ${{ github.event.pull_request.number }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
set -euo pipefail
commits="$(gh api "repos/$REPO/pulls/$PR_NUMBER/commits?per_page=100")"
authors="$(jq -r '[.[].author.login // "unknown"] | unique | join(",")' <<<"$commits")"
if [ "$authors" != "dependabot[bot]" ]; then
Comment thread
ItsPaulAT marked this conversation as resolved.
Resolved
echo "::notice::Commits by $authors; left for a manual review."
exit 0
fi
export MESSAGE
MESSAGE="$(jq -r '.[-1].commit.message' <<<"$commits")"
verdict="$(python3 - <<'PY'
import os
deps, block = [], False
for line in os.environ["MESSAGE"].splitlines():
if line == "updated-dependencies:":
block = True
elif block and line in ("...", "---", ""):
break
elif block and line.startswith("- "):
deps.append({})
if block and deps and ":" in line:
key, _, value = line[2:].partition(":")
deps[-1][key.strip()] = value.strip().strip("'\"")
reasons = []
for d in deps:
kind = d.get("update-type", "")
name = d.get("dependency-name", "?")
if kind not in ("version-update:semver-patch", "version-update:semver-minor"):
reasons.append(f"{name}: {kind or 'no semver update type'}")
elif kind.endswith("minor"):
version = d.get("dependency-version", "").removeprefix("v")
if not version or version.startswith("0."):
reasons.append(f"{name}: minor update below 1.0 or unknown version")
print("; ".join(reasons) if deps else "no update metadata")
PY
)"
if [ -n "$verdict" ]; then
echo "::notice::Left for a manual review ($verdict)."
exit 0
fi
url="https://github.com/$REPO/pull/$PR_NUMBER"
gh pr review "$url" --approve || echo "::warning::Could not approve the pull request."
gh pr merge "$url" --auto --squash --match-head-commit "$HEAD_SHA"
11 changes: 6 additions & 5 deletions scripts/check_pr_title.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
TYPES = ("feat", "fix", "docs", "refactor", "perf", "test", "style", "build", "ci", "chore", "revert", "security")
TITLE_RE = re.compile(r"^(?P<type>[a-z]+)(?:\((?P<scope>[a-z0-9][a-z0-9._/-]*)\))?(?P<bang>!)?: (?P<subject>\S.*)$")
MAX_LENGTH = 100
# Bots whose titles follow Conventional Commits but start the summary with a capital ("Bump ...").
# Only the lower-case rule is relaxed for them; format, types, length and wording still apply.
CAPITALISED_SUMMARY_OK = ("dependabot[bot]",)
# Bots whose titles follow Conventional Commits but start the summary with a capital ("Bump ...")
# and can run past MAX_LENGTH ("... in the actions group across 1 directory"). Only the lower-case
# rule and the length limit are relaxed for them; format, types and wording still apply.
BOT_AUTHORS = ("dependabot[bot]",)


def problems(title: str, author: str = "") -> list[str]:
Expand All @@ -45,9 +46,9 @@ def problems(title: str, author: str = "") -> list[str]:
if subject.endswith("."):
out.append("the summary must not end with a full stop")
if (subject[:1].isupper() and not subject.split()[0].isupper()
and author not in CAPITALISED_SUMMARY_OK):
and author not in BOT_AUTHORS):
out.append("the summary must start with a lower-case letter (imperative mood: 'add', 'fix')")
if len(title) > MAX_LENGTH:
if len(title) > MAX_LENGTH and author not in BOT_AUTHORS:
out.append(f"the title is {len(title)} characters long; keep it to {MAX_LENGTH}")
out += [f"wording: {e.split(': ', 1)[-1]}" for e in check_string(title)]
return out
Expand Down
7 changes: 7 additions & 0 deletions tests/test_check_pr_title.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ def test_dependabot_may_capitalise(self):
self.assertTrue(pt.problems("Bump the actions group", "dependabot[bot]"))
self.assertTrue(any(p.startswith("wording") for p in pt.problems("ci(deps): Bump the pro version", "dependabot[bot]")))

def test_dependabot_may_exceed_the_length_limit(self):
title = ("ci(deps): Bump DavidAnson/markdownlint-cli2-action from 24.2.0 to 25.0.0 "
"in the actions group across 1 directory")
self.assertGreater(len(title), pt.MAX_LENGTH)
self.assertEqual(pt.problems(title, "dependabot[bot]"), [])
self.assertTrue(pt.problems(title.replace("Bump", "bump"), "someone"))

def test_offer_wording_is_rejected(self):
"""Release notes are built from the titles, so they must be offer-free too."""
for title in ("feat: add pro version toggle", "docs: add donation link", "feat: coming soon page",
Expand Down