ziex/pkg/check.sh
2026-03-30 00:02:29 +06:00

120 lines
3.4 KiB
Bash
Executable File

#!/bin/bash
set -euo pipefail
# Smoke-tests @ziex/cli and ziex packages by publishing to a local
# Verdaccio registry and verifying that the CLI binary works.
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
ROOT_DIR="$SCRIPT_DIR/.."
VERDACCIO_DIR="$SCRIPT_DIR/@ziex"
REGISTRY="http://localhost:4873"
PASSED=0
FAILED=0
VERSION="${1:-}"
cleanup() {
if [ -n "${VERDACCIO_PID:-}" ]; then
kill "$VERDACCIO_PID" 2>/dev/null || true
wait "$VERDACCIO_PID" 2>/dev/null || true
fi
rm -rf "$SCRIPT_DIR/_check_tmp" "$SCRIPT_DIR/_check_npmrc" "$SCRIPT_DIR/ziex/.npmrc" "$SCRIPT_DIR/ziex/bunfig.toml"
}
trap cleanup EXIT
# Resolve expected version
if [ -z "$VERSION" ]; then
VERSION=$(sed -n 's/.*\.version *= *"\([^"]*\)".*/\1/p' "$ROOT_DIR/build.zig.zon")
fi
echo "==> Checking packages at version $VERSION"
# Use a clean .npmrc scoped to this script so CI's global auth config
# (written by setup-node) doesn't interfere with local Verdaccio.
export npm_config_userconfig="$SCRIPT_DIR/_check_npmrc"
cat > "$npm_config_userconfig" <<EOF
@ziex:registry=$REGISTRY
//localhost:4873/:_authToken=local-dev-token
EOF
# Start Verdaccio only if not running in CI
if [ -z "${CI:-}" ]; then
echo "==> Starting local registry..."
rm -rf "$VERDACCIO_DIR/.verdaccio-storage"
npx --yes verdaccio --config "$VERDACCIO_DIR/verdaccio.yaml" --listen 4873 &
VERDACCIO_PID=$!
# Wait for Verdaccio to be ready (up to 60s; npx may need time to install verdaccio)
for i in $(seq 1 120); do
if curl -sf "$REGISTRY/-/ping" > /dev/null 2>&1; then break; fi
sleep 0.5
done
else
echo "==> Skipping Verdaccio startup in CI"
fi
# Publish @ziex/cli* packages to local registry
echo "==> Publishing @ziex/cli* to local registry..."
cd "$VERDACCIO_DIR"
npm publish --workspaces --access public --tag dev --registry "$REGISTRY" 2>&1
# Build and publish ziex to local registry
echo "==> Building and publishing ziex to local registry..."
cd "$SCRIPT_DIR/ziex"
cat > bunfig.toml <<BUNEOF
[install.scopes]
"@ziex" = { url = "$REGISTRY" }
BUNEOF
npm_config_userconfig="" bun install
bun run build
cd dist
npm publish --access public --tag dev --registry "$REGISTRY" 2>&1
# Create temp directory for testing
mkdir -p "$SCRIPT_DIR/_check_tmp"
cd "$SCRIPT_DIR/_check_tmp"
pass() { PASSED=$((PASSED + 1)); echo " PASS: $1"; }
fail() { FAILED=$((FAILED + 1)); echo " FAIL: $1"; }
# --- Tests ---
echo ""
echo "==> Running checks..."
# Check @ziex/cli version command
echo ""
echo "--- @ziex/cli ---"
CLI_OUTPUT=$(npx --yes --registry "$REGISTRY" @ziex/cli@dev version 2>&1) || true
if echo "$CLI_OUTPUT" | grep -q "$VERSION"; then
pass "@ziex/cli version outputs $VERSION"
else
fail "@ziex/cli version expected '$VERSION', got: $CLI_OUTPUT"
fi
# Check ziex version command (delegates to @ziex/cli)
echo ""
echo "--- ziex ---"
ZIEX_OUTPUT=$(npx --yes --registry "$REGISTRY" ziex@dev version 2>&1) || true
if echo "$ZIEX_OUTPUT" | grep -q "$VERSION"; then
pass "ziex version outputs $VERSION"
else
fail "ziex version expected '$VERSION', got: $ZIEX_OUTPUT"
fi
# Check that ziex resolves @ziex/cli as dependency
ZIEX_HELP=$(npx --yes --registry "$REGISTRY" ziex@dev --help 2>&1) || true
if [ -n "$ZIEX_HELP" ]; then
pass "ziex --help produces output"
else
fail "ziex --help produced no output"
fi
# --- Summary ---
echo ""
echo "==========================="
echo " Results: $PASSED passed, $FAILED failed"
echo "==========================="
if [ "$FAILED" -gt 0 ]; then
exit 1
fi