Making some QUICK updates to the docs (oops!) #11
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: Validate Documentation | |
| on: | |
| pull_request: | |
| types: [opened, synchronize, reopened] # Run on PR open AND every commit | |
| branches: | |
| - main | |
| paths: | |
| - '**.mdx' | |
| - '**.md' | |
| - 'images/**' | |
| - 'scripts/**' | |
| - '.github/workflows/validate-docs.yml' | |
| jobs: | |
| validate: | |
| name: Check Links and Images | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '18' | |
| - name: Check for broken links | |
| id: check-links | |
| run: | | |
| echo "::group::Checking for broken links" | |
| node scripts/check-links.js > /tmp/check-links-output.txt 2>&1 || echo "issues_found=true" >> $GITHUB_OUTPUT | |
| cat /tmp/check-links-output.txt | |
| echo "::endgroup::" | |
| continue-on-error: true | |
| - name: Check image locations | |
| id: check-images | |
| run: | | |
| echo "::group::Checking image locations" | |
| node scripts/check-image-locations.js > /tmp/check-images-output.txt 2>&1 || echo "issues_found=true" >> $GITHUB_OUTPUT | |
| cat /tmp/check-images-output.txt | |
| echo "::endgroup::" | |
| continue-on-error: true | |
| - name: Post or update PR comment | |
| if: always() # Always run to update comment even if issues are fixed | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const fs = require('fs'); | |
| // Build comment body | |
| let comment = '## π Documentation Validation Report\n\n'; | |
| const hasIssues = '${{ steps.check-links.outputs.issues_found }}' === 'true' || | |
| '${{ steps.check-images.outputs.issues_found }}' === 'true'; | |
| if (hasIssues) { | |
| comment += 'β οΈ Some issues were found in this PR. These are **informational warnings** and will not block merging.\n\n'; | |
| } else { | |
| comment += 'β All validation checks passed!\n\n'; | |
| } | |
| if ('${{ steps.check-links.outputs.issues_found }}' === 'true') { | |
| const linksOutput = fs.readFileSync('/tmp/check-links-output.txt', 'utf8'); | |
| const lines = linksOutput.split('\n'); | |
| const brokenLinks = lines.filter(line => line.includes('Broken link:') || line.includes('π')).slice(0, 10); | |
| comment += '### π Links\n'; | |
| if (brokenLinks.length > 0) { | |
| comment += '<details><summary>β Found broken links (click to expand)</summary>\n\n'; | |
| comment += '```\n' + brokenLinks.join('\n') + '\n```\n'; | |
| comment += '</details>\n\n'; | |
| } | |
| } else { | |
| comment += '### π Links\nβ All links valid\n\n'; | |
| } | |
| if ('${{ steps.check-images.outputs.issues_found }}' === 'true') { | |
| const imagesOutput = fs.readFileSync('/tmp/check-images-output.txt', 'utf8'); | |
| const lines = imagesOutput.split('\n'); | |
| const imageIssues = lines.filter(line => line.includes('π') || line.includes('Expected in:')).slice(0, 10); | |
| comment += '### πΌοΈ Images\n'; | |
| if (imageIssues.length > 0) { | |
| comment += '<details><summary>β Found image location issues (click to expand)</summary>\n\n'; | |
| comment += '```\n' + imageIssues.join('\n') + '\n```\n'; | |
| comment += '</details>\n\n'; | |
| } | |
| } else { | |
| comment += '### πΌοΈ Images\nβ All images in correct locations\n\n'; | |
| } | |
| comment += '---\n'; | |
| comment += 'π‘ **Quick Reference:**\n'; | |
| comment += '- A page at `guides/dashboard.mdx` should use images from `images/guides/dashboard/`\n'; | |
| comment += '- Shared images can be placed in parent directories\n'; | |
| comment += '- All internal links must point to existing files\n\n'; | |
| comment += 'π Run `node scripts/check-links.js` and `node scripts/check-image-locations.js` locally for full details.\n'; | |
| // Find existing comment from this bot | |
| const { data: comments } = await github.rest.issues.listComments({ | |
| issue_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| }); | |
| const botComment = comments.find(c => | |
| c.user.type === 'Bot' && c.body.includes('π Documentation Validation Report') | |
| ); | |
| // Update existing or create new | |
| if (botComment) { | |
| await github.rest.issues.updateComment({ | |
| comment_id: botComment.id, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body: comment | |
| }); | |
| } else { | |
| await github.rest.issues.createComment({ | |
| issue_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body: comment | |
| }); | |
| } | |
| - name: Report results | |
| if: always() | |
| run: | | |
| if [ "${{ steps.check-links.outputs.issues_found }}" == "true" ] || [ "${{ steps.check-images.outputs.issues_found }}" == "true" ]; then | |
| echo "## Documentation Validation Warnings β οΈ" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "Issues found - see PR comment for details" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "## Documentation Validation Passed β " >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "All links are valid and images are in the correct locations!" >> $GITHUB_STEP_SUMMARY | |
| fi |