fix broken link #2650
Workflow file for this run
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: Check removed pages have redirects | |
| on: | |
| pull_request: | |
| branches: [main] | |
| jobs: | |
| check-redirects: | |
| name: Verify docs.json (redirects + pages exist) | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 5 | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: Fetch base branch | |
| run: git fetch origin "${{ github.base_ref }}" | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.13" | |
| - name: Get base branch docs.json | |
| run: | | |
| BASE_REF="${{ github.event.pull_request.base.sha }}" | |
| if [ -z "$BASE_REF" ]; then | |
| BASE_REF="origin/${{ github.base_ref }}" | |
| fi | |
| git show "${BASE_REF}:src/docs.json" > base_docs.json | |
| - name: Run docs.json checks | |
| id: check | |
| run: | | |
| set +e | |
| python scripts/check_removed_pages_redirects.py base_docs.json src/docs.json 2> check_output.txt | |
| EXIT_CODE=$? | |
| set -e | |
| echo "exit_code=${EXIT_CODE}" >> $GITHUB_OUTPUT | |
| if [ $EXIT_CODE -eq 0 ]; then | |
| echo "β All pages exist and removed pages have redirects" | |
| else | |
| cat check_output.txt | |
| fi | |
| - name: Comment on PR on failure | |
| if: steps.check.outputs.exit_code == '1' | |
| uses: actions/github-script@v8 | |
| with: | |
| script: | | |
| const fs = require('fs'); | |
| let output = ''; | |
| try { | |
| output = fs.readFileSync('check_output.txt', 'utf8'); | |
| output = output.replace(/[^\x20-\x7E\n\r\t]/g, ''); | |
| if (output.length > 32000) { | |
| output = output.substring(0, 32000) + '\n... (truncated)'; | |
| } | |
| } catch (error) { | |
| output = 'Error reading check output'; | |
| } | |
| const body = `## β docs.json validation failed | |
| This PR has issues with \`docs.json\`: either pages were removed without redirects, or some pages reference non-existent source files. | |
| \`\`\` | |
| ${output} | |
| \`\`\` | |
| `; | |
| const prNumber = context.payload.pull_request.number; | |
| const comments = await github.rest.issues.listComments({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: prNumber, | |
| }); | |
| const botComment = comments.data.find(comment => | |
| comment.user?.type === 'Bot' && | |
| comment.body.includes('docs.json validation failed') | |
| ); | |
| if (botComment) { | |
| await github.rest.issues.updateComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: botComment.id, | |
| body: body | |
| }); | |
| } else { | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: prNumber, | |
| body: body | |
| }); | |
| } | |
| - name: Fail if docs.json validation failed | |
| if: steps.check.outputs.exit_code == '1' | |
| run: | | |
| echo "β Please fix docs.json issues (see PR comment for details)" | |
| exit 1 |