Skip to content

feat: genlayercli api reference auto generated#247

Merged
cristiam86 merged 7 commits into
mainfrom
dxp-525-genlayercli-api-reference-auto-generated
Sep 3, 2025
Merged

feat: genlayercli api reference auto generated#247
cristiam86 merged 7 commits into
mainfrom
dxp-525-genlayercli-api-reference-auto-generated

Conversation

@epsjunior

@epsjunior epsjunior commented Aug 11, 2025

Copy link
Copy Markdown
Contributor

Add Automated CLI Docs Generation and Sync

Summary

Implements automatic GenlayerCLI command reference generation and synchronization:

  • Generates MDX docs from the built CLI help output on every release.
  • Commits updated docs back into this repo under docs/api-references.
  • Opens a PR to the documentation site syncing the same files to pages/api-references/genlayer-cli.
    This eliminates manual drift between CLI changes and documentation.

Changes

🚀 New Features

  • Auto-generated CLI Reference: Builds MDX pages for all commands, arguments, and options.
  • Dual Sync:
    • Commits docs to this repo on release (non-beta).
    • Creates a PR in the docs repo with the same generated pages.
  • Stable Output Paths: Writes to docs/api-references locally and in CI.

🔧 Implementation Details

  • Help-driven generator: Parses node dist/index.js --help (and each subcommand’s help) to extract command metadata. Avoids importing source or changing the CLI entry.
  • Clean runs in CI: Uses DOCS_CLEAN=true to remove stale pages when commands are removed/renamed.
  • Version awareness: Uses release tag when running in release context; package.json version otherwise (configurable later if needed).

📁 File Structure

scripts/
└── generate-cli-docs.mjs      # Help-driven MDX generator

.github/workflows/
├── cli-docs.yml               # Build → generate → commit back to CLI → PR to docs repo
└── publish.yml                # Paths ignore for docs-only commits; no docs generation here

docs/
└── api-references/            # Generated MDX pages and _meta.json live here

🏗️ Architecture

  • Source of truth: Commander help output from the built dist/index.js.
  • Generation: BFS over root and subcommand help; renders Usage, Arguments, Options, and Subcommands into MDX.
  • Sync:
    • CLI repo: commit docs/api-references on non-beta releases.
    • Docs repo: rsync to pages/api-references/genlayer-cli and open a PR.

🧪 Testing

  • Local verification:
    • npm run build && npm run docs:cli produces MDX files under docs/api-references.
  • CI verification:
    • On release (non-beta), workflow commits changes in this repo.
    • Also pushes a PR to the docs repo with synchronized files.

🔧 Usage

# Local generation (no clean, incremental)
npm run build
npm run docs:cli

# Clean generation locally
DOCS_CLEAN=true npm run docs:cli

✨ Code Quality

  • No changes to CLI entry (src/index.ts) or command registrations.
  • Generator is isolated, robust against Commander internals by parsing help text.
  • Conventional commit messages used by CI for clarity:
    • CLI repo: docs(cli): update API reference for <version>
    • Docs repo PR: docs(cli): sync API reference <version>

🔗 Dependencies

  • Reuses existing build pipeline (dist/index.js).
  • No new runtime deps for the CLI; generator uses Node stdlib.

