|
| 1 | +#!/usr/bin/env bash |
| 2 | +# `cargo publish --dry-run --workspace` that always verifies each crate against the sibling |
| 3 | +# crates it has just packaged, whatever an earlier run left in the target directory or in |
| 4 | +# CARGO_HOME. Nothing is uploaded. The `rust` lane (scripts/ci-local.sh) and the release |
| 5 | +# pack-verify (scripts/release.mjs) both run it. |
| 6 | +# |
| 7 | +# Two kinds of stale state can make a dependency compile from old source. Both happen when |
| 8 | +# the version stays the same while the source changes, which is every merge between releases: |
| 9 | +# |
| 10 | +# 1. Unpacked source. The dry run publishes each crate to a temporary overlay registry |
| 11 | +# (<target>/package/tmp-registry) and unpacks the ones a later crate depends on into |
| 12 | +# $CARGO_HOME/registry/src/-<hash>/<name>-<version>/. cargo never unpacks again once |
| 13 | +# that directory is complete. scripts/rust-clear-stale-publish-sources.sh removes the |
| 14 | +# copies that differ from the tree. |
| 15 | +# 2. Compiled artifacts. cargo treats a registry crate as immutable for its version, so the |
| 16 | +# fingerprint of `metaobjects v1.3.1` from the overlay registry does not look at its |
| 17 | +# source files: a build of it left by an earlier run is reported `Fresh` and linked into |
| 18 | +# the next crate's verify build. A hosted runner restores server/rust/target from its |
| 19 | +# cache, so a build made before a new module landed in `metaobjects` broke |
| 20 | +# `metaobjects-codegen`'s verify with E0432 on some runners and not others. The dry run |
| 21 | +# therefore uses its own target directory and removes this workspace's crates from it |
| 22 | +# first; third-party crates stay built. |
| 23 | +# |
| 24 | +# crates.io's copy of the same version is not involved: the overlay registry takes |
| 25 | +# precedence for a version it holds ("Unpacking ... (registry .../tmp-registry)"). |
| 26 | +# |
| 27 | +# Usage: scripts/rust-publish-dry-run.sh [workspace-dir] (default server/rust) |
| 28 | +set -euo pipefail |
| 29 | + |
| 30 | +root="$(cd "$(dirname "$0")/.." && pwd)" |
| 31 | +ws="$(cd "${1:-$root/server/rust}" && pwd)" |
| 32 | +cd "$ws" |
| 33 | +target="$ws/target/publish-verify" |
| 34 | + |
| 35 | +"$root/scripts/rust-clear-stale-publish-sources.sh" "$ws" |
| 36 | + |
| 37 | +members=$(cargo metadata --no-deps --format-version 1 --locked | python3 -c ' |
| 38 | +import json, sys |
| 39 | +print(" ".join("-p " + p["name"] for p in json.load(sys.stdin)["packages"])) |
| 40 | +') |
| 41 | +# shellcheck disable=SC2086 # one word per `-p <name>` |
| 42 | +cargo clean -q --locked --target-dir "$target" $members |
| 43 | + |
| 44 | +cargo publish --dry-run --workspace --locked --allow-dirty --target-dir "$target" |
0 commit comments