Skip to content

Commit f196dfd

Browse files
authored
ci: clear stale Rust publish state before the dry run (#703)
* fix(ci): verify the Rust crates against fresh sibling builds in the publish dry run cargo fingerprints a registry crate by version, not by its source, so a build of the overlay registry's metaobjects 1.3.1 left in a restored target/ was reported Fresh and linked into metaobjects-codegen's verify build, which then failed with E0432 on runners whose cache predated #701. The dry run now uses its own target directory and removes this workspace's crates from it first; scripts/rust-publish-dry-run.sh is the one definition, run by the rust lane and by the release pack-verify. * no-mistakes(document): Docs follow rust publish dry-run script
1 parent d90ca97 commit f196dfd

5 files changed

Lines changed: 57 additions & 11 deletions

File tree

‎docs/RELEASING.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -987,8 +987,9 @@ live in [`scripts/lib/rust-release.mjs`](../scripts/lib/rust-release.mjs) and ar
987987
3. **Bump**: the workspace version and every sibling crate's version requirement move to the
988988
release's, then `cargo update --workspace` updates the lockfile. The commit carries them
989989
with npm's.
990-
4. **Pack-verify**: `cargo publish --dry-run --workspace` packages each crate and builds it
991-
against its siblings' tarballs, so a crate that builds only from a path in the checkout
990+
4. **Pack-verify**: `scripts/rust-publish-dry-run.sh` runs `cargo publish --dry-run --workspace`
991+
after clearing stale unpacked copies and builds of our own crates, so each crate packages and
992+
builds against its siblings' tarballs and a crate that builds only from a path in the checkout
992993
fails before the confirm.
993994
5. **Publish**, after npm: `cargo publish -p <crate>` in dependency order (`metaobjects`,
994995
`metaobjects-render`, `metaobjects-codegen`, `metaobjects-cli`). cargo waits for each crate

‎scripts/ci-local.sh‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -993,14 +993,13 @@ gate_rust_example() {
993993
cargo test --locked -q --manifest-path examples/rust-service/Cargo.toml
994994
}
995995
# The crates are publishable (ADR-0065 Amendment 3), so a change that would make `cargo publish`
996-
# refuse them fails here, not on the day somebody publishes: package all three, build each
996+
# refuse them fails here, not on the day somebody publishes: package all four, build each
997997
# from its packaged copy, and stop short of uploading. --allow-dirty because this checks the
998998
# packaging, not the working tree; nothing is uploaded, ever, by this gate. Stale unpacked
999-
# copies of our own crates are cleared first: cargo reuses them for the same version and would
1000-
# verify against old source (scripts/rust-clear-stale-publish-sources.sh says how).
999+
# copies and stale builds of our own crates are cleared first: cargo reuses both for the same
1000+
# version and would verify against old source (scripts/rust-publish-dry-run.sh says how).
10011001
gate_rust_publish_dry_run() {
1002-
"$ROOT/scripts/rust-clear-stale-publish-sources.sh" "$PWD" \
1003-
&& cargo publish --dry-run --workspace --locked --allow-dirty
1002+
"$ROOT/scripts/rust-publish-dry-run.sh" "$PWD"
10041003
}
10051004
# Load time per phase and per validation pass on the 20x fitness model. Record only:
10061005
# it prints a table and never fails on a number, so a slowdown is read in the log and

‎scripts/release.mjs‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,9 +329,11 @@ ok(`packed deps verified: all @metaobjectsdev/* pinned to ${VERSION}`);
329329
// --- pack-verify the crates: each packages and builds from its own tarball -------
330330
// `--workspace` resolves the sibling crates from the tarballs it just made, so a crate that
331331
// would only build against a path in this checkout fails here, not on crates.io.
332-
// `--allow-dirty` because the version bump above is not committed yet.
332+
// `--allow-dirty` because the version bump above is not committed yet. The script clears
333+
// stale unpacked copies and stale builds of our crates first, which a re-run at the same
334+
// version would otherwise verify against.
333335
if (rust.publish) {
334-
sh(`cd ${RUST_DIR} && cargo publish --dry-run --workspace --locked --allow-dirty`, { quiet: true });
336+
sh(`scripts/rust-publish-dry-run.sh ${RUST_DIR}`, { quiet: true });
335337
ok(`crates pack-verified: ${crates.join(", ")} @ ${VERSION}`);
336338
}
337339

‎scripts/rust-publish-dry-run.sh‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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"

‎spec/decisions/ADR-0065-rust-is-the-sixth-port.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,8 @@ generator list fixed are replaced. Three things change.
276276
1. **The crates are publishable.** `publish = false` is removed from `metaobjects`,
277277
`metaobjects-codegen` and `metaobjects-cli`, and each carries a description, a README, the
278278
licence text, keywords, categories, a homepage and authors. Decision 4 and Owner ruling 3 are
279-
rewritten to say so. The `rust` lane runs `cargo publish --dry-run --workspace` (the
280-
`gate_rust_publish_dry_run` step of `scripts/ci-local.sh`): it packages all three crates and
279+
rewritten to say so. The `rust` lane runs `scripts/rust-publish-dry-run.sh` (the
280+
`gate_rust_publish_dry_run` step of `scripts/ci-local.sh`), which runs `cargo publish --dry-run --workspace` with stale state cleared: it packages all three crates and
281281
builds each from its package, so a change that would make publishing refuse them fails in
282282
review. **Nothing is published.** Publishing, reserving a crate name and the renumbering of
283283
the workspace onto the shared 1.3.0 line each wait for the owner's go; the one crates.io name

0 commit comments

Comments
 (0)