diff --git a/.mise.toml b/.mise.toml index e0034fe2..b7beae18 100644 --- a/.mise.toml +++ b/.mise.toml @@ -36,6 +36,7 @@ run = [ "bash ./tests/renovate-annotation-managers.sh", "bash ./tests/renovate-version-presets.sh", "bash ./tests/renovate-commit-types.sh", + "bash ./tests/renovate-update-not-scheduled.sh", "bash ./tests/renovate-shell-manager.sh", "bash ./tests/renovate-dprint-plugins.sh", "bash ./tests/renovate-batching-contract.sh", diff --git a/.renovate/base.json5 b/.renovate/base.json5 index a7eef1c8..1497b159 100644 --- a/.renovate/base.json5 +++ b/.renovate/base.json5 @@ -19,20 +19,21 @@ labels: ["dependencies"], osvVulnerabilityAlerts: true, timezone: 'Europe/Amsterdam', - // One weekly window. Every Renovate run inside the window may push to an - // open branch, and every push re-runs the repo's CI, so a single short - // window (instead of Friday + the whole weekend) keeps the number of pushes - // per week low. Automerge itself is not limited by this schedule: GitHub + // One weekly window for new branches. Every new branch and every push + // re-runs the repo's CI, so a single short window (instead of Friday + the + // whole weekend) keeps the number of new PRs per week low; open PRs are kept + // up to date outside it (updateNotScheduled below). Automerge itself is not limited by this schedule: GitHub // merges as soon as the required checks pass. See // docs/design-decisions/0010-batch-renovate-updates-to-save-actions-minutes.md. schedule: [ '* 0-7 * * 6', ], - // Renovate only creates branches inside the schedule but, by default, keeps - // updating existing ones at any time — an open weekly PR would still be - // pushed (and its CI re-run) whenever a newer version clears the soak. - // Manual rebase requests (PR checkbox, dashboard) are still honoured. - updateNotScheduled: false, + // Renovate only creates branches inside the schedule, but keeps existing + // ones rebased and up to date at any time (Renovate's default, stated + // explicitly): an open PR that falls behind or conflicts mid-week is fixed + // without waiting for Saturday. This costs a CI run per push to an open + // branch outside the window; the weekly batch keeps those few. + updateNotScheduled: true, // Renovate's default, stated explicitly (ADR 0013). `auto` rebases a branch // that is behind the base branch only when that is needed for a safe merge: // automerge PRs, and repos that require branches to be up to date. In those @@ -43,8 +44,8 @@ // dotfiles devcontainer) from falling back to a PR when the base moves. // `conflicted` is "not recommended if you have enabled Renovate automerge" // (Renovate docs). The CI cost of rebasing is bounded by the weekly - // all-non-major group, the Saturday-only schedule and - // updateNotScheduled: false above, not by this setting. docker-gated + // all-non-major group and the Saturday-only schedule, not by this + // setting. docker-gated // dependencies keep `conflicted` (packageRules.json5) for their cooldown. rebaseWhen: "auto", ignorePaths: [ @@ -72,8 +73,9 @@ // a lock refresh rarely matters week to week, and each one costs a CI run. schedule: ["* 0-7 1 * *"], // Branch automerge is done by Renovate itself and is skipped outside the - // schedule when updateNotScheduled is false; allow it here so a branch - // whose checks finish after the window does not wait a month to merge. + // schedule when updateNotScheduled is false; keep it true here, whatever + // the global setting, so a branch whose checks finish after the window does + // not wait a month to merge. updateNotScheduled: true, }, registryAliases: { diff --git a/.renovate/groups.json5 b/.renovate/groups.json5 index ad79054e..54aa5a8b 100644 --- a/.renovate/groups.json5 +++ b/.renovate/groups.json5 @@ -54,7 +54,7 @@ // 14-day pr-cooldown soak needs its own branch (ADR 0005). // Majors are not matched, so they keep separate, manually merged PRs; // vulnerability fixes are excluded via vulnerabilityAlerts in base.json5. - description: "Batch every non-major update into a single weekly PR. One PR (instead of one per dependency) means one CI run per Renovate push, and only one open automerge PR to rebase when the base branch moves (within the Saturday window). See docs/design-decisions/0010-batch-renovate-updates-to-save-actions-minutes.md and 0013-rebase-automerge-branches-when-behind.md.", + description: "Batch every non-major update into a single weekly PR. One PR (instead of one per dependency) means one CI run per Renovate push, and only one open automerge PR to rebase when the base branch moves. See docs/design-decisions/0010-batch-renovate-updates-to-save-actions-minutes.md and 0013-rebase-automerge-branches-when-behind.md.", matchUpdateTypes: ["minor", "patch", "pin", "pinDigest", "digest"], groupName: "all non-major dependencies", groupSlug: "all-non-major", diff --git a/docs/architecture.md b/docs/architecture.md index 08f8326f..c579800c 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -1172,9 +1172,10 @@ CI), Renovate batches its work [ADR 0005](design-decisions/0005-pr-age-cooldown-for-untrusted-timestamps.md) cooldown keeps working), and the dotfiles devcontainer image (branch automerge at any time). -- **Schedule:** one window, Saturday 00:00–07:59 (Europe/Amsterdam), and - `updateNotScheduled: false`, so open PRs are not pushed (and their CI is - not re-run) outside it either; manual rebase requests still work. +- **Schedule:** one window, Saturday 00:00–07:59 (Europe/Amsterdam), for + creating branches and PRs. With `updateNotScheduled: true` (Renovate's + default), open PRs are still rebased and updated outside it, so a PR that + falls behind or conflicts mid-week is fixed without waiting for Saturday. Automerge is not tied to the window — GitHub merges as soon as the required checks pass. - **Lock file maintenance:** monthly, on the first day of the month (its @@ -1182,8 +1183,8 @@ CI), Renovate batches its work - **Rebasing:** `rebaseWhen: "auto"` (Renovate's default, [ADR 0013](design-decisions/0013-rebase-automerge-branches-when-behind.md)). An automerge PR that falls behind `main` — or any PR in a repository that - requires up-to-date branches — is rebased on Renovate's next run inside the - window. Only where branches must be up to date (the standard for public + requires up-to-date branches — is rebased on Renovate's next run, also + outside the window (`updateNotScheduled: true`). Only where branches must be up to date (the standard for public repositories) is every automerged update guaranteed to be tested against the latest `main`; elsewhere GitHub's native automerge can merge a behind-base PR before Renovate rebases it. No per-repository override is diff --git a/docs/design-decisions/0010-batch-renovate-updates-to-save-actions-minutes.md b/docs/design-decisions/0010-batch-renovate-updates-to-save-actions-minutes.md index d2f93cb4..c7d686ab 100644 --- a/docs/design-decisions/0010-batch-renovate-updates-to-save-actions-minutes.md +++ b/docs/design-decisions/0010-batch-renovate-updates-to-save-actions-minutes.md @@ -72,7 +72,9 @@ bumping a pin (workflows) or automatically (Renovate presets are read from inside the schedule but keeps _updating_ open ones at any time, which would still push to the weekly PR mid-week. Manual rebase requests are still honoured. Automerge is unaffected: GitHub merges once checks pass, whenever - that is. + that is. _Reversed later: `updateNotScheduled` is `true` again, so open PRs + stay rebased and up to date between windows. Only new branches wait for the + window._ - **Monthly lock-file maintenance** (`* 0-7 1 * *`) instead of Renovate's weekly default. It keeps `updateNotScheduled: true`, because its branch automerge is performed by Renovate and would otherwise wait a month when @@ -161,7 +163,7 @@ and no TODO-to-issue runs for Renovate's automerge pushes. their automerge PRs stall behind the base branch. At the time of writing that applies to `home-assistant-win-companion` and `net-worth-calculator`. Because of `updateNotScheduled: false`, those rebases also happen only in - the Saturday window. _No longer applies since + the Saturday window (`updateNotScheduled` is `true` again since). _No longer applies since [ADR 0013](0013-rebase-automerge-branches-when-behind.md): the global `rebaseWhen: "auto"` already resolves to `behind-base-branch` in those repositories, so no override is needed._ diff --git a/docs/design-decisions/0013-rebase-automerge-branches-when-behind.md b/docs/design-decisions/0013-rebase-automerge-branches-when-behind.md index 1d132ecb..dfb71a23 100644 --- a/docs/design-decisions/0013-rebase-automerge-branches-when-behind.md +++ b/docs/design-decisions/0013-rebase-automerge-branches-when-behind.md @@ -38,7 +38,8 @@ DevSecNinja repositories are owned by a personal account. Meanwhile the CI cost of rebasing is already bounded by other ADR 0010 settings: one weekly `all-non-major` PR instead of one per dependency, a Saturday-only schedule, and `updateNotScheduled: false` (Renovate does not push -to open branches outside the window). +to open branches outside the window). _`updateNotScheduled` was later set back +to `true`, so open branches are also rebased between windows._ ## Decision diff --git a/tests/renovate-batching-contract.sh b/tests/renovate-batching-contract.sh index c577a6ff..49e98a73 100755 --- a/tests/renovate-batching-contract.sh +++ b/tests/renovate-batching-contract.sh @@ -113,8 +113,8 @@ inherits_conflicted="$( fail "docker branch-automerge rules after the docker-gated rule must set rebaseWhen (not conflicted) themselves: ${inherits_conflicted}" jq -e '.schedule | length == 1' <<<"${base}" >/dev/null || fail "base.json5 must use a single weekly schedule window" -jq -e '.updateNotScheduled == false' <<<"${base}" >/dev/null || - fail "base.json5 must set updateNotScheduled: false so open PRs are not pushed outside the window" +jq -e '.updateNotScheduled == true' <<<"${base}" >/dev/null || + fail "base.json5 must set updateNotScheduled: true so open PRs stay rebased between schedule windows" jq -e '.lockFileMaintenance.updateNotScheduled == true' <<<"${base}" >/dev/null || fail "lockFileMaintenance must keep updateNotScheduled: true so its branch automerge is not stranded" jq -e '.lockFileMaintenance.schedule | length > 0' <<<"${base}" >/dev/null || diff --git a/tests/renovate-update-not-scheduled.sh b/tests/renovate-update-not-scheduled.sh new file mode 100755 index 00000000..37027d4c --- /dev/null +++ b/tests/renovate-update-not-scheduled.sh @@ -0,0 +1,78 @@ +#!/usr/bin/env bash +# +# Checks that `updateNotScheduled: true` (.renovate/base.json5) is what a +# typical fleet config resolves to: open Renovate PRs stay rebased and up to +# date between the weekly schedule windows. The extends chain of a legacy fleet +# config (snapshot of DevSecNinja/config-sidecar's renovate.json5), the +# config-sync stub template and this repository's renovate.json5 is resolved +# through the local .renovate/ presets, last value wins, and no later preset or +# the config itself may turn it off. The weekly schedule stays in place. + +set -euo pipefail + +repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" + +if ! command -v pyjson5 >/dev/null 2>&1; then + echo "error: 'pyjson5' not found on PATH. Run via 'mise run test'." >&2 + exit 1 +fi + +to_json() { + pyjson5 --as-json "$1" | tr -d '\r' +} + +presets="{" +for file in "${repo_root}"/.renovate/*.json5; do + presets+="\"$(basename "${file}")\": $(to_json "${file}")," +done +presets="${presets%,}}" + +PRESETS="${presets}" \ + TEMPLATE="$(to_json "${repo_root}/config-sync/templates/renovate.json5")" \ + ROOT="$(to_json "${repo_root}/renovate.json5")" \ + python3 - <<'PY' +import json +import os +import sys + +presets = json.loads(os.environ["PRESETS"]) +local_prefix = "github>DevSecNinja/.github//.renovate/" +errors = [] + + +def resolve(config, key, seen=()): + """The value of a top-level option after Renovate's preset merge: + extends in order, then the config's own value.""" + value = None + for name in config.get("extends", []): + if name.startswith(local_prefix) and name not in seen: + found = resolve(presets[name[len(local_prefix):]], key, seen + (name,)) + if found is not None: + value = found + return config.get(key, value) + + +legacy = { + "extends": [ + "config:recommended", + "helpers:pinGitHubActionDigests", + ":dependencyDashboard", + ":semanticCommits", + ] + [local_prefix + f for f in ("autoMerge.json5", "base.json5", "customManagers.json5", "groups.json5", "labels.json5", "packageRules.json5", "semanticCommits.json5")], +} +configs = { + "legacy fleet config (config-sidecar)": legacy, + "config-sync stub template": json.loads(os.environ["TEMPLATE"]), + "renovate.json5": json.loads(os.environ["ROOT"]), +} +for label, config in configs.items(): + if resolve(config, "updateNotScheduled") is not True: + errors.append(f"{label}: updateNotScheduled resolves to {resolve(config, 'updateNotScheduled')}, want true") + if resolve(config, "schedule") != ["* 0-7 * * 6"]: + errors.append(f"{label}: schedule resolves to {resolve(config, 'schedule')}, want the Saturday window") + +if errors: + print("error: Renovate updateNotScheduled:\n " + "\n ".join(errors), file=sys.stderr) + sys.exit(1) +print("Renovate updateNotScheduled: OK") +PY