Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -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"
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 20 additions & 2 deletions .github/workflows/dependabot-auto-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}
Expand Down
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 22 additions & 10 deletions docs/contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <commit-sha>
cargo update -p sendbox-governance -p sendbox-security
cargo update -p sendbox-governance --precise <commit-sha> # moves all three crates
scripts/check-contract-pin.sh
cargo test --locked --workspace
```

Expand Down
1 change: 1 addition & 0 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
49 changes: 49 additions & 0 deletions scripts/check-contract-pin.sh
Original file line number Diff line number Diff line change
@@ -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."