Skip to content

Commit 2c8b2e1

Browse files
committed
ci: auto-sync CLI docs to docs repo on release
1 parent 3ef6271 commit 2c8b2e1

2 files changed

Lines changed: 81 additions & 3 deletions

File tree

.github/workflows/release.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,79 @@ jobs:
5050

5151
- name: Publish to npm
5252
run: pnpm publish --no-git-checks
53+
54+
sync-docs:
55+
needs: release
56+
if: ${{ needs.release.outputs.release_created == 'true' }}
57+
runs-on: ubuntu-slim
58+
permissions:
59+
contents: read
60+
steps:
61+
- name: Checkout rl-cli
62+
uses: actions/checkout@v6
63+
with:
64+
path: rl-cli
65+
66+
- name: Setup pnpm
67+
uses: pnpm/action-setup@v5
68+
69+
- name: Setup Node.js
70+
uses: actions/setup-node@v6
71+
with:
72+
node-version: "24"
73+
cache: "pnpm"
74+
cache-dependency-path: rl-cli/pnpm-lock.yaml
75+
76+
- name: Install dependencies
77+
run: pnpm install --frozen-lockfile
78+
working-directory: rl-cli
79+
80+
- name: Build
81+
run: pnpm run build
82+
working-directory: rl-cli
83+
84+
- name: Generate CLI docs
85+
run: node scripts/generate-command-docs.js --skip-readme --docs-path "$GITHUB_WORKSPACE/rl-cli.mdx"
86+
working-directory: rl-cli
87+
88+
- name: Create GitHub App token
89+
id: app-token
90+
uses: actions/create-github-app-token@v2
91+
with:
92+
app-id: ${{ vars.DEPLOY_APP_CLIENT_ID }}
93+
private-key: ${{ secrets.DEPLOY_APP_PRIVATE_KEY }}
94+
repositories: docs
95+
permission-contents: write
96+
permission-pull-requests: write
97+
98+
- name: Get GitHub App User ID
99+
id: get-user-id
100+
env:
101+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
102+
run: echo "user-id=$(gh api "/users/${{ steps.app-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
103+
104+
- name: Checkout docs repo
105+
uses: actions/checkout@v6
106+
with:
107+
repository: runloopai/docs
108+
token: ${{ steps.app-token.outputs.token }}
109+
path: docs
110+
111+
- name: Copy generated docs
112+
run: cp "$GITHUB_WORKSPACE/rl-cli.mdx" docs/docs/tools/rl-cli.mdx
113+
114+
- name: Create Pull Request
115+
uses: runloopai/create-pull-request@main
116+
with:
117+
token: ${{ steps.app-token.outputs.token }}
118+
path: docs
119+
commit-message: "docs: update rl-cli command reference for ${{ needs.release.outputs.tag_name }}"
120+
committer: "${{ steps.app-token.outputs.app-slug }}[bot] <${{ steps.get-user-id.outputs.user-id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com>"
121+
author: "${{ steps.app-token.outputs.app-slug }}[bot] <${{ steps.get-user-id.outputs.user-id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com>"
122+
title: "docs: update rl-cli command reference for ${{ needs.release.outputs.tag_name }}"
123+
body: |
124+
Auto-generated from [rl-cli ${{ needs.release.outputs.tag_name }}](https://github.com/runloopai/rl-cli/releases/tag/${{ needs.release.outputs.tag_name }}).
125+
126+
Updates the CLI command reference documentation to match the latest release.
127+
branch: rl-cli-docs/${{ needs.release.outputs.tag_name }}
128+
delete-branch: true

scripts/generate-command-docs.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -510,8 +510,8 @@ The Runloop CLI is open-source. We welcome contributions!
510510
/**
511511
* Updates the external docs rl-cli.mdx file
512512
*/
513-
function updateDocsMdx(program, docsPath) {
514-
if (!existsSync(docsPath)) {
513+
function updateDocsMdx(program, docsPath, explicitPath) {
514+
if (!explicitPath && !existsSync(docsPath)) {
515515
console.log(`⚠️ Docs file not found at ${docsPath}, skipping docs update`);
516516
console.log(" Set DOCS_PATH env var or use --docs-path to specify location");
517517
return false;
@@ -530,13 +530,15 @@ function parseArgs() {
530530
const args = process.argv.slice(2);
531531
const options = {
532532
docsPath: process.env.DOCS_PATH || defaultDocsPath,
533+
explicitDocsPath: !!process.env.DOCS_PATH,
533534
skipReadme: false,
534535
skipDocs: false,
535536
};
536537

537538
for (let i = 0; i < args.length; i++) {
538539
if (args[i] === "--docs-path" && args[i + 1]) {
539540
options.docsPath = args[i + 1];
541+
options.explicitDocsPath = true;
540542
i++;
541543
} else if (args[i] === "--skip-readme") {
542544
options.skipReadme = true;
@@ -573,7 +575,7 @@ async function main() {
573575
}
574576

575577
if (!options.skipDocs) {
576-
updateDocsMdx(program, options.docsPath);
578+
updateDocsMdx(program, options.docsPath, options.explicitDocsPath);
577579
}
578580
} catch (error) {
579581
console.error("Error generating command docs:", error);

0 commit comments

Comments
 (0)