Files
ci-actions/pipeline/scripts/build.sh
T
2026-09-25 17:56:38 +00:00

37 lines
1.6 KiB
Bash
Executable File

#!/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"
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"
rm -f "$logf"
summary "- build: **$status** (${dur}ms)"
[ "$rc" = 0 ] || die "Build failed ($summary); nothing was published."
log "Build ok: $(find dist -type f | wc -l) files"