Skip to content

nav test

nav test #1043

name: Check Documentation URL Changes
on:
pull_request:
branches:
- master
paths:
- '**/*.md'
- '**/*.nav.yml'
- '!**/.*.yml'
- '!**/.*.yaml'
jobs:
check-url-changes:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Identify deleted, renamed, and nav changes
run: |
# Deleted markdown files
DELETED_FILES=$(git diff --name-status origin/master ${{ github.event.pull_request.head.sha }} | grep '^D.*\.md$' | cut -f2- || true)
echo "DELETED_FILES<<EOF" >> $GITHUB_ENV
echo "$DELETED_FILES" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
# Renamed markdown files
RENAMED_FILES=$(git diff --name-status origin/master ${{ github.event.pull_request.head.sha }} | grep '^R.*\.md$' | awk '{print $2 " -> " $3}' || true)
echo "RENAMED_FILES<<EOF" >> $GITHUB_ENV
echo "$RENAMED_FILES" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
# Nav file changes (mkdocs.yml or *.nav.yml/yaml only)
NAV_FILES=$(git diff --name-only origin/master ${{ github.event.pull_request.head.sha }} | grep -E '(mkdocs\.yml$|\.nav\.ya?ml$)' | grep -vE '/\.[^/]+\.ya?ml$' || true)
NAV_CHANGES=""
for FILE in $NAV_FILES; do
DIFF=$(git diff origin/master ${{ github.event.pull_request.head.sha }} -- "$FILE" | grep -vE '^\+\+\+|^---' || true)
if [ ! -z "$DIFF" ]; then
NAV_CHANGES+="$FILE:\n$DIFF\n\n"
fi
done
echo "NAV_CHANGES<<EOF" >> $GITHUB_ENV
echo -e "$NAV_CHANGES" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
# Set warning flag if anything risky is found
if [ -n "$DELETED_FILES" ] || [ -n "$RENAMED_FILES" ] || [ -n "$NAV_CHANGES" ]; then
echo "warning=true" >> $GITHUB_ENV
else
echo "warning=false" >> $GITHUB_ENV
fi
- name: Post PR warning
if: env.warning == 'true'
uses: actions/github-script@v7
with:
script: |
const issue_number = context.payload.pull_request.number;
const repo = context.repo;
const deletedFiles = `${process.env.DELETED_FILES}`.trim();
const renamedFiles = `${process.env.RENAMED_FILES}`.trim();
const navChanges = `${process.env.NAV_CHANGES}`.trim();
let message = `🔍 **Documentation URL Checker**\n\nThis PR modifies documentation files in ways that could potentially create broken links.\n\n`;
if (deletedFiles) {
message += `**Deleted files:**\n\`\`\`\n${deletedFiles}\n\`\`\`\n\n`;
}
if (renamedFiles) {
message += `**Renamed/Moved files:**\n\`\`\`\n${renamedFiles}\n\`\`\`\n\n`;
}
if (navChanges) {
message += `**Modified navigation files (possible URL changes):**\n\`\`\`\n${navChanges}\n\`\`\`\n\n`;
}
message += `🚨 Please review these changes carefully 🚨\n\nIf 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\n- Verifying that the navigation structure still matches the intended URLs.`;
github.rest.issues.createComment({
owner: repo.owner,
repo: repo.repo,
issue_number: issue_number,
body: message
});