From a93043c694cd7ab9c63a9d3a0f6a4cf9deb2d56d Mon Sep 17 00:00:00 2001 From: Krzysztof kuhy Rudnicki Date: Fri, 28 Aug 2026 16:34:14 +0200 Subject: [PATCH] Add the dependency-freshness gate Co-Authored-By: Claude Opus 5 (1M context) --- .../workflows/dependency-freshness.yml | 62 +++++++++++++++++++ _installer_import/.pre-commit-config.yaml | 22 +++++++ .../scripts/check_dependency_freshness.sh | 34 ++++++++++ 3 files changed, 118 insertions(+) create mode 100644 _installer_import/.github/workflows/dependency-freshness.yml create mode 100755 _installer_import/scripts/check_dependency_freshness.sh diff --git a/_installer_import/.github/workflows/dependency-freshness.yml b/_installer_import/.github/workflows/dependency-freshness.yml new file mode 100644 index 0000000..23a0a73 --- /dev/null +++ b/_installer_import/.github/workflows/dependency-freshness.yml @@ -0,0 +1,62 @@ +name: dependency freshness + +# Every dependency on its ecosystem's newest STABLE release, enforced on push +# as well as at commit time. The local pre-commit hook only sees the manifests +# in a commit and can be skipped entirely by a fresh clone that never ran +# `pre-commit install`; this runs `--all` over the whole repo. +# +# `--strict` is CI-only. Offline the gate degrades to its cached answer and +# passes, because `--no-verify` is banned locally and a hook that hard-failed +# on a flaky connection would leave no way to commit. A runner is always +# online, so here an undeterminable answer is a real failure. +# +# Expect this to go red for reasons this repo's commit did not cause: an +# upstream release overnight is enough. That is the chosen behaviour -- the +# alternative is a gate that only notices staleness when someone remembers to +# look. + +on: + push: + branches: [main] + pull_request: + workflow_dispatch: + +jobs: + dependency-freshness: + name: dependencies on newest stable + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + # The gate lives in the shared utils repo so every repo resolves the + # same "latest stable" the same way. Checking it out beats vendoring a + # copy, which is exactly how a gate and its survey start disagreeing. + - name: Check out the shared gate + uses: actions/checkout@v4 + with: + repository: kuhyx/utils + path: .utils + + # "3.x", never a pinned minor: the Python target IS the interpreter the + # gate runs under (registries/toolchain.python_installed), so a runner + # held a release behind this machine reports a repo's `requires-python` + # as excluding "latest" while the same check passes locally. flax-docs-mcp + # hit exactly that -- `>=3.14` green here, red on a 3.13 runner. + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.x" + + - name: Install the gate's two runtime dependencies + run: python -m pip install --upgrade pyyaml packaging + + - name: Cache registry lookups + uses: actions/cache@v4 + with: + path: ~/.cache/dep-freshness + key: dep-freshness-${{ hashFiles('**/pubspec.yaml', '**/pyproject.toml', + '**/requirements*.txt', '**/package.json', '**/Cargo.toml', '**/go.mod') }} + restore-keys: dep-freshness- + + - name: Every dependency is on newest stable + run: bash .utils/scripts/check_dependency_freshness.sh --all --strict diff --git a/_installer_import/.pre-commit-config.yaml b/_installer_import/.pre-commit-config.yaml index 4c6b62e..9c1a169 100644 --- a/_installer_import/.pre-commit-config.yaml +++ b/_installer_import/.pre-commit-config.yaml @@ -15,3 +15,25 @@ repos: entry: scripts/check_md_naming.sh language: system files: \.(md|markdown)$ + + # Every dependency on its ecosystem's newest STABLE release, exact-pinned + # so the question is mechanically answerable at all. + # + # `files:` is what keeps this cheap: a commit touching only source makes + # ZERO network requests, and manifest commits mostly hit a 6h disk cache. + # + # Runs WITHOUT --strict on purpose. Offline it degrades to the cached + # answer and passes with a loud banner; `--no-verify` is banned here, so + # a hook that hard-failed on a flaky connection would leave no way to + # commit at all. CI, always online, is the strict authority. + - id: dependency-freshness + name: dependencies on newest stable + entry: scripts/check_dependency_freshness.sh + language: system + pass_filenames: true + files: >- + (pubspec\.(yaml|lock)|pyproject\.toml|requirements.*\.txt|uv\.lock + |package\.json|package-lock\.json|pnpm-lock\.yaml + |Cargo\.(toml|lock)|go\.(mod|sum) + |\.fvmrc|\.nvmrc|\.python-version + |\.github/workflows/.*\.ya?ml)$ diff --git a/_installer_import/scripts/check_dependency_freshness.sh b/_installer_import/scripts/check_dependency_freshness.sh new file mode 100755 index 0000000..5cb0d78 --- /dev/null +++ b/_installer_import/scripts/check_dependency_freshness.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +# ============================================================================ +# Fail if any dependency in the commit is behind its ecosystem's newest stable. +# +# Thin delegate to the shared gate in ~/utils, which owns the registry +# adapters, the pre-release rules and the allowlist semantics. Copying that +# logic here is what lets one repo's idea of "current" drift from every other +# repo's -- so this script only locates the shared checker and forwards its +# arguments. +# +# Usage: +# scripts/check_dependency_freshness.sh [ ...] # pre-commit +# scripts/check_dependency_freshness.sh --all --strict # CI +# +# Exit: 0 current | 1 behind | 2 allowlist wrong | 3 undeterminable (offline) +# ============================================================================ + +set -euo pipefail + +readonly SHARED_GATE="${UTILS_ROOT:-$HOME/utils}/scripts/check_dependency_freshness.sh" + +main() { + if [[ ! -x "$SHARED_GATE" ]]; then + echo "Error: shared dependency-freshness gate not found at $SHARED_GATE" >&2 + echo " Clone github.com/kuhyx/utils to ~/utils, or set" >&2 + echo " UTILS_ROOT to where it lives." >&2 + exit 1 + fi + + exec bash "$SHARED_GATE" "$@" +} + +main "$@"