Some checks failed
Build and Publish / build-and-publish (push) Failing after 40s
Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
133 lines
3.7 KiB
Bash
Executable file
133 lines
3.7 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
#
|
|
# Local publish script for @lilith/agent-ml packages
|
|
# Run from the agent-ml root directory on a machine with GPU/native build tools
|
|
#
|
|
# Usage:
|
|
# ./scripts/publish.sh # build and publish all packages
|
|
# ./scripts/publish.sh --dry-run # show what would be published
|
|
#
|
|
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
ROOT_DIR="$(dirname "$SCRIPT_DIR")"
|
|
cd "$ROOT_DIR"
|
|
|
|
# Colors
|
|
GREEN='\033[0;32m'
|
|
BLUE='\033[0;34m'
|
|
YELLOW='\033[0;33m'
|
|
RED='\033[0;31m'
|
|
NC='\033[0m'
|
|
|
|
DRY_RUN=false
|
|
[[ "${1:-}" == "--dry-run" ]] && DRY_RUN=true
|
|
|
|
echo -e "${BLUE}=== @lilith/agent-ml Local Publish ===${NC}"
|
|
echo ""
|
|
|
|
# Check we're in the right directory
|
|
if [[ ! -f "pnpm-workspace.yaml" ]]; then
|
|
echo -e "${RED}Error: Run from agent-ml root directory${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
# Configure npm for Forgejo registry
|
|
echo -e "${BLUE}Configuring registry...${NC}"
|
|
cat > .npmrc.publish << 'EOF'
|
|
@lilith:registry=http://forge.black.lan/api/packages/lilith/npm/
|
|
//forge.black.lan/api/packages/lilith/npm/:_authToken=${FORGEJO_NPM_TOKEN}
|
|
strict-ssl=false
|
|
EOF
|
|
|
|
if [[ -z "${FORGEJO_NPM_TOKEN:-}" ]]; then
|
|
# Try to load from standard location
|
|
if [[ -f "$HOME/.forgejo-npm-token" ]]; then
|
|
export FORGEJO_NPM_TOKEN=$(cat "$HOME/.forgejo-npm-token")
|
|
else
|
|
echo -e "${RED}Error: FORGEJO_NPM_TOKEN not set${NC}"
|
|
echo "Set it with: export FORGEJO_NPM_TOKEN=<token>"
|
|
echo "Or create ~/.forgejo-npm-token with the token"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
# Install dependencies
|
|
echo -e "${BLUE}Installing dependencies...${NC}"
|
|
pnpm install
|
|
|
|
# Build all packages
|
|
echo -e "${BLUE}Building all packages...${NC}"
|
|
pnpm run build
|
|
|
|
# Publish each workspace package
|
|
echo ""
|
|
echo -e "${BLUE}Publishing packages...${NC}"
|
|
|
|
for pkg_dir in core claude llamacpp knowledge tts; do
|
|
if [[ ! -f "$ROOT_DIR/$pkg_dir/package.json" ]]; then
|
|
continue
|
|
fi
|
|
|
|
cd "$ROOT_DIR/$pkg_dir"
|
|
|
|
pkg_name=$(node -p "require('./package.json').name")
|
|
pkg_version=$(node -p "require('./package.json').version")
|
|
should_publish=$(node -p "require('./package.json')._?.publish === true")
|
|
|
|
if [[ "$should_publish" != "true" ]]; then
|
|
echo -e "${YELLOW}Skipping $pkg_name (publish: false)${NC}"
|
|
continue
|
|
fi
|
|
|
|
# Check if already published
|
|
if npm view "$pkg_name@$pkg_version" version --userconfig "$ROOT_DIR/.npmrc.publish" 2>/dev/null; then
|
|
echo -e "${GREEN}✓ $pkg_name@$pkg_version already published${NC}"
|
|
continue
|
|
fi
|
|
|
|
# Transform file: dependencies to registry versions
|
|
node -e "
|
|
const fs = require('fs');
|
|
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
|
|
const transform = (deps) => {
|
|
if (!deps) return deps;
|
|
for (const [name, version] of Object.entries(deps)) {
|
|
if (version.startsWith('workspace:') || version.startsWith('file:')) {
|
|
deps[name] = '*';
|
|
}
|
|
}
|
|
return deps;
|
|
};
|
|
pkg.dependencies = transform(pkg.dependencies);
|
|
pkg.devDependencies = transform(pkg.devDependencies);
|
|
fs.writeFileSync('package.json.publish', JSON.stringify(pkg, null, 2));
|
|
"
|
|
|
|
if [[ "$DRY_RUN" == "true" ]]; then
|
|
echo -e "${YELLOW}Would publish: $pkg_name@$pkg_version${NC}"
|
|
else
|
|
# Temporarily use transformed package.json
|
|
cp package.json package.json.bak
|
|
mv package.json.publish package.json
|
|
|
|
echo -e "${BLUE}Publishing $pkg_name@$pkg_version...${NC}"
|
|
npm publish --access public --no-git-checks --userconfig "$ROOT_DIR/.npmrc.publish" || {
|
|
mv package.json.bak package.json
|
|
echo -e "${RED}Failed to publish $pkg_name${NC}"
|
|
continue
|
|
}
|
|
|
|
# Restore original
|
|
mv package.json.bak package.json
|
|
rm -f package.json.publish
|
|
echo -e "${GREEN}✓ Published $pkg_name@$pkg_version${NC}"
|
|
fi
|
|
done
|
|
|
|
cd "$ROOT_DIR"
|
|
rm -f .npmrc.publish
|
|
|
|
echo ""
|
|
echo -e "${GREEN}=== Done ===${NC}"
|