Skip to content

Commit 33083bb

Browse files
committed
Move CLI docs generator to scheduled action
Currently, generating CLI docs is part of the main CI action. Whenever someone opens a pull request, the bot fetches the latest CLI, generates new docs, and inserts a commit into the PR. The extra commit makes PRs noisier to review and can cause merge conflicts. Instead, run the generator on a weekly schedule. The action has its own branch: `actions/update-cli-docs`. Every monday, the action will checkout main, run the CLI tests, update the docs with the week's CLI changes, and force push to the branch. Finally, the bot either opens a new PR, or updates the previous week's if it hasn't been merged yet.
1 parent c350c2e commit 33083bb

File tree

2 files changed

+91
-90
lines changed

2 files changed

+91
-90
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
- '*.md'
99

1010
permissions:
11-
contents: write
11+
contents: read
1212
pull-requests: write
1313

1414
jobs:
@@ -39,98 +39,9 @@ jobs:
3939
- name: Lint
4040
run: pnpm lint
4141

42-
- name: Install Sprites CLI
43-
run: |
44-
curl -fsSL https://sprites.dev/install.sh | bash
45-
echo "$HOME/.local/bin" >> $GITHUB_PATH
46-
47-
- name: Setup Sprites auth
48-
run: sprite auth setup --token "$SPRITES_TEST_TOKEN"
49-
env:
50-
SPRITES_TEST_TOKEN: ${{ secrets.SPRITES_TEST_TOKEN }}
51-
52-
- name: Generate CLI Docs
53-
run: pnpm generate:cli-docs
54-
env:
55-
SKIP_CLI_TESTS: 'true'
56-
57-
- name: Commit generated CLI docs
58-
run: |
59-
git config user.name "github-actions[bot]"
60-
git config user.email "github-actions[bot]@users.noreply.github.com"
61-
git add src/content/docs/cli/commands.mdx
62-
if git diff --cached --quiet; then
63-
echo "No changes to CLI docs"
64-
else
65-
git commit -m "Update auto-generated CLI documentation"
66-
git push
67-
fi
68-
6942
- name: Build
7043
run: pnpm build
7144

72-
- name: Comment CLI Test Results on PR
73-
if: always() && github.event_name == 'pull_request'
74-
uses: actions/github-script@v7
75-
with:
76-
script: |
77-
const fs = require('fs');
78-
const path = './cli-test-report.json';
79-
80-
let body = '### CLI Documentation Generator\n\n';
81-
82-
if (!fs.existsSync(path)) {
83-
body += '⚠️ No test report found (tests may have been skipped)\n';
84-
} else {
85-
const report = JSON.parse(fs.readFileSync(path, 'utf8'));
86-
87-
const allPassed = report.testsFailed === 0;
88-
const emoji = allPassed ? '✅' : '❌';
89-
90-
body += `| Metric | Value |\n`;
91-
body += `|--------|-------|\n`;
92-
body += `| CLI Version | \`${report.cliVersion}\` |\n`;
93-
body += `| Commands Generated | ${report.commandsGenerated.length} |\n`;
94-
body += `| Tests | ${emoji} ${report.testsPassed}/${report.testsRun} passed |\n`;
95-
96-
if (report.errors.length > 0) {
97-
body += `\n<details><summary>❌ ${report.errors.length} Error(s)</summary>\n\n`;
98-
for (const error of report.errors) {
99-
body += `- **${error.command}** (${error.phase}): ${error.message}\n`;
100-
}
101-
body += `\n</details>\n`;
102-
}
103-
104-
if (report.commandsGenerated.length > 0) {
105-
body += `\n<details><summary>📚 Commands documented</summary>\n\n`;
106-
body += report.commandsGenerated.map(c => `- \`${c}\``).join('\n');
107-
body += `\n</details>\n`;
108-
}
109-
}
110-
111-
const { data: comments } = await github.rest.issues.listComments({
112-
owner: context.repo.owner,
113-
repo: context.repo.repo,
114-
issue_number: context.issue.number,
115-
});
116-
const existing = comments.find(c => c.body.includes('### CLI Documentation Generator'));
117-
118-
if (existing) {
119-
await github.rest.issues.updateComment({
120-
owner: context.repo.owner,
121-
repo: context.repo.repo,
122-
comment_id: existing.id,
123-
body,
124-
});
125-
} else {
126-
await github.rest.issues.createComment({
127-
owner: context.repo.owner,
128-
repo: context.repo.repo,
129-
issue_number: context.issue.number,
130-
body,
131-
});
132-
}
133-
13445
preview:
13546
name: Preview Deployment
13647
runs-on: ubuntu-latest
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: Update CLI Docs
2+
3+
on:
4+
schedule:
5+
- cron: "0 8 * * 1"
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: write
10+
pull-requests: write
11+
12+
jobs:
13+
update-cli-docs:
14+
name: Update CLI Docs
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
with:
20+
ref: main
21+
token: ${{ secrets.GITHUB_TOKEN }}
22+
23+
- uses: pnpm/action-setup@v4
24+
with:
25+
version: latest
26+
27+
- uses: actions/setup-node@v4
28+
with:
29+
node-version: 22
30+
cache: pnpm
31+
32+
- name: Install dependencies
33+
run: pnpm install --frozen-lockfile
34+
35+
- name: Install Sprites CLI
36+
run: |
37+
curl -fsSL https://sprites.dev/install.sh | bash
38+
echo "$HOME/.local/bin" >> $GITHUB_PATH
39+
40+
- name: Setup Sprites auth
41+
run: sprite auth setup --token "$SPRITES_TEST_TOKEN"
42+
env:
43+
SPRITES_TEST_TOKEN: ${{ secrets.SPRITES_TEST_TOKEN }}
44+
45+
- name: Generate CLI Docs
46+
run: pnpm generate:cli-docs
47+
48+
- name: Check for changes
49+
id: changes
50+
run: |
51+
git diff --quiet src/content/docs/cli/commands.mdx && \
52+
echo "changed=false" >> $GITHUB_OUTPUT || \
53+
echo "changed=true" >> $GITHUB_OUTPUT
54+
55+
- name: Commit and push to automated branch
56+
if: steps.changes.outputs.changed == 'true'
57+
run: |
58+
git config user.name "github-actions[bot]"
59+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
60+
61+
git checkout -B actions/update-cli-docs
62+
git add src/content/docs/cli/commands.mdx
63+
git commit -m "Update auto-generated CLI documentation ($(date -u +%Y-%m-%d))"
64+
65+
git push origin actions/update-cli-docs --force
66+
67+
- name: Open or update PR
68+
if: steps.changes.outputs.changed == 'true'
69+
env:
70+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
71+
run: |
72+
branch="actions/update-cli-docs"
73+
cat > /tmp/pr-body.md << EOF
74+
This PR was automatically generated by the weekly CLI docs update workflow.
75+
76+
Built from $(sprite --version) on $(date -u +%Y-%m-%d)
77+
EOF
78+
79+
pr=$(gh pr list --head "$branch" --state open --json number --jq '.[0].number')
80+
if test -z "$pr"
81+
then
82+
gh pr create \
83+
--title "Update auto-generated CLI documentation" \
84+
--body-file /tmp/pr-body.md \
85+
--head "$branch" \
86+
--base main
87+
else
88+
gh pr edit "$pr" --body-file /tmp/pr-body.md
89+
echo "Updated existing PR #$pr"
90+
fi

0 commit comments

Comments
 (0)