From ca795f7e717769073a59e75fee1baae35159bf65 Mon Sep 17 00:00:00 2001 From: shay Date: Mon, 20 Apr 2026 13:05:40 -0400 Subject: [PATCH] feat(api): add 'streaks' to allowed widgets and settings structure. --- .github/workflows/health-check.yml | 68 +++++++++++++++++--------- generator/frontend/src/lib/demoData.ts | 8 +++ 2 files changed, 54 insertions(+), 22 deletions(-) diff --git a/.github/workflows/health-check.yml b/.github/workflows/health-check.yml index d32394c..7f42438 100644 --- a/.github/workflows/health-check.yml +++ b/.github/workflows/health-check.yml @@ -76,35 +76,59 @@ jobs: - name: Check widget SVG endpoint id: check-widget run: | - echo "HEAD https://gh-stats.com/ShayManor" - HEADERS=$(curl -sI --max-time 30 https://gh-stats.com/ShayManor) - echo "$HEADERS" - HTTP_CODE=$(printf '%s\n' "$HEADERS" | head -n1 | awk '{print $2}' | tr -d '\r') - STATUS=$(printf '%s\n' "$HEADERS" | grep -i '^x-widget-status:' | awk '{print $2}' | tr -d '\r' || true) + # Cloudflare routes /api/* to the generator directly. The bare + # / and //.svg paths land on the SPA shell + # in prod, so we probe the canonical /api//.svg. + URL="https://gh-stats.com/api/ShayManor/grade.svg" + echo "GET $URL" + HTTP_CODE=$(curl -sS -D /tmp/widget-headers.txt -o /tmp/widget-body.svg \ + -w "%{http_code}" --max-time 30 "$URL") + echo "HTTP $HTTP_CODE" + cat /tmp/widget-headers.txt if [ "$HTTP_CODE" != "200" ]; then echo "::error::Widget endpoint returned HTTP $HTTP_CODE" exit 1 fi - # ready | building | rate_limited are healthy; not_found / missing are not. - case "$STATUS" in - ready|building|rate_limited) echo "X-Widget-Status=$STATUS (ok)";; - *) echo "::error::Unexpected X-Widget-Status='$STATUS'"; exit 1;; + CT=$(grep -i '^content-type:' /tmp/widget-headers.txt | tail -n1 | awk '{print $2}' | tr -d '\r' || true) + case "$CT" in + image/svg+xml*) : ;; + *) echo "::error::Unexpected Content-Type='$CT' (expected image/svg+xml)"; exit 1;; esac - - - name: Check generator API reachable via edge - id: check-api - run: | - # /api/settings/ is a lightweight read the edge proxies to - # the generator. A 200 or 404 both prove the pipeline is alive; - # 5xx / timeout means something is wrong upstream. - HTTP_CODE=$(curl -sS -o /dev/null -w "%{http_code}" --max-time 30 https://gh-stats.com/api/settings/ShayManor) - echo "HTTP $HTTP_CODE" - if [ "$HTTP_CODE" = "200" ] || [ "$HTTP_CODE" = "404" ]; then - echo "API reachable (HTTP $HTTP_CODE)" - else - echo "::error::API returned HTTP $HTTP_CODE" + if ! head -c 200 /tmp/widget-body.svg | grep -q '/dev/null || echo "") + if [ "$STATUS" != "ok" ]; then + echo "::error::/api/health reports status='$STATUS' (expected 'ok')" + exit 1 + fi + echo "generator pipeline healthy" notify: name: notify-on-failure diff --git a/generator/frontend/src/lib/demoData.ts b/generator/frontend/src/lib/demoData.ts index d08600a..cf29c78 100644 --- a/generator/frontend/src/lib/demoData.ts +++ b/generator/frontend/src/lib/demoData.ts @@ -36,4 +36,12 @@ export const DEMO_WIDGET_DATA: WidgetData = { { language: 'Go', percentage: 18, loc: 5 }, { language: 'Rust', percentage: 12, loc: 3 }, ], + streaks: { + current: 12, + max: 47, + current_start: new Date(Date.now() - 11 * 86400000).toISOString().slice(0, 10), + last_active_date: new Date().toISOString().slice(0, 10), + max_start: '2024-09-04', + max_end: '2024-10-20', + }, }