From 584b0f2660afc8553b656b6546754979cf040aa6 Mon Sep 17 00:00:00 2001 From: ayonious Date: Mon, 9 Nov 2026 13:47:39 +0100 Subject: [PATCH] ci: merge passing non-major Dependabot PRs weekly --- .github/dependabot.yml | 18 ++++ .github/workflows/dependabot-weekly-merge.yml | 83 +++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/dependabot-weekly-merge.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..6d4c9472 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,18 @@ +# Dependabot opens weekly update PRs. It has no auto-merge setting of its own: +# .github/workflows/dependabot-weekly-merge.yml merges the non-major PRs whose +# required test jobs and all other checks pass every Monday. Major version bumps +# are left for manual review. +version: 2 +updates: + - package-ecosystem: npm + directory: / + schedule: + interval: weekly + groups: + development-dependencies: + dependency-type: development + + - package-ecosystem: github-actions + directory: / + schedule: + interval: weekly diff --git a/.github/workflows/dependabot-weekly-merge.yml b/.github/workflows/dependabot-weekly-merge.yml new file mode 100644 index 00000000..c8f179f7 --- /dev/null +++ b/.github/workflows/dependabot-weekly-merge.yml @@ -0,0 +1,83 @@ +name: Weekly Dependabot Merge + +on: + schedule: + # Every Monday at 06:00 UTC, after Dependabot's weekly PRs have had time to run CI. + - cron: '0 6 * * 1' + workflow_dispatch: + +permissions: + contents: write + pull-requests: write + +concurrency: + group: dependabot-weekly-merge + cancel-in-progress: false + +jobs: + merge: + runs-on: ubuntu-latest + + steps: + - name: Merge green Dependabot PRs + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_REPO: ${{ github.repository }} + BASE: ${{ github.event.repository.default_branch }} + # Test jobs that must have run and passed, one per line. + REQUIRED_CHECKS: | + test + run: | + set -uo pipefail + + prs=$(gh pr list --author 'app/dependabot' --base "$BASE" --state open \ + --json number,title --jq '.[] | "\(.number)\t\(.title)"') + + if [ -z "$prs" ]; then + echo "No open Dependabot PRs." + exit 0 + fi + + while IFS=$'\t' read -r number title; do + echo "::group::#$number $title" + + # Skip semver-major bumps ("from 6.0.0 to 7.0.1"); review those by hand. + if [[ "$title" =~ from\ v?([0-9]+)[^\ ]*\ to\ v?([0-9]+) ]] \ + && [ "${BASH_REMATCH[1]}" != "${BASH_REMATCH[2]}" ]; then + echo "Skipping major version bump." + echo "::endgroup::" + continue + fi + + # The test jobs must each have run and succeeded on this PR + # (matrix runs named "job (value)" must all have succeeded). + checks=$(gh pr view "$number" --json statusCheckRollup --jq '.statusCheckRollup') + missing="" + while IFS= read -r job; do + [ -z "$job" ] && continue + if ! jq -e --arg job "$job" \ + '[.[] | select((.name // "") == $job or ((.name // "") | startswith($job + " (")))] + | length > 0 and all(.conclusion == "SUCCESS")' <<< "$checks" > /dev/null; then + missing="$missing [$job]" + fi + done <<< "$REQUIRED_CHECKS" + if [ -n "$missing" ]; then + echo "Tests not passing yet:$missing; skipping." + echo "::endgroup::" + continue + fi + + # Every other check must also be green, not pending or failing. + if ! gh pr checks "$number" > /dev/null; then + echo "Another check is failing or still pending; skipping." + echo "::endgroup::" + continue + fi + + if gh pr merge "$number" --squash --delete-branch; then + echo "Merged." + else + echo "::warning::Could not merge #$number (conflict, or it changes workflow files)." + fi + echo "::endgroup::" + done <<< "$prs"