fix(ci): boot-check musl artifacts on Alpine, not the glibc runner
This commit is contained in:
1 parent
118f24e1ba
commit
c933eb39ad
3 files changed
+130
-118
No files matched your search
@@ -105,47 +105,12 @@ jobs:
|
||||
- name: Build standalone binary (musl)
|
||||
run: bash scripts/build-binary.sh --target bun-linux-x64-musl
|
||||
|
||||
- name: Boot check
|
||||
- name: Boot check (Alpine)
|
||||
# Bun's `-musl` artifact needs musl's libstdc++, which the Ubuntu runner
|
||||
# does not ship: running it here fails with unresolved C++ symbols. So the
|
||||
# musl binary is executed where it is actually meant to run.
|
||||
run: |
|
||||
sudo apt-get update -y && sudo apt-get install -y musl
|
||||
if [ ! -f /lib/ld-musl-x86_64.so.1 ]; then
|
||||
MUSL_LIB="$(find /usr/lib /lib -name 'libc.musl*' -o -name 'ld-musl*' 2>/dev/null | head -n 1)"
|
||||
if [ -n "$MUSL_LIB" ]; then
|
||||
sudo ln -s "$MUSL_LIB" /lib/ld-musl-x86_64.so.1
|
||||
fi
|
||||
fi
|
||||
|
||||
TMP="$(mktemp -d)"
|
||||
export PI2_RUNTIME_DIR="$TMP/run"
|
||||
export PI2_DATA_DIR="$TMP/data"
|
||||
export PI2_STATE_DIR="$TMP/state"
|
||||
mkdir -p "$PI2_RUNTIME_DIR" "$PI2_DATA_DIR" "$PI2_STATE_DIR"
|
||||
|
||||
dist-bin/bin/pi2 daemon --port 0 > "$TMP/daemon.log" 2>&1 &
|
||||
PID=$!
|
||||
trap 'kill -TERM "$PID" 2>/dev/null || true; rm -rf "$TMP"' EXIT
|
||||
|
||||
for _ in $(seq 1 50); do
|
||||
[ -f "$PI2_RUNTIME_DIR/daemon.json" ] && break
|
||||
kill -0 "$PID" 2>/dev/null || break
|
||||
sleep 0.1
|
||||
done
|
||||
|
||||
if [ ! -f "$PI2_RUNTIME_DIR/daemon.json" ]; then
|
||||
echo "daemon failed to start; log:" >&2
|
||||
cat "$TMP/daemon.log" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
PORT="$(node -p 'require(process.env.PI2_RUNTIME_DIR + "/daemon.json").port')"
|
||||
STATUS="$(curl -s -o /dev/null -w "%{http_code}" "http://127.0.0.1:${PORT}/api/v1/info")"
|
||||
if [ "$STATUS" != "200" ]; then
|
||||
echo "expected HTTP 200 from /api/v1/info, got $STATUS" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Standalone binary boot check passed (HTTP $STATUS on port $PORT)"
|
||||
kill -TERM "$PID" 2>/dev/null || true
|
||||
wait "$PID" 2>/dev/null || true
|
||||
trap - EXIT
|
||||
rm -rf "$TMP"
|
||||
docker run --rm \
|
||||
-v "${{ github.workspace }}/scripts:/s:ro" \
|
||||
-v "${{ github.workspace }}/dist-bin:/b:ro" \
|
||||
alpine:3.20 sh -c 'apk add --no-cache libstdc++ curl >/dev/null 2>&1 && sh /s/boot-check.sh /b/bin/pi2'
|
||||
@@ -176,82 +176,20 @@ jobs:
|
||||
- name: Build binary tarball
|
||||
run: bash scripts/build-binary.sh --target ${{ matrix.target }}
|
||||
|
||||
- name: Boot check
|
||||
- name: Boot check (host-native)
|
||||
if: ${{ !contains(matrix.target, 'musl') }}
|
||||
run: sh scripts/boot-check.sh dist-bin/bin/pi2 "${GITHUB_REF_NAME#v}"
|
||||
|
||||
- name: Boot check (Alpine, musl artifact)
|
||||
# Bun's musl binaries link against musl's libstdc++; the glibc runner
|
||||
# cannot load them ("symbol not found" for std:: symbols), so musl
|
||||
# artifacts are executed on the libc they are built for.
|
||||
if: ${{ contains(matrix.target, 'musl') }}
|
||||
run: |
|
||||
case "${{ matrix.target }}" in
|
||||
*musl*)
|
||||
ARCH="$(uname -m)"
|
||||
[ "$ARCH" = "arm64" ] && ARCH="aarch64"
|
||||
LOADER="/lib/ld-musl-${ARCH}.so.1"
|
||||
if [ ! -f "$LOADER" ]; then
|
||||
sudo apt-get update -y && sudo apt-get install -y musl
|
||||
if [ ! -f "$LOADER" ]; then
|
||||
MUSL_LIB="$(find /usr/lib /lib -name 'libc.musl*' -o -name 'ld-musl*' 2>/dev/null | head -n 1)"
|
||||
if [ -n "$MUSL_LIB" ]; then
|
||||
sudo ln -s "$MUSL_LIB" "$LOADER"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
TMP="$(mktemp -d)"
|
||||
export PI2_RUNTIME_DIR="$TMP/run"
|
||||
export PI2_DATA_DIR="$TMP/data"
|
||||
export PI2_STATE_DIR="$TMP/state"
|
||||
mkdir -p "$PI2_RUNTIME_DIR" "$PI2_DATA_DIR" "$PI2_STATE_DIR"
|
||||
|
||||
dist-bin/bin/pi2 daemon --port 0 > "$TMP/stdout.log" 2> "$TMP/daemon.log" &
|
||||
PID=$!
|
||||
trap 'kill -TERM "$PID" 2>/dev/null || true; rm -rf "$TMP"' EXIT
|
||||
|
||||
for _ in $(seq 1 100); do
|
||||
if grep -q "listening on http://" "$TMP/stdout.log" 2>/dev/null; then
|
||||
break
|
||||
fi
|
||||
kill -0 "$PID" 2>/dev/null || break
|
||||
sleep 0.1
|
||||
done
|
||||
|
||||
if ! grep -q "listening on http://" "$TMP/stdout.log" 2>/dev/null; then
|
||||
echo "daemon failed to start or emit listening line; stdout:" >&2
|
||||
cat "$TMP/stdout.log" >&2 || true
|
||||
echo "daemon stderr:" >&2
|
||||
cat "$TMP/daemon.log" >&2 || true
|
||||
exit 1
|
||||
fi
|
||||
|
||||
URL="$(grep -o 'http://[^ ]*' "$TMP/stdout.log" | head -n 1)"
|
||||
INFO="$(curl -fsS "$URL/api/v1/info")"
|
||||
|
||||
tag="${GITHUB_REF_NAME#v}"
|
||||
node -e '
|
||||
const info = JSON.parse(process.argv[1]);
|
||||
const tag = process.argv[2];
|
||||
const ref = process.argv[3];
|
||||
if (info.v !== 1) {
|
||||
console.error(`expected v: 1, got ${info.v}`);
|
||||
process.exit(1);
|
||||
}
|
||||
if (info.version !== tag && info.version !== ref) {
|
||||
console.error(`expected version ${tag} (or ${ref}), got ${info.version}`);
|
||||
process.exit(1);
|
||||
}
|
||||
console.log(`Boot check ok: v=${info.v}, version=${info.version}`);
|
||||
' "$INFO" "$tag" "$GITHUB_REF_NAME"
|
||||
|
||||
kill -TERM "$PID"
|
||||
set +e
|
||||
wait "$PID"
|
||||
EXIT_CODE=$?
|
||||
set -e
|
||||
trap - EXIT
|
||||
rm -rf "$TMP"
|
||||
|
||||
if [ "$EXIT_CODE" -ne 0 ]; then
|
||||
echo "daemon exited with code $EXIT_CODE on SIGTERM (expected 0)" >&2
|
||||
exit 1
|
||||
fi
|
||||
docker run --rm \
|
||||
-v "${{ github.workspace }}/scripts:/s:ro" \
|
||||
-v "${{ github.workspace }}/dist-bin:/b:ro" \
|
||||
alpine:3.20 sh -c 'apk add --no-cache libstdc++ curl >/dev/null 2>&1 && sh /s/boot-check.sh /b/bin/pi2 "${GITHUB_REF_NAME#v}"'
|
||||
|
||||
- name: Upload binary tarball artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
|
||||
Executable
+109
@@ -0,0 +1,109 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Boot check for a built `pi2` artifact.
|
||||
#
|
||||
# sh scripts/boot-check.sh <path-to-pi2> [expected-version]
|
||||
#
|
||||
# Starts the daemon on an ephemeral port with throwaway runtime/data/state
|
||||
# directories, waits for the single stdout line, asserts `/api/v1/info` answers
|
||||
# with protocol v1 (and the expected version), then sends SIGTERM and requires a
|
||||
# clean exit 0.
|
||||
#
|
||||
# POSIX `sh` on purpose: this script also runs inside an Alpine container, where
|
||||
# it validates the `-musl` artifacts (Bun's musl binaries need musl's libstdc++,
|
||||
# which the Ubuntu runners do not have, so they must be executed on Alpine).
|
||||
# Only `curl` and a shell are required; no `jq`, no Node, no Python.
|
||||
set -eu
|
||||
|
||||
BIN="${1:-}"
|
||||
EXPECTED_VERSION="${2:-}"
|
||||
|
||||
if [ -z "$BIN" ] || [ ! -x "$BIN" ]; then
|
||||
echo "usage: boot-check.sh <path-to-pi2> [expected-version]" >&2
|
||||
echo " (missing or not executable: '${BIN}')" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
pass() {
|
||||
printf 'PASS %s\n' "$1"
|
||||
}
|
||||
|
||||
TMP="$(mktemp -d "${TMPDIR:-/tmp}/pi2-boot.XXXXXX")"
|
||||
PID=""
|
||||
cleanup() {
|
||||
if [ -n "$PID" ] && kill -0 "$PID" 2>/dev/null; then
|
||||
kill -TERM "$PID" 2>/dev/null || true
|
||||
wait "$PID" 2>/dev/null || true
|
||||
fi
|
||||
rm -rf "$TMP"
|
||||
}
|
||||
trap cleanup EXIT INT TERM
|
||||
|
||||
PI2_RUNTIME_DIR="$TMP/run"
|
||||
PI2_DATA_DIR="$TMP/data"
|
||||
PI2_STATE_DIR="$TMP/state"
|
||||
export PI2_RUNTIME_DIR PI2_DATA_DIR PI2_STATE_DIR
|
||||
mkdir -p "$PI2_RUNTIME_DIR" "$PI2_DATA_DIR" "$PI2_STATE_DIR"
|
||||
|
||||
"$BIN" daemon --port 0 >"$TMP/stdout.log" 2>"$TMP/daemon.log" &
|
||||
PID=$!
|
||||
|
||||
i=0
|
||||
while [ "$i" -lt 200 ]; do
|
||||
if grep -q "listening on http://" "$TMP/stdout.log" 2>/dev/null; then
|
||||
break
|
||||
fi
|
||||
kill -0 "$PID" 2>/dev/null || break
|
||||
i=$((i + 1))
|
||||
sleep 0.1
|
||||
done
|
||||
|
||||
if ! grep -q "listening on http://" "$TMP/stdout.log" 2>/dev/null; then
|
||||
echo "FAIL daemon did not reach 'listening on http://'" >&2
|
||||
echo "--- stdout ---" >&2
|
||||
cat "$TMP/stdout.log" >&2 || true
|
||||
echo "--- stderr ---" >&2
|
||||
cat "$TMP/daemon.log" >&2 || true
|
||||
exit 1
|
||||
fi
|
||||
pass "daemon started and printed one listening line"
|
||||
|
||||
PORT="$(sed -n 's/.*"port": *\([0-9][0-9]*\).*/\1/p' "$PI2_RUNTIME_DIR/daemon.json" | head -n 1)"
|
||||
if [ -z "${PORT:-}" ]; then
|
||||
echo "FAIL could not read the bound port from daemon.json" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
INFO="$(curl -fsS "http://127.0.0.1:$PORT/api/v1/info")" || {
|
||||
echo "FAIL GET /api/v1/info did not answer" >&2
|
||||
exit 1
|
||||
}
|
||||
case "$INFO" in
|
||||
*'"v":1'*) pass "GET /api/v1/info reports protocol v1" ;;
|
||||
*)
|
||||
echo "FAIL /api/v1/info does not report \"v\":1: $INFO" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -n "$EXPECTED_VERSION" ]; then
|
||||
case "$INFO" in
|
||||
*"\"version\":\"$EXPECTED_VERSION\""*) pass "reported version is $EXPECTED_VERSION" ;;
|
||||
*)
|
||||
echo "FAIL expected version $EXPECTED_VERSION in: $INFO" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
kill -TERM "$PID" 2>/dev/null || true
|
||||
set +e
|
||||
wait "$PID" 2>/dev/null
|
||||
EXIT_CODE=$?
|
||||
set -e
|
||||
PID=""
|
||||
if [ "$EXIT_CODE" -ne 0 ]; then
|
||||
echo "FAIL daemon exited $EXIT_CODE after SIGTERM (expected 0)" >&2
|
||||
exit 1
|
||||
fi
|
||||
pass "SIGTERM -> clean exit 0"
|
||||
Reference in new issue
Block a user