forked from ai-dynamo/dynamo
-
Notifications
You must be signed in to change notification settings - Fork 0
495 lines (403 loc) · 17.3 KB
/
fern-docs.yml
File metadata and controls
495 lines (403 loc) · 17.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Consolidated Fern Documentation Workflow
#
# This workflow handles all Fern documentation automation:
#
# 1. LINT (PRs): Validates Fern configuration and checks for broken links
# - Triggers on pull requests when docs/** files change
# - Runs `fern check` and `fern docs broken-links`
#
# 2. SYNC dev (push to main): Syncs docs/ from main to docs-website branch
# - Triggers on push to main when docs/** files change
# - Preserves versioned documentation snapshots on docs-website branch
# - Publishes docs to Fern after syncing
#
# 3. VERSION RELEASE (tags): Creates versioned documentation snapshot
# - Triggers on new version tags (vX.Y.Z format)
# - Creates pages-vX.Y.Z/ directory on docs-website branch
# - Updates docs.yml with new version entry
# - Publishes docs to Fern after releasing
#
# Note: The publish step is included inline because pushes made with GITHUB_TOKEN
# do not trigger other workflows (GitHub's anti-recursion guard), so we cannot
# rely on a separate publish-fern-docs.yml workflow for bot-initiated pushes.
name: Fern Docs
on:
push:
branches:
- main
- "pull-request/[0-9]+"
tags:
# Match only clean semver tags: vX.Y.Z
- 'v[0-9]+.[0-9]+.[0-9]+'
workflow_dispatch:
inputs:
tag:
description: 'Version tag to release (e.g., v0.9.0). Leave empty to sync dev docs.'
required: false
type: string
permissions:
contents: write
jobs:
# Detect changed files for conditional job execution
changed-files:
runs-on: ubuntu-latest
# Skip for tag pushes - version release doesn't need changed-files check
if: github.ref_type != 'tag'
outputs:
docs: ${{ steps.changes.outputs.docs }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check for changes
id: changes
uses: ./.github/actions/changed-files
with:
gh_token: ${{ github.token }}
#############################################################################
# LINT JOBS - Run on PRs when docs/** files change
#############################################################################
fern-check:
name: Fern Configuration Check
needs: changed-files
if: |
github.ref_type != 'tag' &&
needs.changed-files.outputs.docs == 'true' &&
(github.event_name == 'pull_request' || startsWith(github.ref, 'refs/heads/pull-request/'))
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
- name: Install Fern CLI
run: npm install -g fern-api
# Fern CLI expects a fern/ directory; create symlink after docs/ migration
- name: Create fern directory symlink
working-directory: docs
run: ln -s . fern
- name: Validate Fern configuration
working-directory: docs
run: fern check
fern-broken-links:
name: Fern Broken Links Check
needs: changed-files
if: |
github.ref_type != 'tag' &&
needs.changed-files.outputs.docs == 'true' &&
(github.event_name == 'pull_request' || startsWith(github.ref, 'refs/heads/pull-request/'))
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
- name: Install Fern CLI
run: npm install -g fern-api
# Fern CLI expects a fern/ directory; create symlink after docs/ migration
- name: Create fern directory symlink
working-directory: docs
run: ln -s . fern
- name: Check for broken links
working-directory: docs
run: fern docs broken-links
#############################################################################
# SYNC dev - Run on push to main when docs/** files change
#############################################################################
sync-dev:
name: Sync dev to docs-website
needs: changed-files
if: |
github.ref == 'refs/heads/main' &&
(needs.changed-files.outputs.docs == 'true' || github.event_name == 'workflow_dispatch') &&
(github.event.inputs.tag == '' || github.event.inputs.tag == null)
runs-on: ubuntu-latest
steps:
- name: Checkout main branch
uses: actions/checkout@v4
with:
ref: main
path: main-checkout
fetch-depth: 1
- name: Checkout docs-website branch
uses: actions/checkout@v4
with:
ref: docs-website
path: docs-checkout
fetch-depth: 1
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Git
run: |
cd docs-checkout
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Sync dev content from main
run: |
# Sync pages/ directory (dev content)
echo "Syncing pages/ from main to docs-website branch..."
rm -rf docs-checkout/docs/pages
cp -r main-checkout/docs/pages docs-checkout/docs/pages
# Sync versions/dev.yml (dev navigation)
echo "Syncing versions/dev.yml from main to docs-website branch..."
cp main-checkout/docs/versions/dev.yml docs-checkout/docs/versions/dev.yml
# Sync assets/ directory
echo "Syncing assets/ from main to docs-website branch..."
rm -rf docs-checkout/docs/assets
cp -r main-checkout/docs/assets docs-checkout/docs/assets
# Sync fern.config.json
echo "Syncing fern.config.json from main to docs-website branch..."
cp main-checkout/docs/fern.config.json docs-checkout/docs/fern.config.json
# Sync .gitignore if it exists
if [ -f main-checkout/docs/.gitignore ]; then
cp main-checkout/docs/.gitignore docs-checkout/docs/.gitignore
fi
# Sync convert_callouts.py script
if [ -f main-checkout/docs/convert_callouts.py ]; then
cp main-checkout/docs/convert_callouts.py docs-checkout/docs/convert_callouts.py
fi
# Sync components/ directory (e.g., CustomFooter.tsx)
if [ -d main-checkout/docs/components ]; then
echo "Syncing components/ from main to docs-website branch..."
rm -rf docs-checkout/docs/components
cp -r main-checkout/docs/components docs-checkout/docs/components
fi
# Sync main.css
if [ -f main-checkout/docs/main.css ]; then
echo "Syncing main.css from main to docs-website branch..."
cp main-checkout/docs/main.css docs-checkout/docs/main.css
fi
- name: Convert GitHub callouts to Fern format
run: |
echo "Converting GitHub-style callouts to Fern format in pages/..."
python3 docs-checkout/docs/convert_callouts.py --dir docs-checkout/docs/pages
echo "Callout conversion complete."
- name: Update docs.yml preserving versions
run: |
cd docs-checkout/docs
# Save the full versions array from docs-website
yq '.products[0].versions' docs.yml > /tmp/preserved_versions.yml
echo "Preserved versions array:"
cat /tmp/preserved_versions.yml
# Copy docs.yml from main to get config updates
cp ../../main-checkout/docs/docs.yml docs.yml
# Restore the preserved versions array
yq -i '.products[0].versions = load("/tmp/preserved_versions.yml")' docs.yml
echo "Updated docs.yml:"
cat docs.yml
- name: Check for changes
id: changes
run: |
cd docs-checkout
if git diff --quiet && git diff --cached --quiet; then
echo "has_changes=false" >> $GITHUB_OUTPUT
echo "No changes detected"
else
echo "has_changes=true" >> $GITHUB_OUTPUT
echo "Changes detected:"
git status --short
fi
- name: Commit and push changes
if: steps.changes.outputs.has_changes == 'true'
run: |
cd docs-checkout
git add -A
git commit -m "docs(fern): sync dev from main
Automated sync of docs/ directory from main branch.
Preserves versioned documentation snapshots.
Source commit: ${{ github.sha }}"
git push origin docs-website
echo "Successfully synced dev docs to docs-website branch"
- name: Setup Node.js
if: steps.changes.outputs.has_changes == 'true'
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install Fern CLI
if: steps.changes.outputs.has_changes == 'true'
run: npm install -g fern-api
# Fern CLI expects a fern/ directory; create symlink after docs/ migration
- name: Create fern directory symlink
if: steps.changes.outputs.has_changes == 'true'
working-directory: docs-checkout/docs
run: ln -s . fern
- name: Publish Docs
if: steps.changes.outputs.has_changes == 'true'
env:
FERN_TOKEN: ${{ secrets.FERN_TOKEN }}
working-directory: docs-checkout/docs
run: fern generate --docs
#############################################################################
# VERSION RELEASE - Run on new version tags (vX.Y.Z)
#############################################################################
release-version:
name: Release Version to docs-website
# Run on tag push OR manual dispatch with a tag specified
if: |
github.ref_type == 'tag' ||
(github.event_name == 'workflow_dispatch' && github.event.inputs.tag != '' && github.event.inputs.tag != null)
runs-on: ubuntu-latest
steps:
- name: Determine version tag
id: version
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
TAG="${{ github.event.inputs.tag }}"
else
TAG="${GITHUB_REF#refs/tags/}"
fi
# Validate tag format (must be vX.Y.Z exactly)
if ! echo "$TAG" | grep -qE '^v[0-9]+\.[0-9]+\.[0-9]+$'; then
echo "::error::Invalid tag format: $TAG. Must be vX.Y.Z (e.g., v0.9.0)"
exit 1
fi
# Extract version without 'v' prefix
VERSION="${TAG#v}"
echo "tag=$TAG" >> $GITHUB_OUTPUT
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Processing version: $VERSION (tag: $TAG)"
- name: Checkout docs-website branch
uses: actions/checkout@v4
with:
ref: docs-website
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Check if version already exists
run: |
TAG="${{ steps.version.outputs.tag }}"
if [ -d "docs/pages-$TAG" ]; then
echo "::error::Version $TAG already exists (docs/pages-$TAG directory found)"
exit 1
fi
if [ -f "docs/versions/$TAG.yml" ]; then
echo "::error::Version $TAG already exists (docs/versions/$TAG.yml found)"
exit 1
fi
echo "Version $TAG does not exist yet, proceeding with release"
- name: Setup Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Create versioned pages directory
run: |
TAG="${{ steps.version.outputs.tag }}"
echo "Creating docs/pages-$TAG/ from docs/pages/..."
# Copy current pages/ to pages-vX.Y.Z/
cp -r docs/pages "docs/pages-$TAG"
echo "Created docs/pages-$TAG/"
ls -la "docs/pages-$TAG/" | head -20
- name: Update GitHub links to 'main' to version tag
run: |
TAG="${{ steps.version.outputs.tag }}"
echo "Updating GitHub links from 'tree/main' to 'tree/$TAG' in docs/pages-$TAG/..."
# Find all markdown files and replace tree/main with tree/vX.Y.Z
find "docs/pages-$TAG" -name "*.md" -o -name "*.mdx" | while read file; do
if grep -q "github.com/ai-dynamo/dynamo/tree/main" "$file"; then
echo "Updating: $file"
sed -i "s|github.com/ai-dynamo/dynamo/tree/main|github.com/ai-dynamo/dynamo/tree/$TAG|g" "$file"
fi
done
# Also update blob/main references (for direct file links)
find "docs/pages-$TAG" -name "*.md" -o -name "*.mdx" | while read file; do
if grep -q "github.com/ai-dynamo/dynamo/blob/main" "$file"; then
echo "Updating blob links: $file"
sed -i "s|github.com/ai-dynamo/dynamo/blob/main|github.com/ai-dynamo/dynamo/blob/$TAG|g" "$file"
fi
done
echo "GitHub link update complete."
- name: Convert GitHub callouts to Fern format
run: |
TAG="${{ steps.version.outputs.tag }}"
echo "Converting GitHub-style callouts to Fern format in pages-$TAG/..."
python3 docs/convert_callouts.py --dir "docs/pages-$TAG"
echo "Callout conversion complete."
- name: Create version config file
run: |
TAG="${{ steps.version.outputs.tag }}"
VERSION="${{ steps.version.outputs.version }}"
VERSION_FILE="docs/versions/$TAG.yml"
echo "Creating version config: $VERSION_FILE"
# Copy dev.yml as template
cp docs/versions/dev.yml "$VERSION_FILE"
# Update the comment at the top
sed -i "s/# Navigation structure for Latest version/# Navigation structure for $TAG version/" "$VERSION_FILE"
sed -i "s|# Matching https://docs.nvidia.com/dynamo/latest/|# Snapshot from tag $TAG|" "$VERSION_FILE"
# Update all page paths from ../pages/ to ../pages-vX.Y.Z/
sed -i "s|path: \.\./pages/|path: ../pages-$TAG/|g" "$VERSION_FILE"
echo "Created $VERSION_FILE"
echo "First 30 lines:"
head -30 "$VERSION_FILE"
- name: Update docs.yml with new version
run: |
TAG="${{ steps.version.outputs.tag }}"
DOCS_FILE="docs/docs.yml"
echo "Updating $DOCS_FILE to include $TAG..."
# Check if version already in docs.yml
if yq ".products[0].versions[] | select(.display-name == \"$TAG\")" "$DOCS_FILE" | grep -q .; then
echo "Version $TAG already in docs.yml, skipping update"
exit 0
fi
# Find the index of the "dev" entry and insert new version right after it
DEV_IDX=$(yq '.products[0].versions | to_entries | map(select(.value.display-name == "dev")) | .[0].key' "$DOCS_FILE")
INSERT_IDX=$((DEV_IDX + 1))
yq -i "
.products[0].versions |= (
.[:$INSERT_IDX] +
[{\"display-name\": \"$TAG\", \"path\": \"./versions/$TAG.yml\", \"slug\": \"$TAG\", \"availability\": \"stable\"}] +
.[$INSERT_IDX:]
)
" "$DOCS_FILE"
# Update the top-level entry to point to the new version
yq -i ".products[0].path = \"./versions/$TAG.yml\"" "$DOCS_FILE"
# Update the "Latest" entry to point to the new version
yq -i ".products[0].versions[0].path = \"./versions/$TAG.yml\"" "$DOCS_FILE"
yq -i ".products[0].versions[0].display-name = \"Latest ($TAG)\"" "$DOCS_FILE"
echo "Updated docs.yml products/versions section:"
yq '.products[0].versions' "$DOCS_FILE"
- name: Commit and push changes
run: |
TAG="${{ steps.version.outputs.tag }}"
git add "docs/pages-$TAG/"
git add "docs/versions/$TAG.yml"
git add docs/docs.yml
git commit -m "docs(fern): release version $TAG
- Created docs/pages-$TAG/ with documentation snapshot
- Created docs/versions/$TAG.yml version navigation config
- Updated docs/docs.yml to include $TAG in version list
Automated by fern-docs workflow
Source tag: $TAG"
git push origin docs-website
echo "Successfully released documentation for $TAG on docs-website branch"
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install Fern CLI
run: npm install -g fern-api
# Fern CLI expects a fern/ directory; create symlink after docs/ migration
- name: Create fern directory symlink
working-directory: ./docs
run: ln -s . fern
- name: Publish Docs
env:
FERN_TOKEN: ${{ secrets.FERN_TOKEN }}
working-directory: ./docs
run: fern generate --docs