🛡️ Backward Compatibility

  • No breaking changes to commands.
  • Only adds docs-related scripts and workflows.
  • publish workflow ignores docs/** changes to prevent re-trigger loops.

📚 Documentation Updates

  • New auto-generated section at docs/api-references/.
  • Docs repo gets a PR that places the same content at pages/api-references/genlayer-cli.

Testing: ✅ Verified locally and via workflow design
Safety: ✅ No changes to runtime CLI behavior
DX: ✅ Eliminates manual docs updates, keeps docs current on releases

Summary by CodeRabbit

  • New Features

    • Automated CLI docs generation producing per-command pages and a versioned index.
  • Documentation

    • Adds comprehensive, auto-generated MDX CLI reference with source/version metadata and an autogenerated notice.
  • Chores

    • CI workflow to generate, sync, and open PRs to the docs repo; release workflow now ignores docs-only pushes; npm script to run the docs generator.

@coderabbitai

coderabbitai Bot commented Aug 11, 2025

Copy link
Copy Markdown

Walkthrough

Adds a GitHub Actions workflow to generate and sync CLI MDX docs to the genlayer-docs repo on release or manual dispatch, adds an npm script to run a new Node script, implements a Node-based CLI help parser that emits MDX pages into docs/api-references, and updates the publish workflow to ignore docs/** pushes.

Changes

Cohort / File(s) Summary
CLI docs workflow
.github/workflows/cli-docs.yml
New workflow "Generate CLI Docs and PR to genlayer-docs": builds the CLI, runs the docs generator, commits API refs back to the CLI repo for non-beta releases (when applicable), syncs generated MDX into the genlayer-docs repository, and opens a PR if changes are found.
Docs generator & npm script
scripts/generate-cli-docs.mjs, package.json
Adds scripts/generate-cli-docs.mjs which invokes the CLI (--help) in BFS fashion to parse commands, options, arguments and emit MDX pages plus _meta.json under docs/api-references (configurable). Adds docs:cli npm script to run the generator.
Publish workflow tweak
.github/workflows/publish.yml
Adds paths-ignore: docs/** to the push trigger so docs-only changes do not trigger the release workflow.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Maintainer
  participant GH as GitHub Actions (CLI Repo)
  participant CLI as CLI Project
  participant Docs as genlayer-docs Repo
  participant PR as PR Creator

  Maintainer->>GH: workflow_dispatch or release published
  GH->>CLI: checkout, setup Node, npm install, build
  GH->>CLI: run npm run docs:cli
  GH->>CLI: generate MDX under docs/api-references
  alt non-beta release or manual dispatch
    GH->>CLI: commit & push API refs to CLI repo (if changed)
  end
  GH->>Docs: checkout docs repo into branch docs/cli/...
  GH->>Docs: rsync generated MDX to pages/api-references/genlayer-cli/
  GH->>Docs: commit & push branch if changes
  GH->>PR: create PR (if changes)
Loading
sequenceDiagram
  autonumber
  participant Gen as generate-cli-docs.mjs
  participant CLI as dist/index.js --help
  participant FS as Filesystem

  Gen->>FS: read package.json (name, version, description)
  Gen->>CLI: run --help for root command
  Gen->>Gen: parse description, usage, options, subcommands, args
  loop BFS over commands
    Gen->>CLI: run --help for subcommand
    Gen->>Gen: parse and collect command info
    Gen->>FS: write MDX page for command (docs/api-references/...)
  end
  Gen->>FS: write index MDX and _meta.json
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

I hop through flags and usage lines,
I parse each command with tiny designs.
Branches sprout from generated dreams,
MDX leaves flutter in sync and streams.
I push a PR — then nibble on greens. 🥕🐇


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 447e8c3 and e1ba9fd.

📒 Files selected for processing (1)
  • scripts/generate-cli-docs.mjs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • scripts/generate-cli-docs.mjs
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dxp-525-genlayercli-api-reference-auto-generated

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (2)
scripts/generate-cli-docs.mjs (1)

175-179: Log errors instead of silently swallowing them

The empty catch block silently ignores all errors, which could hide important issues during cleanup.

 async function rmrf(dir) {
   try {
     await fs.rm(dir, { recursive: true, force: true });
-  } catch {}
+  } catch (err) {
+    console.warn(`Warning: Failed to remove directory ${dir}:`, err.message);
+  }
 }
.github/workflows/cli-docs.yml (1)

121-121: Remove extra blank line at end of file

-          labels: documentation, cli
-
-
+          labels: documentation, cli
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b2f0e99 and 8c7b22e.

📒 Files selected for processing (4)
  • .github/workflows/cli-docs.yml (1 hunks)
  • .github/workflows/publish.yml (1 hunks)
  • package.json (1 hunks)
  • scripts/generate-cli-docs.mjs (1 hunks)
🧰 Additional context used
🪛 actionlint (1.7.7)
.github/workflows/cli-docs.yml

110-110: could not parse as YAML: yaml: line 110: mapping values are not allowed in this context

(syntax-check)

🪛 YAMLlint (1.37.1)
.github/workflows/cli-docs.yml

[warning] 121-121: too many blank lines (2 > 0)

(empty-lines)


[error] 110-110: syntax error: mapping values are not allowed here

(syntax)

🔇 Additional comments (3)
.github/workflows/publish.yml (1)

8-9: LGTM!

Appropriately excludes documentation-only changes from triggering the release workflow, preventing unnecessary release cycles.

package.json (1)

18-19: LGTM!

The new docs:cli script is properly defined and the formatting is consistent with the file structure.

.github/workflows/cli-docs.yml (1)

90-102: Fix undefined VERSION variable reference

Line 96 references ${VERSION:-${{ env.VERSION }}} but VERSION is not defined in this shell context. Use the step output directly.

-            git commit -m "docs(cli): sync API reference ${VERSION:-${{ env.VERSION }}}"
+            git commit -m "docs(cli): sync API reference ${{ steps.version.outputs.value }}"

Likely an incorrect or invalid review comment.

Comment thread .github/workflows/cli-docs.yml
Comment thread scripts/generate-cli-docs.mjs
Comment thread scripts/generate-cli-docs.mjs
@cristiam86 cristiam86 merged commit b08c342 into main Sep 3, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants