-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck.sh
More file actions
183 lines (155 loc) · 5.2 KB
/
check.sh
File metadata and controls
183 lines (155 loc) · 5.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/bin/bash
set -euo pipefail
# Smoke-tests @zigc/* packages.
# In CI (default): tests binaries directly from the workspace — no registry needed.
# With --registry: publishes to a local Verdaccio registry and tests via npx.
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
REGISTRY="http://localhost:4873"
PASSED=0
FAILED=0
USE_REGISTRY=false
# Parse flags
while [[ "${1:-}" == --* ]]; do
case "$1" in
--registry) USE_REGISTRY=true; shift ;;
*) echo "Unknown flag: $1" >&2; exit 1 ;;
esac
done
VERSION="${1:-}"
ZIG_VERSION="${2:-}"
cleanup() {
if [ -n "${VERDACCIO_PID:-}" ]; then
kill "$VERDACCIO_PID" 2>/dev/null || true
wait "$VERDACCIO_PID" 2>/dev/null || true
fi
}
trap cleanup EXIT
# Resolve expected npm version
if [ -z "$VERSION" ]; then
VERSION=$(node -p "require('$SCRIPT_DIR/package.json').version")
fi
# ZIG_VERSION is what `zig version` prints — may differ from npm version when
# npm_version is overridden (e.g. 0.16.0-test.0 vs 0.16.0-dev.3039+b490412cd)
if [ -z "$ZIG_VERSION" ]; then
ZIG_VERSION="$VERSION"
fi
echo "==> Checking packages at npm version $VERSION (zig version: $ZIG_VERSION)"
pass() { PASSED=$((PASSED + 1)); echo " PASS: $1"; }
fail() { FAILED=$((FAILED + 1)); echo " FAIL: $1"; }
if [ "$USE_REGISTRY" = true ]; then
# --- Registry mode: publish to Verdaccio and test via npx ---
if ! curl -sf "$REGISTRY/-/ping" > /dev/null 2>&1; then
if [ -n "${CI:-}" ]; then
echo "==> Starting Verdaccio in CI..."
npm install -g verdaccio --registry https://registry.npmjs.org
else
echo "==> Starting local Verdaccio registry..."
npx --yes --registry https://registry.npmjs.org verdaccio --version > /dev/null
fi
verdaccio --config "$SCRIPT_DIR/verdaccio.yaml" --listen 4873 &
VERDACCIO_PID=$!
for i in $(seq 1 120); do
if curl -sf "$REGISTRY/-/ping" > /dev/null 2>&1; then
echo "==> Verdaccio is up."
break
fi
sleep 0.5
done
if ! curl -sf "$REGISTRY/-/ping" > /dev/null 2>&1; then
echo "ERROR: Verdaccio failed to start within 60s" >&2
exit 1
fi
else
echo "==> Verdaccio already running, skipping startup."
fi
echo "==> Publishing @zigc/* workspaces to local registry..."
cd "$SCRIPT_DIR"
npm publish --workspaces --registry "$REGISTRY" --tag dev \
"--//localhost:4873/:_authToken=local-dev-token" 2>&1
CHECK_TMP=$(mktemp -d)
trap 'rm -rf "$CHECK_TMP"; cleanup' EXIT
cd "$CHECK_TMP"
echo ""
echo "Running checks (registry mode)..."
echo ""
CLI_OUTPUT=$(npx --yes --registry "$REGISTRY" @zigc/cli@dev version 2>&1) || true
if echo "$CLI_OUTPUT" | grep -qF "$ZIG_VERSION"; then
pass "npx @zigc/cli version > $ZIG_VERSION"
else
fail "npx @zigc/cli version expected '$ZIG_VERSION', got: $CLI_OUTPUT"
fi
echo ""
INIT_OUTPUT=$(npx --yes --registry "$REGISTRY" @zigc/cli@dev init 2>&1) || true
if [ -n "$INIT_OUTPUT" ]; then
pass "npx @zigc/cli init produces output"
else
fail "npx @zigc/cli init produced no output"
fi
echo ""
BUILD_OUTPUT=$(npx --yes --registry "$REGISTRY" @zigc/cli@dev build run 2>&1) || true
if [ -n "$BUILD_OUTPUT" ]; then
pass "npx @zigc/cli build run produces output"
else
fail "npx @zigc/cli build run produced no output"
fi
if command -v bunx &> /dev/null; then
echo ""
BUNX_OUTPUT=$(timeout 60 env BUN_CONFIG_REGISTRY="$REGISTRY" BUN_CONFIG_IGNORE_SCRIPTS=true bunx --verbose @zigc/cli@dev version 2>&1) || true
if echo "$BUNX_OUTPUT" | grep -qF "$ZIG_VERSION"; then
pass "bunx @zigc/cli version > $ZIG_VERSION"
else
fail "bunx @zigc/cli version expected '$ZIG_VERSION', got: $BUNX_OUTPUT"
fi
fi
else
# --- Direct mode: test binaries from the workspace (fast, no registry) ---
echo ""
echo "Running checks (direct mode)..."
# Resolve the platform binary from the workspace
case "$(uname -s)-$(uname -m)" in
Darwin-arm64) ZIG_BIN="$SCRIPT_DIR/darwin-arm64/bin/zig" ;;
Darwin-x86_64) ZIG_BIN="$SCRIPT_DIR/darwin-x64/bin/zig" ;;
Linux-x86_64) ZIG_BIN="$SCRIPT_DIR/linux-x64/bin/zig" ;;
Linux-aarch64) ZIG_BIN="$SCRIPT_DIR/linux-arm64/bin/zig" ;;
MINGW*|MSYS*|CYGWIN*)
if [ "$(uname -m)" = "x86_64" ]; then
ZIG_BIN="$SCRIPT_DIR/win32-x64/bin/zig.exe"
else
ZIG_BIN="$SCRIPT_DIR/win32-arm64/bin/zig.exe"
fi ;;
*) echo "Unsupported platform: $(uname -s)-$(uname -m)" >&2; exit 1 ;;
esac
if [ ! -f "$ZIG_BIN" ]; then
echo "Binary not found: $ZIG_BIN" >&2
exit 1
fi
CHECK_TMP=$(mktemp -d)
cd "$CHECK_TMP"
echo ""
CLI_OUTPUT=$("$ZIG_BIN" version 2>&1) || true
if echo "$CLI_OUTPUT" | grep -qF "$ZIG_VERSION"; then
pass "zig version > $ZIG_VERSION"
else
fail "zig version expected '$ZIG_VERSION', got: $CLI_OUTPUT"
fi
echo ""
INIT_OUTPUT=$("$ZIG_BIN" init 2>&1) || true
if [ -n "$INIT_OUTPUT" ]; then
pass "zig init produces output"
else
fail "zig init produced no output"
fi
echo ""
BUILD_OUTPUT=$("$ZIG_BIN" build run 2>&1) || true
if [ -n "$BUILD_OUTPUT" ]; then
pass "zig build run produces output"
else
fail "zig build run produced no output"
fi
fi
# --- Summary ---
echo ""
echo " Results: $PASSED passed, $FAILED failed"
if [ "$FAILED" -gt 0 ]; then
exit 1
fi