#!/usr/bin/env bash # Safeguards before a publication: # 1. a crate published on a private registry declares `publish = [""]` in its Cargo.toml, so that # cargo itself refuses any publication elsewhere (crates.io for example); # 2. the published archive does not carry the kit's own files (.crate-kit/, .gitea/, api/, Makefile): # development tooling, useless to the users of the crate. `exclude` in [package] keeps them out. # Not applicable: kind without publication (PUBLISH=no), registry absent or crates-io. set -euo pipefail . "$(dirname "$0")/common.sh" [ "${PUBLISH:-yes}" = no ] && exit 0 { [ -n "$REGISTRY" ] && [ "$REGISTRY" != crates-io ]; } || exit 0 [ -f "$CARGO_TOML" ] || exit 0 if ! grep -qE "^publish[[:space:]]*=[[:space:]]*\[[[:space:]]*\"$REGISTRY\"[[:space:]]*\]" "$CARGO_TOML"; then err "✗ $CARGO_TOML : publish = [\"$REGISTRY\"] missing in [package] (without it, cargo publish would accept crates.io)" exit 1 fi # What cargo would really put in the archive (not a reading of Cargo.toml). if ! listing=$("$CARGO" package --allow-dirty --list --manifest-path "$CARGO_TOML" 2>&1); then err "✗ cannot list the files of the package, so its content cannot be checked:" printf '%s\n' "$listing" >&2 exit 1 fi internal=$(printf '%s\n' "$listing" | grep -E '^(\.crate-kit/|\.gitea/|api/|Makefile$)' || true) if [ -n "$internal" ]; then err "✗ the published archive would contain the kit's internal files:" printf '%s\n' "$internal" | head -n 5 | sed 's/^/ /' >&2 err " add to [package] of $CARGO_TOML: exclude = [\".crate-kit/\", \".gitea/\", \"api/\", \"Makefile\"]" exit 1 fi