[rust-magic-release] fix: publish crates in topological order

This commit is contained in:
JasterV 2026-03-07 01:47:00 +01:00
parent b437c5c87e
commit 1b54f8fa48

View file

@ -7,17 +7,29 @@ CRATES_TOKEN="${PLUGIN_CRATES_IO_TOKEN}"
REPO_FULL_NAME="${CI_REPO}" REPO_FULL_NAME="${CI_REPO}"
API_URL="https://codeberg.org/api/v1/repos/${REPO_FULL_NAME}" API_URL="https://codeberg.org/api/v1/repos/${REPO_FULL_NAME}"
# --- Get Workspace Packages in Topological Order --- # Get workspace members in topological order (dependencies first)
PACKAGES=$(cargo metadata --format-version 1 --no-deps | jq -r '.packages | .[] | select(.publish != []) | "\(.name) \(.version) \(.manifest_path)"') # We use 'tac' because 'cargo tree' puts the "roots" at the top.
# Reversing it ensures "leaves" (dependencies) are published first.
ORDERED_CRATES=$(cargo tree --workspace --depth 0 --prefix none --format "{p}" | awk '{print $1}' | tac)
# Get all package metadata in one go
# Use jq to re-sort the metadata to match the ORDERED_NAMES
PACKAGES=$(cargo metadata --format-version 1 --no-deps | jq -r --arg names "$ORDERED_CRATES" '
($names | split("\n")) as $order
| [.packages[] | select(.publish != [])] as $pkgs
| $order[] as $name
| $pkgs[] | select(.name == $name)
| "\(.name) \(.version) \(.manifest_path)"
')
if [ -z "$PACKAGES" ]; then if [ -z "$PACKAGES" ]; then
echo "No publishable packages found in workspace." echo "No publishable packages found."
exit 0 exit 0
fi fi
echo "Starting release process..." echo "Starting release process..."
# --- 3. Process each package --- # --- Process each package ---
echo "$PACKAGES" | while read -r PKG_NAME PKG_VERSION MANIFEST_PATH; do echo "$PACKAGES" | while read -r PKG_NAME PKG_VERSION MANIFEST_PATH; do
TAG_NAME="${PKG_NAME}-v${PKG_VERSION}" TAG_NAME="${PKG_NAME}-v${PKG_VERSION}"