Skip to content

Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.

build(docs): build-api-docs gains --check, and CI runs it

Boris 'B' Kurktchiev7bf38983584b
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 12ccd6857..341cf6d1e 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -10,6 +10,8 @@ on:
- 'mcp/**'
- 'scripts/build-coach-assets.mjs'
- 'scripts/build-coach-library.mjs'
+ - 'scripts/build-api-docs.mjs'
+ - 'website/api.html'
- 'api/coach/prompts/**'
- '.github/workflows/test.yml'
push:
@@ -20,6 +22,8 @@ on:
- 'mcp/**'
- 'scripts/build-coach-assets.mjs'
- 'scripts/build-coach-library.mjs'
+ - 'scripts/build-api-docs.mjs'
+ - 'website/api.html'
- 'api/coach/prompts/**'
- '.github/workflows/test.yml'
workflow_dispatch:
@@ -103,6 +107,9 @@ jobs:
# that forgets to regenerate it would otherwise only surface as "the Coach can't find
# that exercise" on somebody's instance.
- run: node scripts/build-coach-assets.mjs --check
+ # website/api.html is generated from api/openapi.yaml and committed. Same reason.
+ - run: npm ci
+ - run: node scripts/build-api-docs.mjs --check
- run: node api/scripts/check-core-loadable.mjs
# Builds *and runs* both image targets. Building alone would not have caught the api image
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index ce8a1d321..f2c470392 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -256,6 +256,10 @@ test:api:
# A dataset or prompt change that forgets to regenerate them would otherwise only surface as
# "the Coach can't find that exercise" — or a prompt edit that never reached the model.
- node scripts/build-coach-assets.mjs --check
+ # website/api.html is generated from api/openapi.yaml and committed. Same reason: a spec
+ # change that forgets to regenerate it publishes a reference for the previous version.
+ - npm ci
+ - node scripts/build-api-docs.mjs --check
# api/coach/core is imported by the server under bare node AND by the phone under Vite.
# vitest forgives what node does not (?raw, import.meta.glob); this runs outside vitest.
- node api/scripts/check-core-loadable.mjs
diff --git a/scripts/build-api-docs.mjs b/scripts/build-api-docs.mjs
index bc51b8348..5f50b5ced 100644
--- a/scripts/build-api-docs.mjs
+++ b/scripts/build-api-docs.mjs
@@ -2,6 +2,7 @@
// Builds website/api.html — the static API reference — from api/openapi.yaml.
//
// node scripts/build-api-docs.mjs
+// node scripts/build-api-docs.mjs --check # fail if stale, never write (CI)
//
// Deterministic: the same spec always produces byte-identical output (no
// timestamps), so re-running it only dirties the file when the spec changed.
@@ -18,6 +19,7 @@ import yaml from 'js-yaml'
const root = path.join(path.dirname(fileURLToPath(import.meta.url)), '..')
const specPath = path.join(root, 'api', 'openapi.yaml')
const outPath = path.join(root, 'website', 'api.html')
+const check = process.argv.includes('--check')
const spec = yaml.load(fs.readFileSync(specPath, 'utf8'))
/* ------------------------------------------------------------------ helpers */
@@ -627,5 +629,21 @@ ${schemaCards}
</html>
`
-fs.writeFileSync(outPath, html)
-console.log(`wrote ${path.relative(root, outPath)} — ${ops.length} endpoints, ${Object.keys(spec.components.schemas).length} schemas, ${(html.length / 1024).toFixed(1)} KB`)
+const rel = path.relative(root, outPath)
+const summary = `${ops.length} endpoints, ${Object.keys(spec.components.schemas).length} schemas, ${(html.length / 1024).toFixed(1)} KB`
+// --check is what build-coach-assets.mjs has had all along, for the same reason: the page is
+// generated and committed, so a spec change that forgets to regenerate it ships a reference
+// that describes the previous version of the API. It also catches the other direction — an
+// edit made to the page by hand, which the next regeneration would silently undo.
+if (check) {
+ let current = null
+ try { current = fs.readFileSync(outPath, 'utf8') } catch { /* missing counts as stale */ }
+ if (current !== html) {
+ console.error(`${rel} is out of date — run: node scripts/build-api-docs.mjs`)
+ process.exit(1)
+ }
+ console.log(`${rel} in sync — ${summary}`)
+} else {
+ fs.writeFileSync(outPath, html)
+ console.log(`wrote ${rel} — ${summary}`)
+}