|
| 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 }} |
0 commit comments