Skip to content

Commit b8bdf2d

Browse files
nearestnaborsclaude
andcommitted
Add CI workflow to regenerate clean markdown files
Adds a GitHub Action that runs when MDX files are changed in PRs. The workflow builds the site, generates clean markdown, and commits any changes back to the PR branch automatically. Also updates postbuild to support SKIP_POSTBUILD env var to avoid circular dependency in CI. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 21e0415 commit b8bdf2d

File tree

2 files changed

+89
-1
lines changed

2 files changed

+89
-1
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
name: Generate Clean Markdown
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
types: [opened, synchronize, reopened]
7+
paths:
8+
- "app/**/*.mdx"
9+
- "app/**/_meta.tsx"
10+
- "scripts/generate-clean-markdown.ts"
11+
12+
permissions:
13+
contents: write
14+
pull-requests: write
15+
16+
jobs:
17+
generate-markdown:
18+
name: Generate Clean Markdown
19+
runs-on: ubuntu-latest
20+
21+
permissions:
22+
contents: write
23+
pull-requests: write
24+
25+
steps:
26+
- name: Use Node.js
27+
uses: actions/setup-node@v4
28+
with:
29+
node-version: "22.x"
30+
31+
- name: Checkout code
32+
uses: actions/checkout@v4
33+
with:
34+
ref: ${{ github.event.pull_request.head.ref || github.ref }}
35+
token: ${{ secrets.DOCS_PUBLISHABLE_GH_TOKEN }}
36+
37+
- name: Install pnpm
38+
run: npm install -g pnpm
39+
40+
- name: Install dependencies
41+
run: pnpm install
42+
43+
- name: Build Next.js
44+
run: pnpm build
45+
env:
46+
# Skip postbuild to avoid circular dependency
47+
SKIP_POSTBUILD: "true"
48+
49+
- name: Generate clean markdown
50+
run: pnpm generate:markdown
51+
52+
- name: Check for changes
53+
id: check-changes
54+
run: |
55+
if [ -n "$(git status --porcelain public/_markdown/)" ]; then
56+
echo "has_changes=true" >> $GITHUB_OUTPUT
57+
else
58+
echo "has_changes=false" >> $GITHUB_OUTPUT
59+
fi
60+
61+
- name: Commit changes to PR
62+
if: steps.check-changes.outputs.has_changes == 'true' && github.event_name == 'pull_request'
63+
run: |
64+
git config user.name "github-actions[bot]"
65+
git config user.email "github-actions[bot]@users.noreply.github.com"
66+
git add public/_markdown/
67+
git commit -m "Regenerate clean markdown files"
68+
git push
69+
70+
- name: Create Pull Request (for manual runs)
71+
if: steps.check-changes.outputs.has_changes == 'true' && github.event_name != 'pull_request'
72+
id: cpr
73+
uses: peter-evans/create-pull-request@v7
74+
with:
75+
token: ${{ secrets.DOCS_PUBLISHABLE_GH_TOKEN }}
76+
commit-message: Regenerate clean markdown files
77+
branch: auto-update-clean-markdown
78+
delete-branch: true
79+
title: "Regenerate clean markdown files"
80+
reviewers: >
81+
evantahler
82+
torresmateo
83+
84+
- name: Enable Pull Request Automerge
85+
if: steps.check-changes.outputs.has_changes == 'true' && github.event_name != 'pull_request'
86+
run: gh pr merge --squash --auto ${{ steps.cpr.outputs.pull-request-number }}
87+
env:
88+
GH_TOKEN: ${{ secrets.DOCS_PUBLISHABLE_GH_TOKEN }}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"lint": "pnpm dlx ultracite check",
1111
"format": "pnpm dlx ultracite fix",
1212
"prepare": "husky install",
13-
"postbuild": "pnpm run generate:markdown && pnpm run custompagefind",
13+
"postbuild": "if [ \"$SKIP_POSTBUILD\" != \"true\" ]; then pnpm run generate:markdown && pnpm run custompagefind; fi",
1414
"generate:markdown": "pnpm dlx tsx scripts/generate-clean-markdown.ts",
1515
"translate": "pnpm dlx tsx scripts/i18n-sync/index.ts && pnpm format",
1616
"sync:metas": "pnpm dlx tsx scripts/sync-metas.ts app/en",

0 commit comments

Comments
 (0)