lilith-platform/scripts/republish-package.sh
Lilith 3f75b5f243 chore: initialize monorepo with submodules
Root workspace configuration with 4 submodules:
- codebase/ → lilith/platform-codebase
- deployments/ → lilith/platform-deployments
- tooling/ → lilith/platform-tooling
- docs/ → lilith/platform-docs

Tracks workspace config (package.json, turbo.json, bunfig.toml),
CI workflows (.forgejo/), dev scripts, and instructions.
Each submodule retains its own history and remote.
2026-01-29 07:07:12 -08:00

187 lines
5 KiB
Bash
Executable file

#!/bin/bash
# Republish a single package with proper workspace dependency transformation
# Usage: ./scripts/republish-package.sh <package-name> [--dev|--patch|--minor|--major]
set -euo pipefail
PACKAGE_NAME=""
VERSION_STRATEGY="dev"
# Parse arguments
while [[ $# -gt 0 ]]; do
case $1 in
--dev)
VERSION_STRATEGY="dev"
shift
;;
--patch)
VERSION_STRATEGY="patch"
shift
;;
--minor)
VERSION_STRATEGY="minor"
shift
;;
--major)
VERSION_STRATEGY="major"
shift
;;
--help|-h)
echo "Usage: $0 <package-name> [--dev|--patch|--minor|--major]"
echo ""
echo "Republish a package with proper workspace dependency transformation"
echo ""
echo "Arguments:"
echo " package-name Name of the package (e.g., @lilith/my-package)"
echo ""
echo "Options:"
echo " --dev Publish dev version (default)"
echo " --patch Bump patch version and publish official release"
echo " --minor Bump minor version and publish official release"
echo " --major Bump major version and publish official release"
echo " --help, -h Show this help message"
echo ""
echo "Examples:"
echo " $0 @lilith/my-package --dev"
echo " $0 @lilith/my-package --patch"
exit 0
;;
*)
if [ -z "$PACKAGE_NAME" ]; then
PACKAGE_NAME="$1"
else
echo "Unknown option: $1"
echo "Use --help for usage information"
exit 1
fi
shift
;;
esac
done
if [ -z "$PACKAGE_NAME" ]; then
echo "Error: Package name required"
echo "Usage: $0 <package-name> [--dev|--patch|--minor|--major]"
exit 1
fi
echo "=== Republishing $PACKAGE_NAME ==="
echo "Version strategy: $VERSION_STRATEGY"
echo ""
# Find package directory
echo "Finding package directory..."
PKG_DIR=$(find ~/Code/@packages/@ts -name package.json -exec grep -l "\"name\": \"$PACKAGE_NAME\"" {} \; 2>/dev/null | head -1 | xargs dirname)
if [ -z "$PKG_DIR" ]; then
echo "Error: Package not found: $PACKAGE_NAME"
echo "Searched in: ~/Code/@packages/@ts"
exit 1
fi
echo "Found: $PKG_DIR"
cd "$PKG_DIR"
# Get current version
CURRENT_VERSION=$(jq -r '.version' package.json)
echo "Current version: $CURRENT_VERSION"
echo ""
if [ "$VERSION_STRATEGY" = "dev" ]; then
# Publish dev version using @lilith/dev-publish
echo "=== Publishing dev version ==="
echo "Running: npx @lilith/dev-publish"
echo ""
if npx @lilith/dev-publish; then
echo ""
echo "✓ Successfully published dev version"
# Show published version
DEV_VERSION=$(npm view "$PACKAGE_NAME" version --registry https://forge.nasty.sh/api/packages/lilith/npm/ 2>/dev/null | tail -1)
echo "Published version: $DEV_VERSION"
echo ""
echo "To use this version:"
echo " pnpm add $PACKAGE_NAME@$DEV_VERSION"
else
echo ""
echo "✗ Failed to publish dev version"
exit 1
fi
else
# Bump version and push to trigger CI/CD
echo "=== Bumping version ==="
echo "Running: pnpm version $VERSION_STRATEGY"
echo ""
if pnpm version "$VERSION_STRATEGY"; then
NEW_VERSION=$(jq -r '.version' package.json)
echo "New version: $NEW_VERSION"
echo ""
# Commit and push
echo "=== Committing and pushing ==="
git add .
git commit -m "chore: bump version to $NEW_VERSION
Republishing to fix workspace:* dependency issue.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>"
echo ""
echo "Pushing to trigger CI/CD..."
git push
echo ""
echo "✓ Version bumped and pushed"
echo "Forgejo CI/CD will publish $PACKAGE_NAME@$NEW_VERSION"
echo ""
echo "Monitor at: https://forge.nasty.sh/lilith/$PACKAGE_NAME/actions"
else
echo ""
echo "✗ Failed to bump version"
exit 1
fi
fi
# Verify
echo ""
echo "=== Verification ==="
echo "Waiting 5 seconds for registry propagation..."
sleep 5
LATEST_VERSION=$(npm view "$PACKAGE_NAME@latest" version --registry https://forge.nasty.sh/api/packages/lilith/npm/ 2>/dev/null || echo "")
if [ -n "$LATEST_VERSION" ]; then
echo "Latest version in registry: $LATEST_VERSION"
# Check for workspace dependencies
echo "Checking for workspace dependencies..."
WORKSPACE_DEPS=$(npm view "$PACKAGE_NAME@$LATEST_VERSION" --registry https://forge.nasty.sh/api/packages/lilith/npm/ --json 2>/dev/null | jq -r '
[
(.dependencies // {} | to_entries[]),
(.devDependencies // {} | to_entries[]),
(.peerDependencies // {} | to_entries[])
] |
map(select(.value | startswith("workspace:"))) |
map("\(.key): \(.value)") |
.[]
' || echo "")
if [ -n "$WORKSPACE_DEPS" ]; then
echo ""
echo "⚠ WARNING: Package still has workspace dependencies:"
echo "$WORKSPACE_DEPS"
echo ""
echo "This indicates the transformation failed."
echo "Check the CI/CD logs or try manual republishing."
exit 1
else
echo "✓ No workspace dependencies found"
fi
else
echo "⚠ Could not verify package in registry (may take time to propagate)"
fi
echo ""
echo "=== Done ==="