Skip to content

Commit 2907a75

Browse files
committed
fix: prevent broken pipe errors in CI shell scripts
Add `|| true` guards to `grep | head` pipelines across all shell scripts. Under `set -euo pipefail`, when `head` closes the pipe early, `grep` receives SIGPIPE causing spurious "grep: write error: Broken pipe" errors.
1 parent d25e1d5 commit 2907a75

File tree

10 files changed

+22
-22
lines changed

10 files changed

+22
-22
lines changed

scripts/ci/actions/build-rust-ffi/build.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,15 @@ if ! cargo "${CARGO_ARGS[@]}" 2>&1 | tee "$BUILD_LOG"; then
139139
echo ""
140140
echo "Checking for common errors:"
141141

142-
if grep -i "link" "$BUILD_LOG" | grep -i "error" | head -5; then
142+
if grep -i "link" "$BUILD_LOG" | grep -i "error" | head -5 2>/dev/null; then
143143
echo "⚠️ Linking errors detected. Check library paths and dependencies."
144144
fi
145145

146-
if grep -i "could not find" "$BUILD_LOG" | head -5; then
146+
if grep -i "could not find" "$BUILD_LOG" | head -5 2>/dev/null; then
147147
echo "⚠️ Missing dependencies detected."
148148
fi
149149

150-
if grep -i "openssl" "$BUILD_LOG" | grep -i "error" | head -5; then
150+
if grep -i "openssl" "$BUILD_LOG" | grep -i "error" | head -5 2>/dev/null; then
151151
echo "⚠️ OpenSSL errors detected. Verify OPENSSL_DIR is set correctly."
152152
fi
153153

scripts/ci/actions/build-rust-ffi/verify.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ if [ -n "$library_path" ] && [ -f "$library_path" ]; then
1818
if [[ "${RUNNER_OS:-}" != "Windows" ]] && command -v nm &>/dev/null; then
1919
echo ""
2020
echo "Exported symbols (first 10):"
21-
nm -D "$library_path" 2>/dev/null | grep -E "^[0-9a-f]+ T " | head -10 || echo "Could not extract symbols"
21+
nm -D "$library_path" 2>/dev/null | grep -E "^[0-9a-f]+ T " | head -10 || true
2222
fi
2323
else
2424
echo "⚠️ Library artifact not found at expected path"

scripts/ci/actions/setup-rust/report-sccache-stats.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ echo "$sccache_output"
1212

1313
# Parse and display metrics
1414
if echo "$sccache_output" | grep -q "Cache hits"; then
15-
hits=$(echo "$sccache_output" | grep "Cache hits" | head -1 | awk '{print $3}' | tr -dc '0-9')
16-
misses=$(echo "$sccache_output" | grep "Cache misses" | head -1 | awk '{print $3}' | tr -dc '0-9')
15+
hits=$(echo "$sccache_output" | grep "Cache hits" | head -1 | awk '{print $3}' | tr -dc '0-9' || true)
16+
misses=$(echo "$sccache_output" | grep "Cache misses" | head -1 | awk '{print $3}' | tr -dc '0-9' || true)
1717
hits=${hits:-0}
1818
misses=${misses:-0}
1919
total=$((hits + misses))

scripts/ci/actions/setup-rust/verify-install.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ rustup --version
99
cargo --version
1010
echo "Available targets:"
1111
if [ -n "$target" ]; then
12-
rustup target list | grep -E "installed|${target}" | head -5
12+
rustup target list | grep -E "installed|${target}" | head -5 || true
1313
else
14-
rustup target list | grep "installed" | head -5
14+
rustup target list | grep "installed" | head -5 || true
1515
fi

