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
49 changes: 49 additions & 0 deletions .github/scripts/check-fleet-lock.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env bash
# Fleet Cargo.lock freshness guard (#10363).
#
# fleet-search path-depends on atlas-search crates (atlas-core,
# atlas-embed, atlas-proto) whose manifests live outside the fleet
# workspace. When one of them gains a dependency, pkgs/fleet/Cargo.lock
# silently falls behind: nothing in the fleet tree changed, and crane's
# own lockfile check compares the lock with the vendor dir built from
# that same lock, so a stale lock validates against itself. The first
# failure used to be a switch build dying at fleet-0.1.0.drv with
# "no matching package named ... found" (#8260, then #10362).
#
# This guard re-resolves the fleet workspace against the real manifests
# with `cargo metadata --locked`, which refuses to run when the
# committed lock is not the lock cargo would write. It compiles
# nothing, so it takes seconds.
#
# Usage: check-fleet-lock.sh [MANIFEST]
# MANIFEST defaults to pkgs/fleet/Cargo.toml in this repo.
# Extra cargo flags (for example --offline) can be passed in
# FLEET_LOCK_CARGO_FLAGS.
set -euo pipefail

ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
MANIFEST="${1:-$ROOT/pkgs/fleet/Cargo.toml}"

if [ ! -f "$MANIFEST" ]; then
echo "::error::fleet lock guard: manifest not found: $MANIFEST"
exit 1
fi
if ! command -v cargo >/dev/null 2>&1; then
echo "::error::fleet lock guard: cargo is not on PATH"
exit 1
fi

# shellcheck disable=SC2086 # FLEET_LOCK_CARGO_FLAGS is a flag list.
if out=$(cargo metadata --locked --format-version 1 ${FLEET_LOCK_CARGO_FLAGS:-} \
--manifest-path "$MANIFEST" 2>&1 >/dev/null); then
echo "fleet lock guard: OK — $(dirname "$MANIFEST")/Cargo.lock matches the resolved workspace"
exit 0
fi

echo "$out" | tail -20
if printf '%s' "$out" | grep -qE 'lock file .*needs to be updated|cannot update the lock file|--locked was passed'; then
echo "::error::fleet lock guard: $(dirname "$MANIFEST")/Cargo.lock is stale against the manifests it resolves (often an atlas-search crate gained a dependency). Fix: cargo update --workspace --manifest-path $MANIFEST, then commit the lock."
else
echo "::error::fleet lock guard: cargo could not resolve $MANIFEST (see the output above)"
fi
exit 1
76 changes: 76 additions & 0 deletions .github/scripts/check-fleet-lock.test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/env bash
# Contract tests for check-fleet-lock.sh (#10363).
# Builds a path-only fixture shaped like fleet: a workspace member that
# path-depends on a crate outside the workspace. The guard must pass a
# fresh lock, and fail once the outside crate gains a dependency the
# committed lock does not know. Path-only, so it runs offline.
set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CHECK="$SCRIPT_DIR/check-fleet-lock.sh"
TMP="$(mktemp -d)"
trap 'rm -rf "$TMP"' EXIT
export FLEET_LOCK_CARGO_FLAGS=--offline
export CARGO_TARGET_DIR="$TMP/target"

failures=0
note_fail() {
echo "FAIL: $1"
failures=$((failures + 1))
}

crate() { # crate <dir> <name> [dependency lines...]
local dir=$1 name=$2
shift 2
mkdir -p "$dir/src"
{
printf '[package]\nname = "%s"\nversion = "0.1.0"\nedition = "2021"\n\n[dependencies]\n' "$name"
printf '%s\n' "$@"
} >"$dir/Cargo.toml"
: >"$dir/src/lib.rs"
}

# pkgs/{fleet,atlas}: fleet's member reaches into atlas by path.
crate "$TMP/pkgs/atlas/core" atlas-core
crate "$TMP/pkgs/atlas/extra" atlas-extra
crate "$TMP/pkgs/fleet/crates/search" fleet-search 'atlas-core = { path = "../../../atlas/core" }'
printf '[workspace]\nmembers = ["crates/search"]\nresolver = "2"\n' >"$TMP/pkgs/fleet/Cargo.toml"
MANIFEST="$TMP/pkgs/fleet/Cargo.toml"
cargo generate-lockfile --offline --manifest-path "$MANIFEST" >/dev/null 2>&1

if bash "$CHECK" "$MANIFEST" >/dev/null 2>&1; then
echo "ok: a fresh lock passes"
else
note_fail "a fresh lock should pass"
fi

# atlas-core gains a dependency; nothing under pkgs/fleet changes.
crate "$TMP/pkgs/atlas/core" atlas-core 'atlas-extra = { path = "../extra" }'
if out=$(bash "$CHECK" "$MANIFEST" 2>&1); then
note_fail "a lock missing the new atlas edge should fail"
elif ! printf '%s' "$out" | grep -qF 'is stale'; then
note_fail "the stale-lock failure should name the stale lock"
printf '%s\n' "$out" | sed 's/^/ /'
else
echo "ok: a lock missing the new atlas edge fails, naming the stale lock"
fi

# The fix the guard names makes it pass again.
cargo update --workspace --offline --manifest-path "$MANIFEST" >/dev/null 2>&1
if bash "$CHECK" "$MANIFEST" >/dev/null 2>&1; then
echo "ok: the named fix makes it pass"
else
note_fail "the lock should pass after cargo update --workspace"
fi

