From da79ad642bf6b7f4777ec1e6d22b426b140e71fd Mon Sep 17 00:00:00 2001 From: mbianchidev Date: Sun, 15 Nov 2026 20:31:13 +0100 Subject: [PATCH] Automate the contract pin for both SendBox crates and block non-main pins - Dependabot groups sendbox-governance and sendbox-security into one daily pull request; auto-merge accepts it when it updates only those crates. - scripts/check-contract-pin.sh fails unless every SendBox crate is locked to a sendbox main commit (no branch, rev, tag, or path pins). CI runs it as the last step of the required SQLite job. - Document the flow in contract, development, and contributing docs. --- .github/dependabot.yml | 11 ++++- .github/workflows/ci.yml | 5 +++ .github/workflows/dependabot-auto-merge.yml | 22 ++++++++- CONTRIBUTING.md | 2 + docs/contract.md | 32 +++++++++----- docs/development.md | 1 + scripts/check-contract-pin.sh | 49 +++++++++++++++++++++ 7 files changed, 108 insertions(+), 14 deletions(-) create mode 100755 scripts/check-contract-pin.sh diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 1a02152..1afa020 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,12 +1,19 @@ version: 2 updates: - # Keeps the sendbox-governance contract on the latest sendbox `main` commit. - # See docs/contract.md. + # Keeps the SendBox contract crates on the latest sendbox `main` commit, in + # one pull request. Both come from the same git checkout, so they always + # move together. See docs/contract.md. - package-ecosystem: cargo directory: / schedule: interval: daily allow: - dependency-name: sendbox-governance + - dependency-name: sendbox-security + groups: + sendbox-contract: + patterns: + - sendbox-governance + - sendbox-security commit-message: prefix: "Bump contract" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cc9032f..230ca13 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,6 +40,11 @@ jobs: - name: Run tests run: cargo test --locked --workspace + # Last, so a pull request tracking a sendbox branch still gets every + # other result; this step then keeps it from merging (docs/contract.md). + - name: Check the contract is pinned to sendbox main + run: scripts/check-contract-pin.sh + postgres: name: Migrations and server (PostgreSQL) runs-on: ubuntu-24.04 diff --git a/.github/workflows/dependabot-auto-merge.yml b/.github/workflows/dependabot-auto-merge.yml index 7cdb818..2757407 100644 --- a/.github/workflows/dependabot-auto-merge.yml +++ b/.github/workflows/dependabot-auto-merge.yml @@ -7,7 +7,7 @@ permissions: jobs: contract-pin: - name: Auto-merge sendbox-governance pin updates + name: Auto-merge sendbox contract pin updates if: github.event.pull_request.user.login == 'dependabot[bot]' && github.repository == 'mbianchidev/sendbox-fleet' runs-on: ubuntu-24.04 timeout-minutes: 5 @@ -19,9 +19,27 @@ jobs: id: metadata uses: dependabot/fetch-metadata@25dd0e34f4fe68f24cc83900b1fe3fe149efef98 # v3.1.0 + # Only pull requests that update nothing but the contract crates. + - name: Check the updated dependencies + id: scope + env: + NAMES: ${{ steps.metadata.outputs.dependency-names }} + run: | + contract=true + IFS=',' read -ra names <<< "$NAMES" + [ "${#names[@]}" -gt 0 ] || contract=false + for name in "${names[@]}"; do + case "${name// /}" in + sendbox-governance | sendbox-security) ;; + *) contract=false ;; + esac + done + echo "Updated: ${NAMES:-nothing}; contract only: $contract" + echo "contract=$contract" >> "$GITHUB_OUTPUT" + # Branch protection holds the merge until every required CI job passes. - name: Enable auto-merge - if: steps.metadata.outputs.dependency-names == 'sendbox-governance' + if: steps.scope.outputs.contract == 'true' run: gh pr merge --auto --squash "$PR_URL" env: PR_URL: ${{ github.event.pull_request.html_url }} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f5b41f5..e3cf09a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -6,6 +6,8 @@ workload-supplied identity never authoritative). 2. Contract types come from `sendbox-governance`. Change them in the sendbox repository first, then update the pin ([docs/contract.md](docs/contract.md)). + A pull request may track a sendbox branch during review, but CI blocks the + merge until it tracks sendbox `main` again. 3. Schema changes need matching PostgreSQL and SQLite migrations and a test. 4. Before opening a pull request, run the checks in [docs/development.md](docs/development.md#checks). CI runs the same diff --git a/docs/contract.md b/docs/contract.md index 67467b3..1ecbc5e 100644 --- a/docs/contract.md +++ b/docs/contract.md @@ -12,30 +12,42 @@ redefining any of those types. ```toml # Cargo.toml (workspace) sendbox-governance = { git = "https://github.com/mbianchidev/sendbox", branch = "main" } +sendbox-security = { git = "https://github.com/mbianchidev/sendbox", branch = "main" } ``` +`sendbox-security` supplies the signing envelope and trust store used for +profile signatures and audit heads. + - The dependency tracks sendbox `main`, and `Cargo.lock` records the exact commit. CI builds with `--locked`, so every build sees the same contract until the lockfile moves. - [Dependabot](../.github/dependabot.yml) checks sendbox `main` daily and opens - a pull request that moves `Cargo.lock` to the latest commit. The + one pull request (group `sendbox-contract`) that moves `Cargo.lock` to the + latest commit. The [auto-merge workflow](../.github/workflows/dependabot-auto-merge.yml) enables - auto-merge on those pull requests, and branch protection merges them only - after every CI job passes. A contract change that breaks this service leaves - the pull request open with failing checks for a maintainer to fix. -- `sendbox-governance` inherits versions from the sendbox workspace and - depends on `sendbox-core` by path; Cargo resolves both from the same git - checkout. + auto-merge when that pull request updates nothing but `sendbox-governance` + and `sendbox-security`, and branch protection merges it only after every CI + job passes. A contract change that breaks this service leaves the pull + request open with failing checks for a maintainer to fix. +- Both crates inherit versions from the sendbox workspace and depend on + `sendbox-core` by path; Cargo resolves all three from the same git checkout, + so they always share one commit. - Only `main` is tracked, so the recorded commit cannot disappear when sendbox feature branches are rewritten or deleted. A pull request that needs an unmerged contract change may track the sendbox pull request branch while - both are in review; it must move back to `main` before it merges. + both are in review. CI's last step, + [`scripts/check-contract-pin.sh`](../scripts/check-contract-pin.sh), fails + until every SendBox crate is locked to a sendbox `main` commit again (it also + rejects `rev`/`tag` pins and local path patches), so such a pull request + cannot merge. After the sendbox pull request merges, set `branch = "main"` + and run `cargo update -p sendbox-governance -p sendbox-security`. To move the lockfile by hand, to the latest `main` commit or to a specific one: ```sh -cargo update -p sendbox-governance -cargo update -p sendbox-governance --precise +cargo update -p sendbox-governance -p sendbox-security +cargo update -p sendbox-governance --precise # moves all three crates +scripts/check-contract-pin.sh cargo test --locked --workspace ``` diff --git a/docs/development.md b/docs/development.md index 2313331..ce9c189 100644 --- a/docs/development.md +++ b/docs/development.md @@ -122,6 +122,7 @@ cargo fmt --all -- --check cargo clippy --locked --workspace --all-targets -- -D warnings cargo test --locked --workspace cargo audit --deny warnings # needs cargo-audit; see .cargo/audit.toml +scripts/check-contract-pin.sh # SendBox crates locked to sendbox main ``` Tests use in-memory SQLite and synthetic data. To run the migration and API diff --git a/scripts/check-contract-pin.sh b/scripts/check-contract-pin.sh new file mode 100755 index 0000000..5d218d0 --- /dev/null +++ b/scripts/check-contract-pin.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash +# Fails unless every SendBox crate is locked to a sendbox `main` commit. +# +# While a sendbox pull request is in review, a fleet pull request may track +# its branch (docs/contract.md). CI runs this check so such a pull request +# cannot merge until it tracks `main` again. Local path patches fail too. +set -euo pipefail + +cd "$(dirname "$0")/.." +repo='https://github.com/mbianchidev/sendbox' +status=0 + +while IFS= read -r line; do + if [[ "$line" != *'branch = "main"'* || "$line" == *'rev ='* || "$line" == *'tag ='* ]]; then + echo "Cargo.toml: SendBox dependency must use branch = \"main\": $line" >&2 + status=1 + fi +done < <(grep -F "git = \"$repo\"" Cargo.toml || true) + +awk -v want="git+$repo?branch=main#" ' + function check() { + if (name !~ /^sendbox-/) return + found++ + hash = substr(source, length(want) + 1) + if (index(source, want) != 1 || hash !~ /^[0-9a-f]+$/ || length(hash) != 40) { + printf "Cargo.lock: %s is locked to %s, not a sendbox main commit\n", + name, (source == "" ? "a local path" : source) > "/dev/stderr" + bad = 1 + } + } + /^\[\[package\]\]$/ { check(); name = ""; source = ""; next } + /^name = / { name = $3; gsub(/"/, "", name) } + /^source = / { source = $3; gsub(/"/, "", source) } + END { + check() + if (found == 0) { + print "Cargo.lock: no SendBox crates found" > "/dev/stderr" + bad = 1 + } + exit bad + } +' Cargo.lock || status=1 + +if [[ "$status" -ne 0 ]]; then + echo "Track sendbox main before merging: set branch = \"main\" in Cargo.toml, then run" >&2 + echo " cargo update -p sendbox-governance -p sendbox-security" >&2 + exit 1 +fi +echo "SendBox contract crates are locked to sendbox main."