Some checks are pending
Test Publishing Setup / Test Publishing Setup (pull_request) Waiting to run
- Add a workflow for testing the publishing setup - Add a workflow for publishing SAL crates to crates.io - Improve crate metadata and version management - Add optional dependencies for modularity - Improve documentation for publishing and usage
219 lines
5.8 KiB
Bash
Executable File
219 lines
5.8 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# SAL Publishing Script
|
|
# This script publishes all SAL crates to crates.io in the correct dependency order
|
|
# Handles path dependencies, version updates, and rate limiting
|
|
|
|
set -e
|
|
|
|
# Colors for output
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Configuration
|
|
DRY_RUN=false
|
|
WAIT_TIME=15 # Seconds to wait between publishes
|
|
VERSION=""
|
|
|
|
# Parse command line arguments
|
|
while [[ $# -gt 0 ]]; do
|
|
case $1 in
|
|
--dry-run)
|
|
DRY_RUN=true
|
|
shift
|
|
;;
|
|
--wait)
|
|
WAIT_TIME="$2"
|
|
shift 2
|
|
;;
|
|
--version)
|
|
VERSION="$2"
|
|
shift 2
|
|
;;
|
|
-h|--help)
|
|
echo "Usage: $0 [OPTIONS]"
|
|
echo ""
|
|
echo "Options:"
|
|
echo " --dry-run Show what would be published without actually publishing"
|
|
echo " --wait SECONDS Time to wait between publishes (default: 15)"
|
|
echo " --version VER Set version for all crates"
|
|
echo " -h, --help Show this help message"
|
|
exit 0
|
|
;;
|
|
*)
|
|
echo "Unknown option: $1"
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
# Crates to publish in dependency order
|
|
CRATES=(
|
|
"os"
|
|
"process"
|
|
"text"
|
|
"net"
|
|
"git"
|
|
"vault"
|
|
"kubernetes"
|
|
"virt"
|
|
"redisclient"
|
|
"postgresclient"
|
|
"zinit_client"
|
|
"mycelium"
|
|
"rhai"
|
|
)
|
|
|
|
echo -e "${BLUE}===============================================${NC}"
|
|
echo -e "${BLUE} SAL Publishing Script${NC}"
|
|
echo -e "${BLUE}===============================================${NC}"
|
|
echo ""
|
|
|
|
if [ "$DRY_RUN" = true ]; then
|
|
echo -e "${YELLOW}🔍 DRY RUN MODE - No actual publishing will occur${NC}"
|
|
echo ""
|
|
fi
|
|
|
|
# Check if we're in the right directory
|
|
if [ ! -f "Cargo.toml" ] || [ ! -d "os" ] || [ ! -d "git" ]; then
|
|
echo -e "${RED}❌ Error: This script must be run from the SAL repository root${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
# Check if cargo is available
|
|
if ! command -v cargo &> /dev/null; then
|
|
echo -e "${RED}❌ Error: cargo is not installed or not in PATH${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
# Check if user is logged in to crates.io
|
|
if [ "$DRY_RUN" = false ]; then
|
|
if ! cargo login --help &> /dev/null; then
|
|
echo -e "${RED}❌ Error: Please run 'cargo login' first${NC}"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
# Update version if specified
|
|
if [ -n "$VERSION" ]; then
|
|
echo -e "${YELLOW}📝 Updating version to $VERSION...${NC}"
|
|
|
|
# Update root Cargo.toml
|
|
sed -i.bak "s/^version = \".*\"/version = \"$VERSION\"/" Cargo.toml
|
|
|
|
# Update each crate's Cargo.toml
|
|
for crate in "${CRATES[@]}"; do
|
|
if [ -f "$crate/Cargo.toml" ]; then
|
|
sed -i.bak "s/^version = \".*\"/version = \"$VERSION\"/" "$crate/Cargo.toml"
|
|
echo " ✅ Updated $crate to version $VERSION"
|
|
fi
|
|
done
|
|
|
|
echo ""
|
|
fi
|
|
|
|
# Run tests before publishing
|
|
echo -e "${YELLOW}🧪 Running tests...${NC}"
|
|
if [ "$DRY_RUN" = false ]; then
|
|
if ! cargo test --workspace; then
|
|
echo -e "${RED}❌ Tests failed! Aborting publish.${NC}"
|
|
exit 1
|
|
fi
|
|
echo -e "${GREEN}✅ All tests passed${NC}"
|
|
else
|
|
echo -e "${YELLOW} (Skipped in dry-run mode)${NC}"
|
|
fi
|
|
echo ""
|
|
|
|
# Check for uncommitted changes
|
|
if [ "$DRY_RUN" = false ]; then
|
|
if ! git diff --quiet; then
|
|
echo -e "${YELLOW}⚠️ Warning: You have uncommitted changes${NC}"
|
|
read -p "Continue anyway? (y/N): " -n 1 -r
|
|
echo
|
|
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
|
echo -e "${RED}❌ Aborted by user${NC}"
|
|
exit 1
|
|
fi
|
|
fi
|
|
fi
|
|
|
|
# Publish individual crates
|
|
echo -e "${BLUE}📦 Publishing individual crates...${NC}"
|
|
echo ""
|
|
|
|
for crate in "${CRATES[@]}"; do
|
|
echo -e "${YELLOW}Publishing sal-$crate...${NC}"
|
|
|
|
if [ ! -d "$crate" ]; then
|
|
echo -e "${RED} ❌ Directory $crate not found${NC}"
|
|
continue
|
|
fi
|
|
|
|
cd "$crate"
|
|
|
|
if [ "$DRY_RUN" = true ]; then
|
|
echo -e "${BLUE} 🔍 Would run: cargo publish --allow-dirty${NC}"
|
|
else
|
|
if cargo publish --allow-dirty; then
|
|
echo -e "${GREEN} ✅ sal-$crate published successfully${NC}"
|
|
else
|
|
echo -e "${RED} ❌ Failed to publish sal-$crate${NC}"
|
|
cd ..
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
cd ..
|
|
|
|
if [ "$DRY_RUN" = false ] && [ "$crate" != "${CRATES[-1]}" ]; then
|
|
echo -e "${BLUE} ⏳ Waiting $WAIT_TIME seconds for crates.io to process...${NC}"
|
|
sleep "$WAIT_TIME"
|
|
fi
|
|
|
|
echo ""
|
|
done
|
|
|
|
# Publish main crate
|
|
echo -e "${BLUE}📦 Publishing main sal crate...${NC}"
|
|
|
|
if [ "$DRY_RUN" = true ]; then
|
|
echo -e "${BLUE}🔍 Would run: cargo publish --allow-dirty${NC}"
|
|
else
|
|
if cargo publish --allow-dirty; then
|
|
echo -e "${GREEN}✅ Main sal crate published successfully${NC}"
|
|
else
|
|
echo -e "${RED}❌ Failed to publish main sal crate${NC}"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
echo ""
|
|
echo -e "${GREEN}===============================================${NC}"
|
|
echo -e "${GREEN} Publishing Complete!${NC}"
|
|
echo -e "${GREEN}===============================================${NC}"
|
|
echo ""
|
|
|
|
if [ "$DRY_RUN" = true ]; then
|
|
echo -e "${YELLOW}🔍 This was a dry run. No crates were actually published.${NC}"
|
|
echo -e "${YELLOW} Run without --dry-run to publish for real.${NC}"
|
|
else
|
|
echo -e "${GREEN}🎉 All SAL crates have been published to crates.io!${NC}"
|
|
echo ""
|
|
echo "Users can now install SAL modules with:"
|
|
echo ""
|
|
echo -e "${BLUE}# Individual crates${NC}"
|
|
echo "cargo add sal-os sal-process sal-text"
|
|
echo ""
|
|
echo -e "${BLUE}# Meta-crate with features${NC}"
|
|
echo "cargo add sal --features core"
|
|
echo "cargo add sal --features all"
|
|
echo ""
|
|
echo "📚 See PUBLISHING.md for complete usage documentation."
|
|
fi
|
|
|
|
echo ""
|