Spaces:
Running
Running
| # Run any command and tell Puck how it went. | |
| # puck-run bun test | |
| # puck-run cargo build | |
| # Exit code passes through untouched; reporting is fire-and-forget — | |
| # a sleeping daemon never breaks your build. | |
| set -uo pipefail | |
| if [ $# -eq 0 ]; then | |
| echo "usage: puck-run <command> [args...]" >&2 | |
| exit 64 | |
| fi | |
| PUCK_URL="${PUCK_URL:-http://127.0.0.1:7777}" | |
| PROJECT="$(basename "$PWD")" | |
| CMD="$*" | |
| START=$(date +%s) | |
| "$@" | |
| CODE=$? | |
| DUR=$(( $(date +%s) - START )) | |
| if [ $CODE -eq 0 ]; then | |
| TYPE="passed"; TITLE="${CMD} passed in ${PROJECT} (${DUR}s)" | |
| else | |
| TYPE="failed"; TITLE="${CMD} failed in ${PROJECT} (exit ${CODE}, ${DUR}s)" | |
| fi | |
| if command -v jq >/dev/null 2>&1; then | |
| BODY="$(jq -nc --arg type "$TYPE" --arg title "$TITLE" \ | |
| --arg cmd "$CMD" --arg project "$PROJECT" --argjson code "$CODE" --argjson dur "$DUR" \ | |
| '{source: "build", type: $type, title: $title, payload: {cmd: $cmd, project: $project, exit: $code, seconds: $dur}}')" | |
| curl -s -m 2 -X POST "$PUCK_URL/api/events" \ | |
| -H 'Content-Type: application/json' -d "$BODY" >/dev/null 2>&1 || true | |
| fi | |
| exit $CODE | |