"vscode:/vscode.git/clone" did not exist on "910b587db1a605c2f70355c6963582928ffa80fa"
Unverified Commit 219e5c45 authored by Jonathan Tong's avatar Jonathan Tong Committed by GitHub
Browse files

ci: add GitHub actions for linting and cutting versioned docs for Fern (#5524)


Signed-off-by: default avatarJont828 <jt572@cornell.edu>
parent ac50dccf
...@@ -31,6 +31,9 @@ outputs: ...@@ -31,6 +31,9 @@ outputs:
rust: rust:
description: 'Whether rust files changed' description: 'Whether rust files changed'
value: ${{ steps.filter.outputs.rust_any_modified }} value: ${{ steps.filter.outputs.rust_any_modified }}
fern:
description: 'Whether fern docs files changed'
value: ${{ steps.filter.outputs.fern_any_modified }}
runs: runs:
using: "composite" using: "composite"
...@@ -86,6 +89,7 @@ runs: ...@@ -86,6 +89,7 @@ runs:
echo "trtllm: ${{ steps.filter.outputs.trtllm_any_modified }}" echo "trtllm: ${{ steps.filter.outputs.trtllm_any_modified }}"
echo "frontend: ${{ steps.filter.outputs.frontend_any_modified }}" echo "frontend: ${{ steps.filter.outputs.frontend_any_modified }}"
echo "rust: ${{ steps.filter.outputs.rust_any_modified }}" echo "rust: ${{ steps.filter.outputs.rust_any_modified }}"
echo "fern: ${{ steps.filter.outputs.fern_any_modified }}"
echo "" echo ""
echo "=== Files Matching Each Filter ===" echo "=== Files Matching Each Filter ==="
echo "docs: ${{ steps.filter.outputs.docs_all_modified_files }}" echo "docs: ${{ steps.filter.outputs.docs_all_modified_files }}"
...@@ -99,12 +103,13 @@ runs: ...@@ -99,12 +103,13 @@ runs:
echo "trtllm: ${{ steps.filter.outputs.trtllm_all_modified_files }}" echo "trtllm: ${{ steps.filter.outputs.trtllm_all_modified_files }}"
echo "frontend: ${{ steps.filter.outputs.frontend_all_modified_files }}" echo "frontend: ${{ steps.filter.outputs.frontend_all_modified_files }}"
echo "rust: ${{ steps.filter.outputs.rust_all_modified_files }}" echo "rust: ${{ steps.filter.outputs.rust_all_modified_files }}"
echo "fern: ${{ steps.filter.outputs.fern_all_modified_files }}"
- name: Check for uncovered files - name: Check for uncovered files
shell: bash shell: bash
run: | run: |
# Combine all filter-specific files into one list # Combine all filter-specific files into one list
COVERED_FILES=$(echo "${{ steps.filter.outputs.docs_all_modified_files }} ${{ steps.filter.outputs.examples_all_modified_files }} ${{ steps.filter.outputs.ignore_all_modified_files }} ${{ steps.filter.outputs.ci_all_modified_files }} ${{ steps.filter.outputs.core_all_modified_files }} ${{ steps.filter.outputs.operator_all_modified_files }} ${{ steps.filter.outputs.deploy_all_modified_files }} ${{ steps.filter.outputs.planner_all_modified_files }} ${{ steps.filter.outputs.vllm_all_modified_files }} ${{ steps.filter.outputs.sglang_all_modified_files }} ${{ steps.filter.outputs.trtllm_all_modified_files }} ${{ steps.filter.outputs.frontend_all_modified_files }} ${{ steps.filter.outputs.rust_all_modified_files }}" | tr ' ' '\n' | grep -v '^$' | sort -u) COVERED_FILES=$(echo "${{ steps.filter.outputs.docs_all_modified_files }} ${{ steps.filter.outputs.examples_all_modified_files }} ${{ steps.filter.outputs.ignore_all_modified_files }} ${{ steps.filter.outputs.ci_all_modified_files }} ${{ steps.filter.outputs.core_all_modified_files }} ${{ steps.filter.outputs.operator_all_modified_files }} ${{ steps.filter.outputs.deploy_all_modified_files }} ${{ steps.filter.outputs.planner_all_modified_files }} ${{ steps.filter.outputs.vllm_all_modified_files }} ${{ steps.filter.outputs.sglang_all_modified_files }} ${{ steps.filter.outputs.trtllm_all_modified_files }} ${{ steps.filter.outputs.frontend_all_modified_files }} ${{ steps.filter.outputs.rust_all_modified_files }} ${{ steps.filter.outputs.fern_all_modified_files }}" | tr ' ' '\n' | grep -v '^$' | sort -u)
# Get all modified files # Get all modified files
ALL_FILES=$(echo "${{ steps.filter.outputs.all_all_modified_files }}" | tr ' ' '\n' | grep -v '^$' | sort -u) ALL_FILES=$(echo "${{ steps.filter.outputs.all_all_modified_files }}" | tr ' ' '\n' | grep -v '^$' | sort -u)
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
# sglang -> sglang build and test # sglang -> sglang build and test
# trtllm -> trtllm build and test # trtllm -> trtllm build and test
# frontend -> frontend EPP image build # frontend -> frontend EPP image build
# fern -> fern docs lint, sync, and version release
# #
# Filters for coverage only (no CI triggered): # Filters for coverage only (no CI triggered):
# docs, examples, ignore, planner # docs, examples, ignore, planner
...@@ -17,7 +18,6 @@ all: ...@@ -17,7 +18,6 @@ all:
docs: docs:
- 'docs/**' - 'docs/**'
- 'fern/**'
- '**/*.md' - '**/*.md'
- '**/*.rst' - '**/*.rst'
- '**/*.txt' - '**/*.txt'
...@@ -27,6 +27,9 @@ docs: ...@@ -27,6 +27,9 @@ docs:
- 'LICENSE' - 'LICENSE'
- 'CODEOWNERS' - 'CODEOWNERS'
fern:
- 'fern/**'
examples: examples:
- 'recipes/**' - 'recipes/**'
- 'examples/**' - 'examples/**'
......
# 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 fern/** files change
# - Runs `fern check` and `fern docs broken-links`
#
# 2. SYNC vNEXT (push to main): Syncs fern/ from main to docs-website branch
# - Triggers on push to main when fern/** files change
# - Preserves versioned documentation snapshots on docs-website branch
#
# 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
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 vNext.'
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:
fern: ${{ steps.changes.outputs.fern }}
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 fern/** files change
#############################################################################
fern-check:
name: Fern Configuration Check
needs: changed-files
if: |
github.ref_type != 'tag' &&
needs.changed-files.outputs.fern == '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
- name: Validate Fern configuration
working-directory: fern
run: fern check
fern-broken-links:
name: Fern Broken Links Check
needs: changed-files
if: |
github.ref_type != 'tag' &&
needs.changed-files.outputs.fern == '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
- name: Check for broken links
working-directory: fern
run: fern docs broken-links
#############################################################################
# SYNC vNEXT - Run on push to main when fern/** files change
#############################################################################
sync-vnext:
name: Sync vNext to docs-website
needs: changed-files
if: |
github.ref == 'refs/heads/main' &&
(needs.changed-files.outputs.fern == '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: fern-checkout
fetch-depth: 1
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Git
run: |
cd fern-checkout
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Sync vNext content from main
run: |
# Sync pages/ directory (vNext content)
echo "Syncing pages/ from main to docs-website branch..."
rm -rf fern-checkout/fern/pages
cp -r main-checkout/fern/pages fern-checkout/fern/pages
# Sync versions/next.yml (vNext navigation)
echo "Syncing versions/next.yml from main to docs-website branch..."
cp main-checkout/fern/versions/next.yml fern-checkout/fern/versions/next.yml
# Sync assets/ directory
echo "Syncing assets/ from main to docs-website branch..."
rm -rf fern-checkout/fern/assets
cp -r main-checkout/fern/assets fern-checkout/fern/assets
# Sync fern.config.json
echo "Syncing fern.config.json from main to docs-website branch..."
cp main-checkout/fern/fern.config.json fern-checkout/fern/fern.config.json
# Sync .gitignore if it exists
if [ -f main-checkout/fern/.gitignore ]; then
cp main-checkout/fern/.gitignore fern-checkout/fern/.gitignore
fi
# Sync convert_callouts.py script
if [ -f main-checkout/fern/convert_callouts.py ]; then
cp main-checkout/fern/convert_callouts.py fern-checkout/fern/convert_callouts.py
fi
- name: Convert GitHub callouts to Fern format
run: |
echo "Converting GitHub-style callouts to Fern format in pages/..."
python3 fern-checkout/fern/convert_callouts.py --dir fern-checkout/fern/pages
echo "Callout conversion complete."
- name: Update docs.yml preserving versions
run: |
cd fern-checkout/fern
# Extract the list of versioned entries from current docs.yml (on docs-website branch)
# These are entries after "path: ./versions/next.yml"
# We need to preserve them while updating the rest from main
# Get version entries (lines containing "display-name: v" and their path lines)
VERSION_ENTRIES=$(awk '/- display-name: v/{found=1} found{print; if(/path:/) found=0}' docs.yml)
# Copy docs.yml from main as base
cp ../../main-checkout/fern/docs.yml docs.yml
# If we had version entries, append them after the next.yml line
if [ -n "$VERSION_ENTRIES" ]; then
echo "Preserving version entries:"
echo "$VERSION_ENTRIES"
# Create a temp file with the version entries properly indented
echo "$VERSION_ENTRIES" > /tmp/version_entries.txt
# Insert version entries after the next.yml path line
sed -i '/path: \.\/versions\/next\.yml/r /tmp/version_entries.txt' docs.yml
fi
echo "Updated docs.yml:"
cat docs.yml
- name: Check for changes
id: changes
run: |
cd fern-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 fern-checkout
git add -A
git commit -m "docs(fern): sync vNext from main
Automated sync of fern/ directory from main branch.
Preserves versioned documentation snapshots.
Source commit: ${{ github.sha }}"
git push origin docs-website
echo "Successfully synced vNext docs to docs-website branch"
#############################################################################
# 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 "fern/pages-$TAG" ]; then
echo "::error::Version $TAG already exists (fern/pages-$TAG directory found)"
exit 1
fi
if [ -f "fern/versions/$TAG.yml" ]; then
echo "::error::Version $TAG already exists (fern/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 fern/pages-$TAG/ from fern/pages/..."
# Copy current pages/ to pages-vX.Y.Z/
cp -r fern/pages "fern/pages-$TAG"
echo "Created fern/pages-$TAG/"
ls -la "fern/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 fern/pages-$TAG/..."
# Find all markdown files and replace tree/main with tree/vX.Y.Z
find "fern/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 "fern/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 fern/convert_callouts.py --dir "fern/pages-$TAG"
echo "Callout conversion complete."
- name: Create version config file
run: |
TAG="${{ steps.version.outputs.tag }}"
VERSION="${{ steps.version.outputs.version }}"
VERSION_FILE="fern/versions/$TAG.yml"
echo "Creating version config: $VERSION_FILE"
# Copy next.yml as template
cp fern/versions/next.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="fern/docs.yml"
echo "Updating $DOCS_FILE to include $TAG..."
# Check if version already in docs.yml
if grep -q "display-name: $TAG" "$DOCS_FILE"; then
echo "Version $TAG already in docs.yml, skipping update"
exit 0
fi
# Insert new version after "Next" entry
# The new version should be inserted after the "path: ./versions/next.yml" line
# Use a temp file approach for reliable multi-line insertion
awk -v tag="$TAG" '
/path: \.\/versions\/next\.yml/ {
print
print " - display-name: " tag
print " path: ./versions/" tag ".yml"
next
}
{ print }
' "$DOCS_FILE" > "${DOCS_FILE}.tmp" && mv "${DOCS_FILE}.tmp" "$DOCS_FILE"
echo "Updated docs.yml versions section:"
grep -A 20 "^versions:" "$DOCS_FILE"
- name: Commit and push changes
run: |
TAG="${{ steps.version.outputs.tag }}"
git add "fern/pages-$TAG/"
git add "fern/versions/$TAG.yml"
git add fern/docs.yml
git commit -m "docs(fern): release version $TAG
- Created fern/pages-$TAG/ with documentation snapshot
- Created fern/versions/$TAG.yml version navigation config
- Updated fern/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"
#!/usr/bin/env python3
# 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.
"""
Convert GitHub-style admonitions to Fern's admonition format.
GitHub admonitions look like:
> [!NOTE]
> Useful information that users should know.
> [!TIP]
> Helpful advice for doing things better.
> [!IMPORTANT]
> Key information users need to know.
> [!WARNING]
> Urgent info that needs immediate user attention.
> [!CAUTION]
> Advises about risks or negative outcomes.
Fern admonitions look like:
<Note>This highlights additional context or supplementary information</Note>
<Tip>This suggests a helpful tip</Tip>
<Info>This draws attention to important information</Info>
<Warning>This raises a warning to watch out for</Warning>
<Error>This indicates a potential error</Error>
This script can be used when syncing docs from the main docs/ folder
to the fern/pages/ folder for the docs-website branch.
Usage:
# Convert a single file
python convert_callouts.py input.md output.md
# Convert a single file in-place
python convert_callouts.py input.md
# Convert all markdown files in a directory
python convert_callouts.py --dir /path/to/pages
# Convert from stdin to stdout
cat input.md | python convert_callouts.py -
# Run tests
python convert_callouts.py --test
"""
import argparse
import re
import sys
from pathlib import Path
# Mapping from GitHub alert types to Fern admonition tags
# GitHub types: NOTE, TIP, IMPORTANT, WARNING, CAUTION
# Fern types: Info, Warning, Success, Error, Note, Launch, Tip, Check
GITHUB_TO_FERN_MAPPING = {
"NOTE": "Note",
"TIP": "Tip",
"IMPORTANT": "Info", # IMPORTANT -> Info (draws attention to important info)
"WARNING": "Warning",
"CAUTION": "Error", # CAUTION -> Error (indicates potential error/risk)
}
# Regex pattern to match GitHub-style admonitions
# Matches:
# > [!TYPE]
# > Content line 1
# > Content line 2
# (ends at a blank line or non-blockquote line)
GITHUB_ADMONITION_PATTERN = re.compile(
r"^(?P<indent>[ \t]*)>[ \t]*\[!(?P<type>NOTE|TIP|IMPORTANT|WARNING|CAUTION)\][ \t]*\n"
r"(?P<content>(?:(?P=indent)>[ \t]*.*\n?)+)",
re.MULTILINE | re.IGNORECASE,
)
def extract_blockquote_content(content: str, indent: str) -> str:
"""
Extract the actual content from blockquote lines.
Args:
content: The raw blockquote content (lines starting with '>')
indent: The leading indentation before '>'
Returns:
The content without blockquote markers, preserving internal formatting.
"""
lines = content.split("\n")
extracted_lines = []
for line in lines:
# Remove the indent and blockquote marker
if line.startswith(indent + ">"):
# Remove indent + '>' and optional single space after
stripped = line[len(indent) + 1 :]
if stripped.startswith(" "):
stripped = stripped[1:]
extracted_lines.append(stripped)
elif line.strip() == "":
# Empty line ends the blockquote
break
else:
# Non-blockquote line ends the content
break
# Join and strip trailing whitespace, but preserve internal newlines
result = "\n".join(extracted_lines).rstrip()
return result
def convert_single_admonition(match: re.Match) -> str:
"""
Convert a single GitHub admonition match to Fern format.
Args:
match: A regex match object containing the admonition
Returns:
The converted Fern-style admonition
"""
indent = match.group("indent")
alert_type = match.group("type").upper()
raw_content = match.group("content")
# Get the Fern tag for this alert type
fern_tag = GITHUB_TO_FERN_MAPPING.get(alert_type, "Note")
# Extract the actual content from blockquote lines
content = extract_blockquote_content(raw_content, indent)
# Handle multi-line content
# For Fern, we can either:
# 1. Keep it on one line (for short content)
# 2. Use multi-line format (for longer content)
content_lines = content.split("\n")
if len(content_lines) == 1 and len(content) < 100:
# Single short line - keep on one line
return f"{indent}<{fern_tag}>{content}</{fern_tag}>\n"
else:
# Multi-line content - format with proper indentation
# Fern supports multi-line content within the tags
formatted_content = "\n".join(content_lines)
return f"{indent}<{fern_tag}>\n{formatted_content}\n{indent}</{fern_tag}>\n"
def convert_admonitions(text: str) -> str:
"""
Convert all GitHub-style admonitions in the text to Fern format.
Args:
text: The markdown text containing GitHub admonitions
Returns:
The text with admonitions converted to Fern format
"""
return GITHUB_ADMONITION_PATTERN.sub(convert_single_admonition, text)
def process_file(input_path: Path, output_path: Path | None = None) -> None:
"""
Process a single markdown file, converting admonitions.
Args:
input_path: Path to the input file
output_path: Path to the output file (None for in-place)
"""
content = input_path.read_text(encoding="utf-8")
converted = convert_admonitions(content)
if output_path is None:
output_path = input_path
output_path.write_text(converted, encoding="utf-8")
def process_directory(dir_path: Path, recursive: bool = True) -> int:
"""
Process all markdown files in a directory.
Args:
dir_path: Path to the directory
recursive: Whether to process subdirectories
Returns:
Number of files processed
"""
pattern = "**/*.md" if recursive else "*.md"
files = list(dir_path.glob(pattern))
count = 0
for file_path in files:
print(f"Processing: {file_path}")
process_file(file_path)
count += 1
return count
def run_tests():
"""Run all test cases for the convert_admonitions function."""
import textwrap
passed = 0
failed = 0
def test(name: str, input_text: str, expected: str):
nonlocal passed, failed
result = convert_admonitions(input_text)
if result == expected:
print(f" PASS: {name}")
passed += 1
else:
print(f" FAIL: {name}")
print(f" Input:\n{textwrap.indent(repr(input_text), ' ')}")
print(f" Expected:\n{textwrap.indent(repr(expected), ' ')}")
print(f" Got:\n{textwrap.indent(repr(result), ' ')}")
failed += 1
print("Running tests...\n")
# Test 1: Simple NOTE conversion (short content -> single line)
test(
"Simple NOTE - single line",
"> [!NOTE]\n> This is a note.\n",
"<Note>This is a note.</Note>\n",
)
# Test 2: Simple TIP conversion
test(
"Simple TIP - single line",
"> [!TIP]\n> This is a tip.\n",
"<Tip>This is a tip.</Tip>\n",
)
# Test 3: IMPORTANT -> Info mapping
test(
"IMPORTANT -> Info mapping",
"> [!IMPORTANT]\n> This is important.\n",
"<Info>This is important.</Info>\n",
)
# Test 4: WARNING conversion
test(
"WARNING conversion",
"> [!WARNING]\n> This is a warning.\n",
"<Warning>This is a warning.</Warning>\n",
)
# Test 5: CAUTION -> Error mapping
test(
"CAUTION -> Error mapping",
"> [!CAUTION]\n> This is a caution.\n",
"<Error>This is a caution.</Error>\n",
)
# Test 6: Multi-line content (should use multi-line format)
test(
"Multi-line content",
"> [!NOTE]\n> Line one.\n> Line two.\n",
"<Note>\nLine one.\nLine two.\n</Note>\n",
)
# Test 7: Long single line (>100 chars -> multi-line format)
long_content = "A" * 101
test(
"Long single line -> multi-line format",
f"> [!NOTE]\n> {long_content}\n",
f"<Note>\n{long_content}\n</Note>\n",
)
# Test 8: Case insensitivity
test(
"Case insensitivity (lowercase)",
"> [!note]\n> Lowercase note.\n",
"<Note>Lowercase note.</Note>\n",
)
test(
"Case insensitivity (mixed case)",
"> [!NoTe]\n> Mixed case note.\n",
"<Note>Mixed case note.</Note>\n",
)
# Test 9: Indented admonition
test(
"Indented admonition",
" > [!NOTE]\n > Indented note.\n",
" <Note>Indented note.</Note>\n",
)
# Test 10: Multiple admonitions in one text
test(
"Multiple admonitions",
"> [!NOTE]\n> First note.\n\nSome text.\n\n> [!TIP]\n> A tip.\n",
"<Note>First note.</Note>\n\nSome text.\n\n<Tip>A tip.</Tip>\n",
)
# Test 11: Admonition with markdown formatting
test(
"Admonition with markdown formatting",
"> [!NOTE]\n> This has **bold** and `code`.\n",
"<Note>This has **bold** and `code`.</Note>\n",
)
# Test 12: Admonition with link
test(
"Admonition with link",
"> [!TIP]\n> See [the docs](https://example.com).\n",
"<Tip>See [the docs](https://example.com).</Tip>\n",
)
# Test 13: Empty content after type
test(
"Content on same line as blockquote marker",
"> [!NOTE]\n>\n",
"<Note></Note>\n",
)
# Test 14: Content with extra spaces
test(
"Content with leading space preserved",
"> [!NOTE]\n> Two spaces before.\n",
"<Note> Two spaces before.</Note>\n",
)
# Test 15: No conversion needed (not an admonition)
test(
"Regular blockquote (no conversion)",
"> This is just a regular blockquote.\n",
"> This is just a regular blockquote.\n",
)
# Test 16: Admonition in middle of document
test(
"Admonition in middle of document",
"# Header\n\nSome paragraph.\n\n> [!WARNING]\n> Be careful!\n\nMore text.\n",
"# Header\n\nSome paragraph.\n\n<Warning>Be careful!</Warning>\n\nMore text.\n",
)
# Test 17: Tab-indented admonition
test(
"Tab-indented admonition",
"\t> [!NOTE]\n\t> Tab indented.\n",
"\t<Note>Tab indented.</Note>\n",
)
# Test 18: Multi-line with blank line in content (ends at blank)
test(
"Multi-line ending at blank line",
"> [!NOTE]\n> Line one.\n> Line two.\n\nAfter.\n",
"<Note>\nLine one.\nLine two.\n</Note>\n\nAfter.\n",
)
print(f"\n{'='*50}")
print(f"Results: {passed} passed, {failed} failed")
print(f"{'='*50}")
return failed == 0
def main():
parser = argparse.ArgumentParser(
description="Convert GitHub-style admonitions to Fern format",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog=__doc__,
)
parser.add_argument(
"input",
nargs="?",
help="Input file path, or '-' for stdin. If --dir is used, this is ignored.",
)
parser.add_argument(
"output",
nargs="?",
help="Output file path. If omitted, modifies input in-place (except for stdin).",
)
parser.add_argument(
"--dir",
"-d",
type=Path,
help="Process all markdown files in the specified directory",
)
parser.add_argument(
"--no-recursive",
action="store_true",
help="Don't process subdirectories when using --dir",
)
parser.add_argument(
"--test",
"-t",
action="store_true",
help="Run test cases",
)
args = parser.parse_args()
if args.test:
# Run tests
success = run_tests()
sys.exit(0 if success else 1)
if args.dir:
# Process directory
if not args.dir.is_dir():
print(f"Error: {args.dir} is not a directory", file=sys.stderr)
sys.exit(1)
count = process_directory(args.dir, recursive=not args.no_recursive)
print(f"Processed {count} file(s)")
elif args.input == "-" or args.input is None:
# Read from stdin, write to stdout
content = sys.stdin.read()
converted = convert_admonitions(content)
sys.stdout.write(converted)
else:
# Process single file
input_path = Path(args.input)
if not input_path.is_file():
print(f"Error: {input_path} is not a file", file=sys.stderr)
sys.exit(1)
output_path = Path(args.output) if args.output else None
process_file(input_path, output_path)
if output_path:
print(f"Converted: {input_path} -> {output_path}")
else:
print(f"Converted: {input_path} (in-place)")
if __name__ == "__main__":
main()
...@@ -234,7 +234,7 @@ Key customization points include: ...@@ -234,7 +234,7 @@ Key customization points include:
- **[Operator Documentation](dynamo-operator.md)** - How the platform works - **[Operator Documentation](dynamo-operator.md)** - How the platform works
- **[Service Discovery](service-discovery.md)** - Discovery backends and configuration - **[Service Discovery](service-discovery.md)** - Discovery backends and configuration
- **[Helm Charts](https://github.com/ai-dynamo/dynamo/tree/main/deploy/helm/README.md)** - For advanced users - **[Helm Charts](https://github.com/ai-dynamo/dynamo/tree/main/deploy/helm/README.md)** - For advanced users
- **[Checkpointing](/docs/kubernetes/chrek/README.md)** - Fast pod startup with checkpoint/restore - **[Checkpointing](chrek/dynamo.md)** - Fast pod startup with checkpoint/restore
- **[GitOps Deployment with FluxCD](fluxcd.md)** - For advanced users - **[GitOps Deployment with FluxCD](fluxcd.md)** - For advanced users
- **[Logging](observability/logging.md)** - For logging setup - **[Logging](observability/logging.md)** - For logging setup
- **[Multinode Deployment](deployment/multinode-deployment.md)** - For multinode deployment - **[Multinode Deployment](deployment/multinode-deployment.md)** - For multinode deployment
......
<!-- ---
SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
#
Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
You may obtain a copy of the License at # You may obtain a copy of the License at
#
http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
#
Unless required by applicable law or agreed to in writing, software # Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, # distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
limitations under the License. # limitations under the License.
--> ---
# Checkpoint/Restore for Fast Pod Startup # Checkpoint/Restore for Fast Pod Startup
......
...@@ -675,8 +675,8 @@ securityContext: ...@@ -675,8 +675,8 @@ securityContext:
## Additional Resources ## Additional Resources
- [ChReK Helm Chart Values](../../deploy/helm/charts/chrek/values.yaml) - [ChReK Helm Chart Values](https://github.com/ai-dynamo/dynamo/tree/main/deploy/helm/charts/chrek/values.yaml)
- [Smart Entrypoint Script](../../deploy/chrek/scripts/smart-entrypoint.sh) - [Smart Entrypoint Script](https://github.com/ai-dynamo/dynamo/tree/main/deploy/chrek/scripts/smart-entrypoint.sh)
- [CRIU Documentation](https://criu.org/Main_Page) - [CRIU Documentation](https://criu.org/Main_Page)
- [CUDA Checkpoint Plugin](https://docs.nvidia.com/cuda/cuda-checkpoint-plugin/) - [CUDA Checkpoint Plugin](https://docs.nvidia.com/cuda/cuda-checkpoint-plugin/)
......
<!-- ---
SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. # SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES.
All rights reserved. # All rights reserved.
SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
--> ---
# Mocker: LLM Engine Simulation in Rust # Mocker: LLM Engine Simulation in Rust
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment