Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions .github/workflows/generate-node-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: Generate Node Documentation

# Trigger this action after a release is published
on:
release:
types:
- published
workflow_dispatch:

permissions:
contents: write

env:
USER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
USER_NAME: github-actions[bot]
USER_EMAIL: github-actions[bot]@users.noreply.github.com
OWNER: ${{ github.event.repository.owner.login }}
REPOSITORY_NAME: ${{ github.event.repository.name }}

jobs:
generate-and-publish:
name: Generate and publish node documentation
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18
cache: 'npm'

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Install Node dependencies
run: npm ci

- name: Start backend and generate node documentation
run: |
# Start backend in background
python ./backend/src/run.py 8765 --install-builtin-packages > /tmp/backend.log 2>&1 &
BACKEND_PID=$!

# Wait for backend to be ready (up to 3 minutes)
echo "Waiting for backend to start..."
for i in {1..90}; do
if curl -s http://127.0.0.1:8765/health > /dev/null 2>&1; then
echo "Backend is ready!"
break
fi
if [ $i -eq 90 ]; then
echo "Backend failed to start within 3 minutes"
cat /tmp/backend.log
kill $BACKEND_PID || true
exit 1
fi
sleep 2
done

# Generate documentation
python scripts/generate_node_docs.py --url http://127.0.0.1:8765

# Stop backend
kill $BACKEND_PID || true

- name: Pull wiki content
run: |
mkdir tmp_wiki
cd tmp_wiki
git init
git config user.name "$USER_NAME"
git config user.email "$USER_EMAIL"
git remote add origin https://x-access-token:${USER_TOKEN}@github.com/${OWNER}/${REPOSITORY_NAME}.wiki.git
git fetch origin
git checkout master || git checkout -b master
git pull origin master || echo "Wiki is empty, will create initial commit"

- name: Update wiki with generated docs
run: |
# Copy all documentation files
rsync -av --delete docs/ tmp_wiki/ --exclude .git
cd tmp_wiki
git add .
git diff --staged --quiet || git commit -m "Update node documentation (automated from release ${{ github.ref_name }})"
git push origin master
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,6 @@ dmypy.json

# traces
backend/traces

# Generated node documentation
docs/nodes/
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,5 @@ For FAQ information, view the [FAQ document](https://github.com/chaiNNer-org/cha

For in-depth documentation covering various aspects of ChaiNNer, including CLI usage, data representation, and a contributor's guide, kindly refer to our [ChaiNNer Wiki](https://github.com/chaiNNer-org/chaiNNer/wiki).

A complete reference of all available nodes can be found in the [Nodes Reference](https://github.com/chaiNNer-org/chaiNNer/wiki/08--Nodes-Reference) section of the wiki. This documentation is automatically generated from the latest release and includes detailed information about all available filters, functions, and their parameters.

5 changes: 5 additions & 0 deletions docs/08--Nodes-Reference.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# chaiNNer Nodes Documentation

This documentation lists all nodes available in chaiNNer, organized by category.

## Categories
87 changes: 87 additions & 0 deletions scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Node Documentation Generation Scripts

This directory contains scripts for generating markdown documentation for all chaiNNer nodes.

## Scripts

### `generate_node_docs.py`

Main script that generates markdown documentation files from node data.

**Usage:**

```bash
# Fetch from a running backend server
python generate_node_docs.py --url http://127.0.0.1:8000

# Generate from a JSON file
python generate_node_docs.py --file nodes_data.json

# Automatically start backend server
python generate_node_docs.py --start-server --server-port 8765

# Specify custom output directory
python generate_node_docs.py --file nodes_data.json --output-dir ./custom_docs
```

**Output:**

The script generates:
- `docs/08--Nodes-Reference.md` - Main index file listing all categories
- `docs/nodes/<category_id>.md` - One file per category with all nodes in that category

### `fetch_nodes.py`

Helper script to fetch node data from a running backend server and save to JSON.

**Usage:**

```bash
# Fetch from default server (http://127.0.0.1:8000)
python fetch_nodes.py

# Fetch from custom server
python fetch_nodes.py http://127.0.0.1:8765 output.json
```

## Automated Documentation Updates

The `.github/workflows/generate-node-docs.yml` workflow automatically:
1. Runs after each release is published
2. Starts the backend server with all packages installed
3. Fetches node data and generates markdown documentation
4. Updates the GitHub Wiki with the generated documentation

## Local Development

To generate documentation locally:

1. Start the backend server:
```bash
cd backend/src
python run.py 8000 --install-builtin-packages
```

2. In another terminal, generate docs:
```bash
python scripts/generate_node_docs.py
```

Or use the automated approach:
```bash
python scripts/generate_node_docs.py --start-server
```

## Output Format

Each category file contains:
- Category name and description
- Node groups within the category
- For each node:
- Name and Schema ID
- Description
- Icon
- Input parameters with types and descriptions
- Output types
- See Also references
- Deprecation warnings (if applicable)
37 changes: 37 additions & 0 deletions scripts/fetch_nodes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env python3
"""
Simple script to export node data to JSON file.
This can be run after the backend has started to capture node data.
"""

from __future__ import annotations

import json
import sys
import urllib.request
import urllib.error
from pathlib import Path

def fetch_and_save_nodes(server_url: str, output_file: Path):
"""Fetch node data and save to JSON."""
try:
print(f"Fetching nodes from {server_url}/nodes...")
response = urllib.request.urlopen(f"{server_url}/nodes", timeout=60)
data = json.loads(response.read().decode('utf-8'))

# Save to file
with open(output_file, 'w', encoding='utf-8') as f:
json.dump(data, f, indent=2)

print(f"Saved {len(data.get('nodes', []))} nodes to {output_file}")
return 0
except Exception as e:
print(f"Error: {e}")
import traceback
traceback.print_exc()
return 1

if __name__ == "__main__":
server_url = sys.argv[1] if len(sys.argv) > 1 else "http://127.0.0.1:8000"
output_file = Path(sys.argv[2]) if len(sys.argv) > 2 else Path("nodes_data.json")
sys.exit(fetch_and_save_nodes(server_url, output_file))
Loading