DistrictSearch built its "most arrests" list from /estimates?state=XX&year=21-22&limit=500. That endpoint returns rows ORDER BY LEAID, RACE, SEX at eight rows per district, so a 500-row cap is not a sample of the state — it is the ~62 lowest-LEAID districts in it. Measured against California (11,488 rows, 1,715 districts): the old read covered 68 districts, and 6 of the true top 8 were invisible to it. It suggested districts with 1 and 2 arrests as the state's most notable, while San Diego Unified (178), Fresno Unified (77) and Kern High (69) never appeared. Replaced with a committed fixture, public/data/top_districts.json, generated by scripts/build-top-districts.mjs. The script pages each state to completion using meta.total from the response envelope and fails loudly on a short read, since a silent truncation there would reintroduce exactly this bug. 51 states, 135 requests, ~104KB, following the national_rates.json precedent. Re-run it only when a new CRDC wave lands. The search screen also loses a multi-second fetch on every visit, and the hardcoded "Try Derby (KS), Paterson (NJ)" hint goes with it — the real list supersedes it. Degrades to search-only if the fixture is missing. fetchStateDistricts() is kept for scripts and ad-hoc use, with its JSDoc now warning that any short read ranks by LEAID. pages.yml gains public/** in its paths filter: the fixture ships with the build, so regenerating it has to be able to trigger a deploy on its own.
67 lines
2.1 KiB
YAML
67 lines
2.1 KiB
YAML
name: Deploy to git-pages
|
|
|
|
# Builds the Vite static site and pushes it to the `pages` branch, which
|
|
# the git-pages webhook receiver at pages.civilytics.org serves.
|
|
# URL: https://pages.civilytics.org/crdc-demo/
|
|
# Same pattern as Civilytics/sln-school-comparison.
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
paths:
|
|
- 'src/**'
|
|
# Committed fixtures ship with the build: public/data/top_districts.json
|
|
# is what the search screen ranks its suggestions from, so regenerating it
|
|
# has to be able to trigger a deploy on its own.
|
|
- 'public/**'
|
|
- 'index.html'
|
|
- 'vite.config.mjs'
|
|
- 'package.json'
|
|
- '.gitea/workflows/pages.yml'
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
deploy:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v3
|
|
|
|
- name: Setup Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: '22'
|
|
cache: 'npm'
|
|
|
|
- name: Install dependencies & build static site
|
|
run: |
|
|
npm ci
|
|
# VITE_API_BASE defaults to the production API; override if needed via secrets.
|
|
# For git-pages deployment, CORS is handled by setting up a proxy endpoint on the server.
|
|
npm run build
|
|
|
|
- name: Publish dist/ to pages branch
|
|
run: |
|
|
git config user.name "Gitea Actions"
|
|
git config user.email "actions@gitea.civilytics.org"
|
|
|
|
# Use the GITHUB_TOKEN for authentication (works with Gitea token auth)
|
|
TOKEN="${{ secrets.GITHUB_TOKEN }}"
|
|
if [ -z "$TOKEN" ]; then
|
|
echo "GITHUB_TOKEN not available; skipping deploy."
|
|
exit 0
|
|
fi
|
|
|
|
git remote set-url origin "https://token:${TOKEN}@gitea.civilytics.org/Civilytics/crdc-demo.git"
|
|
|
|
# Create orphan pages branch with only the built files
|
|
rm -rf /tmp/pages-branch
|
|
git worktree add --orphan -B pages /tmp/pages-branch
|
|
|
|
cp -r dist/. /tmp/pages-branch/
|
|
echo "${GITHUB_SHA}" > /tmp/pages-branch/deploy-sha.txt
|
|
|
|
cd /tmp/pages-branch
|
|
git add --all
|
|
git commit -m "Deploy from ${GITHUB_SHA}" || echo "No changes to deploy"
|
|
git push origin pages --force
|