diff --git a/.github/workflows/sync-d1.yml b/.github/workflows/sync-d1.yml new file mode 100644 index 0000000..ebbb93d --- /dev/null +++ b/.github/workflows/sync-d1.yml @@ -0,0 +1,36 @@ +name: Sync D1 Catalog + +# GitHub issues own the SRS catalog (topics, problems, set/diff labels, +# milestones); the Worker's D1 holds a reconciled copy. The 8 AM ET cron is +# the backstop — this workflow pushes curriculum edits into D1 immediately. +# +# The reconcile is a total recompute (never touches SRS-owned columns), so +# bursts can safely collapse to the last run: cancel-in-progress is correct. + +on: + issues: + types: + [opened, edited, labeled, unlabeled, milestoned, demilestoned, reopened, transferred, deleted] + workflow_dispatch: + +permissions: {} + +concurrency: + group: sync-d1 + cancel-in-progress: true + +jobs: + reconcile: + # Only curriculum issues shape the catalog. + if: >- + github.event_name == 'workflow_dispatch' || + contains(github.event.issue.labels.*.name, 'problem') || + contains(github.event.issue.labels.*.name, 'topic') + runs-on: ubuntu-latest + steps: + - name: Reconcile catalog into D1 + run: | + curl -sf -X POST -H "Authorization: Bearer $SRS_ADMIN_KEY" \ + https://srs-api.prdlk.workers.dev/admin/reconcile + env: + SRS_ADMIN_KEY: ${{ secrets.SRS_ADMIN_KEY }} diff --git a/AGENTS.md b/AGENTS.md index a28c39d..518982c 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -36,7 +36,7 @@ flowchart LR | `scripts/` | Flat Bun TS: automation entries (shebang + top-level await) and libraries (no shebang, side-effect-free on import) | | `docs/` | Blume site. `docs/solutions/()/-.mdx` generated by sync; `(algorithms)/`, `(data-structures)/` hand-written explainers | | `api/` | Cloudflare Worker (own Bun workspace): `src/` modules, `data/schedule.json` (day → topic issue, human-edited, bundled at deploy), `migrations/`, `scripts/import-srs.ts` | -| `.github/workflows/` | deploy (docs), close-solved, close-topics — Worker deploys are manual (`bun run api:deploy`) | +| `.github/workflows/` | deploy (docs), close-solved, close-topics, sync-d1 (issue edits → `/admin/reconcile`) — Worker deploys are manual (`bun run api:deploy`) | ## Development Commands diff --git a/api/README.md b/api/README.md index 33e6075..f030e51 100644 --- a/api/README.md +++ b/api/README.md @@ -59,6 +59,10 @@ routes). Bindings in `wrangler.jsonc`: `DB` (D1 `srs`), `EMAIL` (`send_email`, restricted to the verified destination). Sender domain `prdlk.com` is onboarded to Email Sending. +The `sync-d1.yml` Actions workflow additionally pushes curriculum issue +edits into D1 immediately (`POST /admin/reconcile` with the +`SRS_ADMIN_KEY` repo secret); the morning cron is the backstop. + ## Local dev ```sh