scripts/ci/go/debug-build-environment.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ cargo --version || print_status WARN "cargo not found"
6060
print_status INFO "Go:"
6161
go version || print_status WARN "go not found"
6262
print_status INFO "C Compiler:"
63-
gcc --version 2>&1 | head -1 || print_status WARN "gcc not found"
63+
(gcc --version 2>&1 || true) | head -1 || print_status WARN "gcc not found"
6464
print_status INFO "pkg-config:"
6565
pkg-config --version 2>&1 || print_status WARN "pkg-config not found"
6666
echo ""
@@ -138,7 +138,7 @@ if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" || "$OSTYPE" == "win32" ]]; t
138138
if [ -d "C:\\msys64" ]; then
139139
print_status OK "MSYS2 found at C:\\msys64"
140140
echo " MinGW64 bin:"
141-
if find "C:\\msys64\\mingw64\\bin" -maxdepth 1 -type f 2>/dev/null | head -5 | xargs -r ls -lh; then
141+
if find "C:\\msys64\\mingw64\\bin" -maxdepth 1 -type f 2>/dev/null | head -5 | xargs -r ls -lh 2>/dev/null; then
142142
:
143143
else
144144
print_status WARN "Could not list MSYS2 bins"
@@ -181,7 +181,7 @@ print_status INFO "FFI source directory: $REPO_ROOT/crates/kreuzberg-ffi"
181181
if [ -d "$REPO_ROOT/crates/kreuzberg-ffi" ]; then
182182
print_status OK "FFI directory exists"
183183
print_status INFO "FFI Cargo.toml:"
184-
grep '^name\|^version' "$REPO_ROOT/crates/kreuzberg-ffi/Cargo.toml" | head -2 | sed 's/^/ /'
184+
grep '^name\|^version' "$REPO_ROOT/crates/kreuzberg-ffi/Cargo.toml" | head -2 | sed 's/^/ /' || true
185185
fi
186186

187187
print_status INFO "FFI header file: $REPO_ROOT/crates/kreuzberg-ffi/kreuzberg.h"
@@ -213,15 +213,15 @@ fi
213213

214214
if [ -d "$REPO_ROOT/packages/go/v4" ]; then
215215
print_status INFO "Go packages in v4:"
216-
find "$REPO_ROOT/packages/go/v4" -maxdepth 1 -type f -name "*.go" | head -5 | sed 's/^/ /'
216+
find "$REPO_ROOT/packages/go/v4" -maxdepth 1 -type f -name "*.go" | head -5 | sed 's/^/ /' || true
217217
fi
218218
echo ""
219219

220220
print_section "Dependency Status"
221221
print_status INFO "Checking PDFium..."
222222
if [ -n "${KREUZBERG_PDFIUM_PREBUILT:-}" ] && [ -d "$KREUZBERG_PDFIUM_PREBUILT" ]; then
223223
print_status OK "PDFium found at $KREUZBERG_PDFIUM_PREBUILT"
224-
if find "$KREUZBERG_PDFIUM_PREBUILT/lib" -maxdepth 1 -type f 2>/dev/null | head -3 | xargs -r ls -lh; then
224+
if find "$KREUZBERG_PDFIUM_PREBUILT/lib" -maxdepth 1 -type f 2>/dev/null | head -3 | xargs -r ls -lh 2>/dev/null; then
225225
:
226226
else
227227
echo " Could not list PDFium libs"
@@ -233,7 +233,7 @@ fi
233233
print_status INFO "Checking ONNX Runtime..."
234234
if [ -n "${ORT_LIB_LOCATION:-}" ] && [ -d "$ORT_LIB_LOCATION" ]; then
235235
print_status OK "ONNX Runtime found at $ORT_LIB_LOCATION"
236-
if find "$ORT_LIB_LOCATION" -maxdepth 1 -type f 2>/dev/null | head -3 | xargs -r ls -lh; then
236+
if find "$ORT_LIB_LOCATION" -maxdepth 1 -type f 2>/dev/null | head -3 | xargs -r ls -lh 2>/dev/null; then
237237
:
238238
else
239239
echo " Could not list ORT libs"

