#!/usr/bin/env bash # Run one Site CI command with a hard timeout and durable diagnostic output. # Cargo failures, SIGKILL/OOM, and timeout remain failures; this wrapper never # turns a missing result into a green job. set -euo pipefail usage() { echo "usage: $0 [args ...]" >&2 exit 64 } [[ $# -ge 2 ]] || usage name=$1 shift [[ $name =~ ^[A-Za-z0-9._-]+$ ]] || { echo "invalid artifact name: $name" >&2 exit 64 } log_dir=${NIGIG_SITE_CI_LOG_DIR:-/tmp/nigig-site-ci} timeout_seconds=${NIGIG_SITE_CI_TIMEOUT_SECONDS:-3300} [[ $timeout_seconds =~ ^[1-9][0-9]*$ ]] || { echo "NIGIG_SITE_CI_TIMEOUT_SECONDS must be a positive integer" >&2 exit 64 } mkdir -p "$log_dir" log_file="$log_dir/$name.log" rss_file="$log_dir/$name.rss.txt" result_file="$log_dir/$name.result.txt" : >"$log_file" : >"$rss_file" printf 'command:' >"$result_file" printf ' %q' "$@" >>"$result_file" printf '\nstarted_utc=%s\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)" >>"$result_file" set +e if [[ -x /usr/bin/time ]]; then /usr/bin/time -v -o "$rss_file" \ timeout --signal=TERM --kill-after=30 "$timeout_seconds" "$@" \ >"$log_file" 2>&1 status=$? else echo "warning: /usr/bin/time unavailable; peak RSS not captured" >"$rss_file" timeout --signal=TERM --kill-after=30 "$timeout_seconds" "$@" \ >"$log_file" 2>&1 status=$? fi set -e printf 'finished_utc=%s\nexit_status=%s\n' \ "$(date -u +%Y-%m-%dT%H:%M:%SZ)" "$status" >>"$result_file" cat "$log_file" echo "--- resource report: $name ---" cat "$rss_file" echo "--- command result: $name ---" cat "$result_file" if [[ $status -eq 124 || $status -eq 137 ]]; then echo "ERROR: $name exceeded its timeout/resource envelope (exit $status)." >&2 elif grep -Eiq 'signal: 9|SIGKILL|out of memory|Cannot allocate memory' "$log_file"; then echo "ERROR: $name was killed by an infrastructure/resource failure." >&2 fi exit "$status"