Run LLM Ingestion Checks for Docs #22297
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Run LLM Ingestion Checks for Docs | |
| on: | |
| deployment_status: | |
| jobs: | |
| check-docs: | |
| # Only run when Vercel reports a successful deploy | |
| if: >- | |
| github.event.deployment_status.state == 'success' && | |
| contains(github.event.deployment_status.environment_url, 'vercel.app') | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Find associated PR | |
| id: find-pr | |
| uses: actions/github-script@v7 | |
| with: | |
| result-encoding: string | |
| script: | | |
| const sha = context.payload.deployment.sha; | |
| const prs = await github.rest.repos.listPullRequestsAssociatedWithCommit({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| commit_sha: sha, | |
| }); | |
| const openPr = prs.data.find(pr => pr.state === 'open' && pr.base.ref === 'main'); | |
| return openPr ? String(openPr.number) : ''; | |
| - name: Check if PR touches docs | |
| if: steps.find-pr.outputs.result != '' | |
| id: check-docs-changed | |
| uses: actions/github-script@v7 | |
| with: | |
| result-encoding: string | |
| script: | | |
| const prNumber = parseInt(process.env.PR_NUMBER); | |
| const files = await github.paginate( | |
| github.rest.pulls.listFiles, | |
| { | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| pull_number: prNumber, | |
| per_page: 100, | |
| } | |
| ); | |
| const touchesDocs = files.some(f => f.filename.startsWith('docs/')); | |
| return touchesDocs ? 'true' : 'false'; | |
| env: | |
| PR_NUMBER: ${{ steps.find-pr.outputs.result }} | |
| - name: Setup Node | |
| if: steps.check-docs-changed.outputs.result == 'true' | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 22 | |
| - name: Run afdocs check | |
| if: steps.check-docs-changed.outputs.result == 'true' | |
| id: afdocs | |
| run: | | |
| OUTPUT=$(npx --yes afdocs@0.6.0 check "$URL" --max-links 1000 2>&1) || true | |
| echo "result<<EOF" >> $GITHUB_OUTPUT | |
| echo "$OUTPUT" >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| env: | |
| URL: ${{ github.event.deployment_status.environment_url }} | |
| - name: Comment on PR | |
| if: steps.check-docs-changed.outputs.result == 'true' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const marker = '<!-- afdocs-check -->'; | |
| const url = process.env.URL; | |
| const output = process.env.OUTPUT; | |
| const prNumber = parseInt(process.env.PR_NUMBER); | |
| const body = [ | |
| marker, | |
| '## 📋 afdocs check results', | |
| `**URL:** ${url}`, | |
| '```', | |
| output, | |
| '```', | |
| ].join('\n'); | |
| // Find existing comment by hidden marker | |
| const comments = await github.paginate( | |
| github.rest.issues.listComments, | |
| { | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: prNumber, | |
| per_page: 100, | |
| } | |
| ); | |
| const existing = comments.find(c => c.body?.includes(marker)); | |
| if (existing) { | |
| await github.rest.issues.updateComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: existing.id, | |
| body, | |
| }); | |
| } else { | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: prNumber, | |
| body, | |
| }); | |
| } | |
| env: | |
| URL: ${{ github.event.deployment_status.environment_url }} | |
| OUTPUT: ${{ steps.afdocs.outputs.result }} | |
| PR_NUMBER: ${{ steps.find-pr.outputs.result }} |