-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathsync_cargo.sh
More file actions
executable file
·119 lines (106 loc) · 3.74 KB
/
Copy pathsync_cargo.sh
File metadata and controls
executable file
·119 lines (106 loc) · 3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/env bash
#
# sync_cargo.sh — publish the Cersei workspace crates to crates.io.
#
# The crate currently published is 0.1.9; the workspace has since moved on (and
# gained new crates). This script publishes every library crate at the version
# declared in the workspace `Cargo.toml`, in dependency order (leaves first), so
# crates.io always has a crate's dependencies available before the dependents are
# uploaded. Crates whose current version is already on crates.io are skipped, so
# the script is safe to re-run after a partial/failed run.
#
# Usage:
# ./sync_cargo.sh # publish everything that isn't already up
# ./sync_cargo.sh --dry-run # run `cargo publish --dry-run` for each
# ./sync_cargo.sh --include-cli # also publish the `abstract` CLI binary
# ./sync_cargo.sh --allow-dirty # pass --allow-dirty to cargo publish
#
# Auth: set CARGO_REGISTRY_TOKEN, or run `cargo login` beforehand.
set -euo pipefail
cd "$(dirname "$0")"
DRY_RUN=0
INCLUDE_CLI=0
ALLOW_DIRTY=0
for arg in "$@"; do
case "$arg" in
--dry-run) DRY_RUN=1 ;;
--include-cli) INCLUDE_CLI=1 ;;
--allow-dirty) ALLOW_DIRTY=1 ;;
*) echo "unknown flag: $arg" >&2; exit 2 ;;
esac
done
# Seconds to wait after a successful publish, giving the crates.io index time to
# propagate before a dependent crate is published. Modern cargo also waits for
# the index itself, but this adds a safety margin.
PROPAGATION_SLEEP="${PROPAGATION_SLEEP:-15}"
# Version published for every crate — the single workspace version.
VERSION="$(grep -m1 '^version' Cargo.toml | sed -E 's/.*"([^"]+)".*/\1/')"
if [[ -z "$VERSION" ]]; then
echo "could not read workspace version from Cargo.toml" >&2
exit 1
fi
echo "Workspace version: $VERSION"
# Library crates in dependency order (a crate appears after everything it
# depends on). `cersei` is the umbrella facade and goes last among libraries;
# `abstract-cli` (binary) is optional and goes after that.
CRATES=(
cersei-types
cersei-compression
cersei-embeddings
cersei-lsp
cersei-tools-derive
cersei-hooks
cersei-mcp
cersei-provider
cersei-skills
cersei-memory
cersei-vms
cersei-tools
cersei-agentlang
cersei-agent
cersei-agentrl
cersei-workflows
cersei-tbench
cersei
)
if [[ "$INCLUDE_CLI" == "1" ]]; then
CRATES+=(abstract-cli)
fi
# Return 0 if <name>@<version> already exists on crates.io.
already_published() {
local name="$1" version="$2" code
code="$(curl -fsS -o /dev/null -w '%{http_code}' \
-H 'User-Agent: cersei-sync (https://github.com/pacifio/cersei)' \
"https://crates.io/api/v1/crates/${name}/${version}" 2>/dev/null || true)"
[[ "$code" == "200" ]]
}
# Verification stays on by default so a broken crate is caught before upload.
PUBLISH_FLAGS=()
[[ "$ALLOW_DIRTY" == "1" ]] && PUBLISH_FLAGS+=(--allow-dirty)
published_any=0
for crate in "${CRATES[@]}"; do
if [[ "$DRY_RUN" == "1" ]]; then
echo "==> [dry-run] $crate@$VERSION"
cargo publish -p "$crate" --dry-run ${PUBLISH_FLAGS[@]+"${PUBLISH_FLAGS[@]}"}
continue
fi
if already_published "$crate" "$VERSION"; then
echo "==> $crate@$VERSION already on crates.io — skipping"
continue
fi
echo "==> publishing $crate@$VERSION"
cargo publish -p "$crate" ${PUBLISH_FLAGS[@]+"${PUBLISH_FLAGS[@]}"}
published_any=1
# Don't sleep after the final crate (bash 3.2 has no negative indices).
if [[ "$crate" != "${CRATES[$((${#CRATES[@]} - 1))]}" ]]; then
echo " waiting ${PROPAGATION_SLEEP}s for index propagation..."
sleep "$PROPAGATION_SLEEP"
fi
done
if [[ "$DRY_RUN" == "1" ]]; then
echo "Dry run complete."
elif [[ "$published_any" == "0" ]]; then
echo "Nothing to do — every crate is already at $VERSION on crates.io."
else
echo "Done — published crates at $VERSION."
fi