if bash "$CHECK" "$TMP/missing/Cargo.toml" >/dev/null 2>&1; then
note_fail "a missing manifest should fail"
else
echo "ok: a missing manifest fails"
fi

if [ "$failures" -ne 0 ]; then
echo "check-fleet-lock.test: $failures failure(s)"
exit 1
fi
echo "check-fleet-lock.test: OK"
13 changes: 12 additions & 1 deletion .github/scripts/check-fleet-smoke.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
# silently skipped suite cannot report green;
# 3. the registry row fleet.smoke is status "mapped" and names this
# workflow as its venue;
# 4. .github/ci-policy.md carries the fleet-smoke tier row.
# 4. .github/ci-policy.md carries the fleet-smoke tier row;
# 5. the workflow also runs on atlas-search manifest changes and
# runs check-fleet-lock.sh before the build, so a fleet lock
# left stale by an atlas dependency change fails by name (#10363).
# A disagreement fails, naming the broken leg.
#
# Usage: check-fleet-smoke.sh [ROOT] (default: repo root)
Expand Down Expand Up @@ -72,6 +75,14 @@ if ! grep -qF 'passed, 0 failed' "$WF"; then
err "workflow does not assert the suite's 'passed, 0 failed' summary — a skipped suite could report green"
fi

# 5. The lock guard and the atlas path filter (#10363).
if ! grep -qF 'bash .github/scripts/check-fleet-lock.sh' "$WF"; then
err "workflow does not run check-fleet-lock.sh — a stale fleet lock would only fail inside the nix build"
fi
if ! grep -qF '"pkgs/atlas-search/crates/**"' "$WF"; then
err "workflow path filter does not cover pkgs/atlas-search/crates/** — an atlas dependency change could skip the lock guard"
fi

# 3 + 4. Registry row and policy row agree with the workflow.
python3 - "$REGISTRY" <<'PYEOF' || err "registry row fleet.smoke is not mapped to .github/workflows/fleet-smoke.yml"
import json
Expand Down
10 changes: 10 additions & 0 deletions .github/scripts/check-fleet-smoke.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ make_fixture "$MUT"
sed -i '/pkgs\/fleet\/\*\*/d' "$MUT/.github/workflows/fleet-smoke.yml"
expect_fail "$MUT" "workflow without the pkgs/fleet path filter"

MUT="$TMP/no-lock-guard"
make_fixture "$MUT"
sed -i '/bash .github\/scripts\/check-fleet-lock.sh/d' "$MUT/.github/workflows/fleet-smoke.yml"
expect_fail "$MUT" "workflow without the fleet lock guard"

MUT="$TMP/no-atlas-paths"
make_fixture "$MUT"
sed -i '/pkgs\/atlas-search\/crates/d' "$MUT/.github/workflows/fleet-smoke.yml"
expect_fail "$MUT" "workflow without the atlas-search path filter"

MUT="$TMP/pr-trigger"
make_fixture "$MUT"
sed -i 's/^ workflow_dispatch:/ pull_request:\n workflow_dispatch:/' "$MUT/.github/workflows/fleet-smoke.yml"
Expand Down
13 changes: 13 additions & 0 deletions .github/workflows/fleet-smoke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,15 @@ on:
branches: [main]
paths:
- "pkgs/fleet/**"
# fleet-search builds atlas-search crates by path, so an atlas
# manifest change can break the fleet lock and build (#10363).
- "pkgs/atlas-search/Cargo.toml"
- "pkgs/atlas-search/crates/**"
- ".github/workflows/fleet-smoke.yml"
- ".github/scripts/check-fleet-smoke.sh"
- ".github/scripts/check-fleet-smoke.test.sh"
- ".github/scripts/check-fleet-lock.sh"
- ".github/scripts/check-fleet-lock.test.sh"
workflow_dispatch:

permissions:
Expand All @@ -50,6 +56,13 @@ jobs:
bash .github/scripts/check-fleet-smoke.sh
bash .github/scripts/check-fleet-smoke.test.sh

# Before the nix build, so a stale lock fails here by name
# instead of as "no matching package" deep in fleet-0.1.0.drv.
- name: Fleet Cargo.lock matches the atlas manifests (#10363)
run: |
bash .github/scripts/check-fleet-lock.test.sh
bash .github/scripts/check-fleet-lock.sh

- uses: DeterminateSystems/nix-installer-action@3138316df39ed29be04236d7ffc686fa525866aa # v23

- uses: DeterminateSystems/magic-nix-cache-action@84c0677f58dcedf3b91f8223ce36a9ea5b3c84b7 # v15
Expand Down
4 changes: 3 additions & 1 deletion pkgs/fleet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,9 @@ both installs. If the build fails in the cargo vendor step with
'atlas-core'` (or another atlas crate), `pkgs/fleet/Cargo.lock` has
drifted from the atlas-search path dependencies again — the fleet
lock covers their external dependencies too (see `default.nix`).
Regenerate it before building:
`bash .github/scripts/check-fleet-lock.sh` names that drift in
seconds without building anything (fleet-smoke runs it on atlas-search
manifest changes too, #10363). Regenerate the lock before building:

```sh
(cd pkgs/fleet && cargo update --workspace)
Expand Down