scripts/install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ get_latest_version() {
7070
# List recent releases and pick the first tag starting with "v" (skip benchmark runs etc.)
7171
local url="https://api.github.com/repos/${REPO}/releases?per_page=20"
7272
local tag
73-
tag="$(curl -fsSL "$url" | grep '"tag_name"' | sed 's/.*"tag_name":[[:space:]]*"\([^"]*\)".*/\1/' | grep '^v' | head -1)"
73+
tag="$(curl -fsSL "$url" | grep '"tag_name"' | sed 's/.*"tag_name":[[:space:]]*"\([^"]*\)".*/\1/' | grep '^v' | head -1 || true)"
7474

7575
if [ -z "$tag" ]; then
7676
error "failed to fetch latest release tag from GitHub"

scripts/publish/csharp/verify-nuget-native-assets.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ echo "Package size: $((pkg_size / 1024))K"
1414

1515
echo ""
1616
echo "=== All runtimes in package ==="
17-
unzip -l "$pkg" | grep "runtimes/" | head -20 || echo " (no runtimes found)"
17+
unzip -l "$pkg" | grep "runtimes/" | head -20 || true
1818

1919
missing_files=0
2020
for rid in linux-arm64 linux-x64 osx-arm64 win-x64; do

scripts/publish/validate-version-consistency.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ errors=0
1212
echo "Expected version: $expected"
1313
echo "----------------------------------------"
1414

15-
cargo_version="$(grep '^version' Cargo.toml | head -1 | cut -d'"' -f2)"
15+
cargo_version="$(grep '^version' Cargo.toml | head -1 | cut -d'"' -f2 || true)"
1616
echo "Cargo.toml: $cargo_version"
1717
[ "$cargo_version" = "$expected" ] || {
1818
echo "❌ Cargo.toml mismatch"
@@ -40,7 +40,7 @@ echo "crates/kreuzberg-node/package.json: $node_version"
4040
errors=$((errors + 1))
4141
}
4242

43-
python_version="$(grep '^version' packages/python/pyproject.toml | head -1 | cut -d'"' -f2)"
43+
python_version="$(grep '^version' packages/python/pyproject.toml | head -1 | cut -d'"' -f2 || true)"
4444
echo "packages/python/pyproject.toml: $python_version"
4545
[ "$python_version" = "$expected" ] || {
4646
echo "❌ Python pyproject.toml mismatch"
@@ -119,7 +119,7 @@ echo "packages/php/composer.json: $php_version"
119119
errors=$((errors + 1))
120120
}
121121

122-
elixir_version="$(grep '@version' packages/elixir/mix.exs | head -1 | cut -d'"' -f2)"
122+
elixir_version="$(grep '@version' packages/elixir/mix.exs | head -1 | cut -d'"' -f2 || true)"
123123
echo "packages/elixir/mix.exs: $elixir_version"
124124
[ "$elixir_version" = "$expected" ] || {
125125
echo "❌ Elixir mix.exs mismatch"

scripts/publish/verify-cargo-version.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ if [ ! -f "$cargo_toml" ]; then
1414
exit 1
1515
fi
1616

17-
cargo_version=$(grep '^\[workspace.package\]' -A 10 "$cargo_toml" | grep '^version = ' | head -1 | sed -E 's/version = "(.*)"/\1/')
17+
cargo_version=$(grep '^\[workspace.package\]' -A 10 "$cargo_toml" | grep '^version = ' | head -1 | sed -E 's/version = "(.*)"/\1/' || true)
1818

1919
if [ -z "$cargo_version" ]; then
2020
echo "Error: Could not extract version from $cargo_toml" >&2

tests/test_apps/homebrew/tests/test-mcp.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ log_info "Test 5: Checking for MCP socket/port configuration..."
202202
if grep -qE "(socket|port|[0-9]{4,5})" "$LOG_FILE" 2>/dev/null; then
203203
log_success "Found socket/port configuration in logs"
204204
verbose "Configuration:"
205-
grep -E "(socket|port|listen|bind)" "$LOG_FILE" | head -5 | sed 's/^/ /'
205+
grep -E "(socket|port|listen|bind)" "$LOG_FILE" | head -5 | sed 's/^/ /' || true
206206
else
207207
log_info "No explicit socket/port configuration found (may be default)"
208208
fi
@@ -216,7 +216,7 @@ if [ "$ERROR_COUNT" -eq 0 ]; then
216216
else
217217
log_warning "Found $ERROR_COUNT error entries in logs"
218218
log_warning "Error lines:"
219-
grep -iE "(error|failed|exception|panic)" "$LOG_FILE" 2>/dev/null | head -5 | sed 's/^/ /'
219+
grep -iE "(error|failed|exception|panic)" "$LOG_FILE" 2>/dev/null | head -5 | sed 's/^/ /' || true
220220
fi
221221

222222
log_info "Stopping MCP server..."

0 commit comments

Comments
 (0)