Skip to content

Commit 2d3a254

Browse files
committed
fix(docs): document sanitizeLinkHref and gate api docs build in ci
- Add @sanitizeLinkHref to the preset-commonmark api template (public export from #2410 that was missing from the doc template). - Exit non-zero when any module fails to build. The script previously logged per-module failures but always resolved, so a broken api docs build (e.g. the builddocs bump) exited 0 and slipped past ci. - Run the api docs build as an explicit step in the ci build job so regressions are caught.
1 parent 93cba10 commit 2d3a254

3 files changed

Lines changed: 18 additions & 3 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ jobs:
6565
- name: Build packages
6666
run: pnpm build
6767

68+
- name: Build API docs
69+
run: pnpm --filter=@milkdown/docs run build
70+
6871
- name: Publish snapshot
6972
if: ${{ github.event_name == 'pull_request' }}
7073
run: >

‎docs/api/preset-commonmark.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ Editor.make()
166166
@linkSchema
167167
@toggleLinkCommand
168168
@updateLinkCommand
169+
@sanitizeLinkHref
169170

170171
---
171172

‎docs/src/index.ts‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const logError = (error: unknown) => {
3232
const write = readdirSync(apiDir)
3333
.filter((dir) => dir !== '.DS_Store')
3434
.map((pathname) => parse(pathname).name)
35-
.map(async (name) => {
35+
.map(async (name): Promise<boolean> => {
3636
const main = resolve(apiDir, `${name}.md`)
3737
const out = resolve(apiOutDir, `${name}.md`)
3838

@@ -51,27 +51,38 @@ const write = readdirSync(apiDir)
5151
})
5252
await writeFile(out, markdown)
5353
logger.info(`Build module: @milkdown/${name} finished.`)
54+
return true
5455
} catch (error) {
5556
logger.error(`Build module: @milkdown/${name} failed.`)
5657
logError(error)
58+
return false
5759
}
5860
} catch {
5961
// copy the main file to out
6062
logger.log(`Copying module: @milkdown/${name}...`)
6163
try {
6264
await copyFile(main, out)
6365
logger.info(`Copy module: @milkdown/${name} finished.`)
66+
return true
6467
} catch (error) {
6568
logger.error(`Copy module: @milkdown/${name} failed.`)
6669
logError(error)
70+
return false
6771
}
6872
}
6973
})
7074

7175
Promise.all(write)
72-
.then(() => {
76+
.then((results) => {
77+
const failed = results.filter((ok) => !ok).length
78+
if (failed > 0) {
79+
logger.error(`Build api failed: ${failed} module(s) could not be built.`)
80+
process.exitCode = 1
81+
return
82+
}
7383
logger.info('Build api done.')
7484
})
7585
.catch((error) => {
76-
throw error
86+
logError(error)
87+
process.exitCode = 1
7788
})

0 commit comments

Comments
 (0)