|
1 | | -name: Check Documentation URL Changes |
| 1 | +name: Navigation File Change Checker |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | pull_request_target: |
5 | 5 | branches: |
6 | | - - master # target branch of PR |
| 6 | + - master # target branch |
7 | 7 | paths: |
8 | | - - '**/*.md' |
9 | 8 | - '**/.nav.yml' |
10 | 9 | - '**/.nav.yaml' |
11 | 10 |
|
12 | 11 | jobs: |
13 | | - check-url-changes: |
| 12 | + check-nav-changes: |
14 | 13 | runs-on: ubuntu-latest |
15 | 14 | steps: |
16 | | - - name: Checkout code |
| 15 | + # 1οΈβ£ Checkout the PR branch safely (fork-safe) |
| 16 | + - name: Checkout PR |
17 | 17 | uses: actions/checkout@v4 |
18 | 18 | with: |
19 | 19 | fetch-depth: 0 |
20 | 20 | ref: ${{ github.event.pull_request.head.ref }} |
21 | 21 | repository: ${{ github.event.pull_request.head.repo.full_name }} |
22 | 22 |
|
23 | | - - name: Identify deleted, renamed, and nav changes |
| 23 | + # 2οΈβ£ Identify nav file changes |
| 24 | + - name: Detect nav file changes |
24 | 25 | run: | |
25 | | - # Deleted markdown files |
26 | | - DELETED_FILES=$(git diff --name-status origin/master ${{ github.event.pull_request.head.sha }} | grep '^D.*\.md$' | cut -f2- || true) |
27 | | - echo "DELETED_FILES<<EOF" >> $GITHUB_ENV |
28 | | - echo "$DELETED_FILES" >> $GITHUB_ENV |
29 | | - echo "EOF" >> $GITHUB_ENV |
30 | | -
|
31 | | - # Renamed markdown files |
32 | | - RENAMED_FILES=$(git diff --name-status origin/master ${{ github.event.pull_request.head.sha }} | grep '^R.*\.md$' | awk '{print $2 " -> " $3}' || true) |
33 | | - echo "RENAMED_FILES<<EOF" >> $GITHUB_ENV |
34 | | - echo "$RENAMED_FILES" >> $GITHUB_ENV |
35 | | - echo "EOF" >> $GITHUB_ENV |
| 26 | + # Deleted nav files |
| 27 | + DELETED_NAV=$(git diff --name-status origin/master ${{ github.event.pull_request.head.sha }} | grep '^D.*\.nav\.ya?ml$' | cut -f2- || true) |
36 | 28 |
|
37 | | - # Deleted nav files (.nav.yml or .nav.yaml) |
38 | | - DELETED_NAV_FILES=$(git diff --name-status origin/master ${{ github.event.pull_request.head.sha }} | grep '^D.*\.nav\.ya?ml$' | cut -f2- || true) |
39 | | -
|
40 | | - # Modified nav files |
41 | | - MODIFIED_NAV_FILES=$(git diff --name-only origin/master ${{ github.event.pull_request.head.sha }} | grep -E '\.nav\.ya?ml$' || true) |
| 29 | + # Added or modified nav files |
| 30 | + MODIFIED_NAV=$(git diff --name-status origin/master ${{ github.event.pull_request.head.sha }} | grep -E '^[AM].*\.nav\.ya?ml$' | cut -f2- || true) |
42 | 31 |
|
43 | 32 | NAV_CHANGES="" |
44 | 33 |
|
45 | | - # Combine deleted and modified nav files |
46 | | - for FILE in $DELETED_NAV_FILES $MODIFIED_NAV_FILES; do |
47 | | - if [ -f "$FILE" ]; then |
48 | | - DIFF=$(git diff origin/master ${{ github.event.pull_request.head.sha }} -- "$FILE" | grep -vE '^\+\+\+|^---' || true) |
49 | | - else |
50 | | - DIFF="[FILE DELETED]" |
51 | | - fi |
| 34 | + # Process deleted files |
| 35 | + for FILE in $DELETED_NAV; do |
| 36 | + NAV_CHANGES+="$FILE: [FILE DELETED]\n\n" |
| 37 | + done |
| 38 | +
|
| 39 | + # Process added or modified files |
| 40 | + for FILE in $MODIFIED_NAV; do |
| 41 | + DIFF=$(git diff origin/master ${{ github.event.pull_request.head.sha }} -- "$FILE" | grep -vE '^\+\+\+|^---' || true) |
52 | 42 | NAV_CHANGES+="$FILE:\n$DIFF\n\n" |
53 | 43 | done |
54 | 44 |
|
| 45 | + # Export to environment |
55 | 46 | echo "NAV_CHANGES<<EOF" >> $GITHUB_ENV |
56 | 47 | echo -e "$NAV_CHANGES" >> $GITHUB_ENV |
57 | 48 | echo "EOF" >> $GITHUB_ENV |
58 | 49 |
|
59 | | - # Set warning flag if any risky changes found |
60 | | - if [ -n "$DELETED_FILES" ] || [ -n "$RENAMED_FILES" ] || [ -n "$NAV_CHANGES" ]; then |
| 50 | + # Set warning flag |
| 51 | + if [ -n "$NAV_CHANGES" ]; then |
61 | 52 | echo "warning=true" >> $GITHUB_ENV |
62 | 53 | else |
63 | 54 | echo "warning=false" >> $GITHUB_ENV |
64 | 55 | fi |
65 | 56 |
|
66 | | - # Log for debugging |
67 | | - echo "Deleted markdown files:" |
68 | | - echo "$DELETED_FILES" |
69 | | - echo -e "\nRenamed/Moved markdown files:" |
70 | | - echo "$RENAMED_FILES" |
71 | | - echo -e "\nNav file changes (deleted/modified):" |
72 | | - echo -e "$NAV_CHANGES" |
| 57 | + # Debug output |
| 58 | + echo -e "NAV file changes detected:\n$NAV_CHANGES" |
73 | 59 |
|
74 | | - - name: Post PR warning |
| 60 | + # 3οΈβ£ Post PR comment if changes exist |
| 61 | + - name: Post PR comment |
75 | 62 | if: env.warning == 'true' |
76 | 63 | uses: actions/github-script@v7 |
77 | 64 | with: |
78 | 65 | github-token: ${{ secrets.GITHUB_TOKEN }} |
79 | 66 | script: | |
80 | 67 | const issue_number = context.payload.pull_request.number; |
81 | 68 | const repo = context.repo; |
82 | | - const deletedFiles = `${process.env.DELETED_FILES}`.trim(); |
83 | | - const renamedFiles = `${process.env.RENAMED_FILES}`.trim(); |
84 | 69 | const navChanges = `${process.env.NAV_CHANGES}`.trim(); |
85 | 70 |
|
86 | | - let message = `π **Documentation URL Checker**\n\nThis PR modifies documentation files in ways that could potentially create broken links.\n\n`; |
87 | | -
|
88 | | - if (deletedFiles) { |
89 | | - message += `**Deleted markdown files:**\n\`\`\`\n${deletedFiles}\n\`\`\`\n\n`; |
90 | | - } |
91 | | -
|
92 | | - if (renamedFiles) { |
93 | | - message += `**Renamed/Moved markdown files:**\n\`\`\`\n${renamedFiles}\n\`\`\`\n\n`; |
94 | | - } |
95 | | -
|
96 | | - if (navChanges) { |
97 | | - // Highlight deleted nav files separately |
98 | | - const navLines = navChanges.split('\n').map(line => { |
99 | | - if (line.includes('[FILE DELETED]')) { |
100 | | - return `β ${line.replace(':', '')}`; // mark deleted files with β |
101 | | - } |
102 | | - return line; |
103 | | - }).join('\n'); |
104 | | -
|
105 | | - message += `**Modified or deleted navigation files:**\n\`\`\`\n${navLines}\n\`\`\`\n\n`; |
106 | | - } |
| 71 | + let formatted = navChanges.split('\n').map(line => { |
| 72 | + if (line.includes('[FILE DELETED]')) return `β ${line.replace(': [FILE DELETED]', '')}`; |
| 73 | + return line; |
| 74 | + }).join('\n'); |
107 | 75 |
|
108 | | - 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.`; |
| 76 | + const message = `π **Navigation File Changes Detected**\n\nThis PR modifies navigation files (.nav.yml/.nav.yaml) which could affect the Table of Contents.\n\n**Changes:**\n\`\`\`\n${formatted}\n\`\`\`\n\nπ¨ Please verify:\n- Navigation structure still matches intended URLs\n- Internal links are correct\n- Any deleted entries are handled or redirected`; |
109 | 77 |
|
110 | 78 | github.rest.issues.createComment({ |
111 | 79 | owner: repo.owner, |
|
0 commit comments