#!/usr/bin/env bash # Build the app with the DealSage connection baked in from org variables, and # record the build as a check so DealSage shows it beside the declared ones. set -euo pipefail . "$(dirname "$0")/lib.sh" step_start build require_env APP_ID DEALSAGE_FUNCTIONS_URL PUBLISH_TOKEN SUPABASE_ANON_KEY SUPABASE_URL git_context logf="$(mktemp)"; started="$(iso_now)"; t0="$(now_ms)" echo "::group::build" set +e VITE_SUPABASE_URL="$SUPABASE_URL" VITE_SUPABASE_ANON_KEY="$SUPABASE_ANON_KEY" \ npm run build 2>&1 | tee "$logf" rc=${PIPESTATUS[0]} set -e echo "::endgroup::" dur=$(( $(now_ms) - t0 )) if [ "$rc" = 0 ] && [ ! -f dist/index.html ]; then echo "build succeeded but dist/index.html is missing" | tee -a "$logf"; rc=2 fi status=passed; summary="built in $(( dur / 1000 ))s" [ "$rc" = 0 ] || { status=failed; summary="exit code $rc"; } payload="$(jq -n \ --arg appId "$APP_ID" --arg sha "$COMMIT_SHA" --arg branch "$BRANCH" \ --arg status "$status" --argjson duration "$dur" --arg summary "$summary" --rawfile log "$logf" \ --arg started "$started" --arg finished "$(iso_now)" \ '{appId:$appId, commitSha:$sha, branch:$branch, checkId:"build", name:"Build", status:$status, required:true, durationMs:$duration, summary:$summary, logTail:($log | split("\n") | .[-80:] | join("\n")), reportedBy:"ci", startedAt:$started, finishedAt:$finished}')" ds_post record-app-check "$payload" >/dev/null || warn "could not record the build check in DealSage" summary "- build: **$status** (${dur}ms)" [ "$rc" = 0 ] || fail_build build_failed "Build failed ($summary); nothing was published." "$logf" rm -f "$logf" files="$(find dist -type f | wc -l | tr -d ' ')" log "Build ok: $files files" step_done build passed "$files $([ "$files" = 1 ] && echo file || echo files) in dist/"