#!/usr/bin/env bash # Publishes the current version on the $REGISTRY registry (private, or crates-io with CARGO_REGISTRY_TOKEN). # DRY_RUN non-empty: assembles and builds the package without sending it. # # Idempotent: if the version is already published, it is a success (allows replaying the release # workflow after a later failure). Authentication: variable CARGO_REGISTRIES__TOKEN # ("Bearer "), otherwise built from the forge token (forge_token: FORGETOKEN in CI). # # --allow-dirty: in a colocated jj repository, git always sees the working copy as # modified relative to its HEAD, even when the jj commit is already pushed. set -euo pipefail . "$(dirname "$0")/common.sh" if [ "${PUBLISH:-yes}" = no ]; then info " (kind ${CRATE_KIND:-crate}: nothing to publish on the registry)" exit 0 fi [ -n "$REGISTRY" ] || { err "✗ no registry: declare the kit extension (KIT_OVERLAY in the Makefile, org.mk) or set REGISTRY = crates-io"; exit 1; } version=$(current_version) name=$(crate_name) if [ -n "${DRY_RUN:-}" ]; then warn "→ Checking the publication of $name $version (without sending)..." "$CARGO" publish --registry "$REGISTRY" --allow-dirty --dry-run exit 0 fi warn "→ Publishing $name $version on registry $REGISTRY..." log=$(mktemp) trap 'rm -f -- "$log"' EXIT if "$CARGO" publish --registry "$REGISTRY" --allow-dirty 2>&1 | tee "$log" >&2; then ok "✓ $name $version published" elif grep -qiE 'already (exists|uploaded)|crate version .* is already' "$log"; then warn " $name $version is already published on $REGISTRY: nothing to do" else err "✗ Publication of $name $version failed" exit 1 fi