OverviewFilesCommitsIssuesDocsReleasesPeers

hyper-wallet / scripts / pear-deploy.sh

154 lines · bash ref:
#!/bin/bash
# Pear Deployment Script with Testing vs Production Channels
# Usage:
#   ./scripts/pear-deploy.sh --testing "commit message"
#   ./scripts/pear-deploy.sh --production "commit message"

set -e  # Exit on error

# Deployment channel configuration
TESTING_KEY="hyper-wallet-test"
PRODUCTION_KEY="wdk-bare-wallet"
APP_DIR="/storage/projects/code/hypercore-kb/hyper-fleeky/hyper-wallet"

# Parse arguments
MODE=""
MESSAGE=""

if [ "$1" == "--testing" ] || [ "$1" == "-t" ]; then
    MODE="testing"
    MESSAGE="$2"
    PEAR_KEY="$TESTING_KEY"
    TMUX_WINDOW="pear-seed:3"  # hw-test window
elif [ "$1" == "--production" ] || [ "$1" == "-p" ]; then
    MODE="production"
    MESSAGE="$2"
    PEAR_KEY="$PRODUCTION_KEY"
    TMUX_WINDOW="pear-seed:0"  # hyper-wallet production window
else
    echo "❌ Invalid mode"
    echo ""
    echo "Usage:"
    echo "  ./scripts/pear-deploy.sh --testing \"commit message\""
    echo "  ./scripts/pear-deploy.sh --production \"commit message\""
    echo ""
    echo "Channels:"
    echo "  --testing (-t)     → $TESTING_KEY (tmux: pear-seed:3)"
    echo "  --production (-p)  → $PRODUCTION_KEY (tmux: pear-seed:0)"
    echo ""
    exit 1
fi

if [ -z "$MESSAGE" ]; then
    echo "❌ Commit message required"
    echo "Usage: ./scripts/pear-deploy.sh --$MODE \"your commit message\""
    exit 1
fi

echo "🔧 Pear Deployment Workflow"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "   Mode: $MODE"
echo "   Channel: $PEAR_KEY"
echo "   Tmux: $TMUX_WINDOW"
echo ""

# 1. Check we're in the right directory
if [ ! -f "package.json" ]; then
    echo "❌ Must run from hyper-wallet directory"
    exit 1
fi

# 2. Check for uncommitted changes
if [ -n "$(git status --porcelain)" ]; then
    echo "📝 Step 1: Git Commit"

    # Show what will be committed
    echo ""
    echo "Changes to commit:"
    git status --short
    echo ""

    # Stage all changes
    git add -A

    # Commit with co-authorship
    git commit -m "$(cat <<EOF
$MESSAGE

Deployment: $MODE ($PEAR_KEY)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
EOF
)"

    echo "✅ Committed: $MESSAGE"
else
    echo "✅ Step 1: No uncommitted changes"
fi

echo ""
echo "📦 Step 2: Pear Stage ($MODE)"
STAGE_OUTPUT=$(pear stage $PEAR_KEY . 2>&1)
echo "$STAGE_OUTPUT"

# Extract version numbers
LATEST=$(echo "$STAGE_OUTPUT" | grep "Latest:" | awk '{print $2}')
RELEASE=$(echo "$STAGE_OUTPUT" | grep "Release:" | awk '{print $2}')

# Get the actual pear:// key (only needed for testing on first run)
PEAR_HASH=$(pear info $PEAR_KEY --json 2>/dev/null | grep -oP '"key":"pear://\K[^"]+' || echo "unknown")

echo ""
echo "🚀 Step 3: Pear Release ($MODE)"
pear release $PEAR_KEY

echo ""
echo "🌱 Step 4: Update Seeder (tmux: $TMUX_WINDOW)"

# Check if tmux window exists
if tmux list-windows -t pear-seed 2>/dev/null | grep -q "^${TMUX_WINDOW##*:}:"; then
    tmux send-keys -t $TMUX_WINDOW C-c
    sleep 2

    if [ "$MODE" == "testing" ]; then
        tmux send-keys -t $TMUX_WINDOW "pear seed $PEAR_KEY ." Enter
    else
        tmux send-keys -t $TMUX_WINDOW "pear seed pear://18x3enb54ttcr6uuhg5hh1cqzwi8ydnm658fmgyyjkzoqxd1ybso ." Enter
    fi

    echo "✅ Seeder updated in $TMUX_WINDOW"
else
    echo "⚠️  Warning: tmux window $TMUX_WINDOW not found"
    echo "   You may need to start the seeder manually"
fi

echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "✅ Deployment Complete!"
echo ""
echo "📊 Summary:"
echo "   Mode: $MODE"
echo "   Channel: $PEAR_KEY"
if [ "$PEAR_HASH" != "unknown" ]; then
    echo "   Key: pear://$PEAR_HASH"
fi
echo "   Commit: $MESSAGE"
echo "   Version: $LATEST"
echo "   Seeding: $TMUX_WINDOW"
echo ""

if [ "$MODE" == "testing" ]; then
    echo "🧪 Testing Deployment - Next Steps:"
    echo "   1. Test on ashatron.local"
    echo "   2. Test all Phase 2 security features"
    echo "   3. Once verified, deploy to production:"
    echo "      ./scripts/pear-deploy.sh --production \"Phase 2 complete\""
    echo ""
else
    echo "🚀 Production Deployment - Next Steps:"
    echo "   1. Announce to users"
    echo "   2. Monitor for issues"
    echo "   3. Update documentation with new version"
    echo ""
fi