Taylor/update url checker #1108
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: Documentation & Navigation Change Checker | |
| on: | |
| pull_request: | |
| branches: | |
| - master | |
| jobs: | |
| check-doc-nav-changes: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout PR branch | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 1 | |
| ref: ${{ github.event.pull_request.head.ref }} | |
| repository: ${{ github.event.pull_request.head.repo.full_name }} | |
| - name: Fetch base branch | |
| run: git fetch origin ${{ github.event.pull_request.base.ref }} --depth=1 | |
| - name: Identify .md and .nav changes | |
| run: | | |
| BASE=origin/${{ github.event.pull_request.base.ref }} | |
| HEAD=${{ github.event.pull_request.head.sha }} | |
| # Markdown changes | |
| DELETED_MD=$(git diff --name-status $BASE $HEAD | grep '^D.*\.md$' | cut -f2- || true) | |
| RENAMED_MD=$(git diff --name-status $BASE $HEAD | grep '^R.*\.md$' | awk '{print $2 " -> " $3}' || true) | |
| # Nav changes | |
| DELETED_NAV=$(git diff --name-status $BASE $HEAD | grep '^D.*\.nav\.ya?ml$' | cut -f2- || true) | |
| MODIFIED_NAV=$(git diff --name-status $BASE $HEAD | grep -E '^[AM].*\.nav\.ya?ml$' | cut -f2- || true) | |
| RENAMED_NAV=$(git diff --name-status $BASE $HEAD | grep '^R.*\.nav\.ya?ml$' | awk '{print $2 " -> " $3}' || true) | |
| NAV_CHANGES="" | |
| for f in $DELETED_NAV; do NAV_CHANGES+="$f: [DELETED]\n\n"; done | |
| for f in $MODIFIED_NAV; do DIFF=$(git diff $BASE $HEAD -- "$f" | grep -vE '^\+\+\+|^---'); NAV_CHANGES+="$f:\n$DIFF\n\n"; done | |
| for f in $RENAMED_NAV; do NAV_CHANGES+="$f [RENAMED]\n\n"; done | |
| echo "DELETED_MD<<EOF" >> $GITHUB_ENV | |
| echo "$DELETED_MD" >> $GITHUB_ENV | |
| echo "EOF" >> $GITHUB_ENV | |
| echo "RENAMED_MD<<EOF" >> $GITHUB_ENV | |
| echo "$RENAMED_MD" >> $GITHUB_ENV | |
| echo "EOF" >> $GITHUB_ENV | |
| echo "NAV_CHANGES<<EOF" >> $GITHUB_ENV | |
| echo -e "$NAV_CHANGES" >> $GITHUB_ENV | |
| echo "EOF" >> $GITHUB_ENV | |
| if [ -n "$DELETED_MD$RENAMED_MD$NAV_CHANGES" ]; then | |
| echo "warning=true" >> $GITHUB_ENV | |
| else | |
| echo "warning=false" >> $GITHUB_ENV | |
| fi | |
| - name: Post PR comment if relevant | |
| if: env.warning == 'true' | |
| uses: actions/github-script@v7 | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| script: | | |
| const deletedMd = `${process.env.DELETED_MD}`.trim(); | |
| const renamedMd = `${process.env.RENAMED_MD}`.trim(); | |
| const navChanges = `${process.env.NAV_CHANGES}`.trim(); | |
| let message = "🔍 **Documentation & Navigation Checker**\n\nThis PR modifies `.md` or `.nav.yml` files.\n\n"; | |
| if (deletedMd) message += `**Deleted Markdown files:**\n\`\`\`\n${deletedMd}\n\`\`\`\n\n`; | |
| if (renamedMd) message += `**Renamed Markdown files:**\n\`\`\`\n${renamedMd}\n\`\`\`\n\n`; | |
| if (navChanges) message += `**Navigation file changes:**\n\`\`\`\n${navChanges}\n\`\`\`\n\n`; | |
| message += "🚨 Please verify:\n- Links are correct\n- TOC matches expected structure\n- Deleted/renamed entries are handled. \n\n 🚨 If not handled properly, broken links (404 errors) could appear. To maintain a smooth user experience, consider:\n- Adding redirects in the \`mkdocs.yml\` file from the old URLs to the new ones\n- Updating internal references to these files"; | |
| github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.payload.pull_request.number, | |
| body: message | |
| }); |