diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 5de1bea9..40cdbb03 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,9 +1,17 @@ version: 2 updates: + # Cooldowns do not delay Dependabot security updates. - package-ecosystem: "uv" directory: "/" schedule: interval: "weekly" + groups: + uv-minor-and-patch: + update-types: + - "minor" + - "patch" + cooldown: + default-days: 3 commit-message: prefix: "chore(deps)" @@ -11,6 +19,8 @@ updates: directory: "/website" schedule: interval: "weekly" + cooldown: + default-days: 3 commit-message: prefix: "chore(deps)" @@ -18,14 +28,23 @@ updates: directory: "/" schedule: interval: "weekly" + groups: + github-actions-minor-and-patch: + update-types: + - "minor" + - "patch" + cooldown: + default-days: 3 commit-message: prefix: "chore(deps)" - # npm updates require running `npm --prefix ui run build` and committing built assets (checked by CI drift job) + # npm updates require rebuilding the committed UI with `npm --prefix ui run build` as described in docs/development/ci.md (Dependency updates); CI checks for drift - package-ecosystem: "npm" directory: "/ui" schedule: interval: "weekly" + cooldown: + default-days: 3 open-pull-requests-limit: 2 groups: ui-dependencies: diff --git a/docs/development/ci.md b/docs/development/ci.md index 8554a274..44bbcaea 100644 --- a/docs/development/ci.md +++ b/docs/development/ci.md @@ -80,6 +80,23 @@ full matrix runs on every merge before anything ships. of that branch, which refreshes the base analysis the PR scans compare against (a stale one made each PR's Python sensor re-parse ~848 files). Every push is its own concurrency group (`run_id`), so none cancels another. +## Dependency updates + +At the start of each release wave, list open Dependabot pull requests with `gh pr list --author "app/dependabot"`. +Land them one at a time. Main protection requires an up-to-date branch and auto-merge is off: merge `origin/main` into +the Dependabot branch, push it, wait for CI, then merge the pull request. + +Complete per-bump fixes before merging: + +- A code-scan action bump also updates the scanner cache key + `sonar-${{ runner.os }}-vX.Y.Z` in `.github/workflows/ci.yml`. The key is pinned by + `test_the_sonar_scanner_cache_is_keyed_and_pinned`. +- An npm bump rebuilds `src/sharpit/ui/static` with `cd ui && npm ci --ignore-scripts && npm run build`, then commits the + built assets. + +A maintainer commit on a Dependabot branch is signed off. A failed DCO check is fixed with a signed remediation commit, +never a force-push. When every Dependabot pull request fails the same shards, check `main` first. + ## CodeQL on release pull requests The classic branch protection rule for `release/*` enables CodeQL default setup on pull requests into version diff --git a/tests/docs/test_procurement_docs.py b/tests/docs/test_procurement_docs.py index 68570ba6..c57d06a9 100644 --- a/tests/docs/test_procurement_docs.py +++ b/tests/docs/test_procurement_docs.py @@ -196,29 +196,40 @@ def _clean_val(val: str) -> object: def _parse_block(block: str) -> dict[str, object]: entry: dict[str, object] = {} - for line in block.splitlines(): + stack: list[tuple[int, dict[str, object] | list[object]]] = [(-1, entry)] + lines = block.splitlines() + for index, line in enumerate(lines): + if not line.strip() or line.lstrip().startswith("#"): + continue + indent = len(line) - len(line.lstrip()) stripped = line.strip() - if not stripped or stripped.startswith("#") or ":" not in stripped: + while stack[-1][0] >= indent: + stack.pop() + parent = stack[-1][1] + if stripped.startswith("- "): + assert isinstance(parent, list) + parent.append(_clean_val(stripped[2:])) + continue + if ":" not in stripped: continue k, v = stripped.split(":", 1) key, val = k.strip(), v.strip() if val: - entry[key] = _clean_val(val) + assert isinstance(parent, dict) + parent[key] = _clean_val(val) else: - entry[key] = {} + next_line = next( + (later for later in lines[index + 1 :] if later.strip() and not later.lstrip().startswith("#")), + "", + ) + child: dict[str, object] | list[object] = [] if next_line.strip().startswith("- ") else {} + assert isinstance(parent, dict) + parent[key] = child + stack.append((indent, child)) return entry def _parse_yaml(text: str) -> dict[str, object]: - try: - import yaml # type: ignore[import-not-found] - - loaded = yaml.safe_load(text) - if isinstance(loaded, dict): - return loaded - except ImportError: - pass - result: dict[str, object] = {"version": 2, "updates": []} updates_list: list[dict[str, object]] = [] result["updates"] = updates_list @@ -251,6 +262,28 @@ def test_dependabot_covers_uv_pip_actions_and_ui_npm() -> None: assert ("github-actions", "/") in entries, "Dependabot must cover github-actions at /" assert ("npm", "/ui") in entries, "Dependabot must cover npm at /ui" + for update in updates: + assert isinstance(update, dict) + schedule = update.get("schedule") + assert isinstance(schedule, dict) + assert schedule.get("interval") == "weekly" + + for ecosystem in ("uv", "github-actions"): + entry = next(u for u in updates if u.get("package-ecosystem") == ecosystem and u.get("directory") == "/") + groups = entry.get("groups") + assert isinstance(groups, dict) + group = next(iter(groups.values())) + assert isinstance(group, dict) + assert {"minor", "patch"}.issubset(set(group.get("update-types", []))) + + for update in updates: + assert isinstance(update, dict) + ecosystem = update.get("package-ecosystem") + cooldown = update.get("cooldown") + assert isinstance(cooldown, dict), f"{ecosystem} needs a cooldown block" + assert isinstance(cooldown.get("default-days"), int), f"{ecosystem} needs an integer cooldown.default-days" + assert cooldown["default-days"] >= 3, f"{ecosystem} needs cooldown.default-days >= 3" + npm_entry = next( ( u