Skip to content

Commit bf4b550

Browse files
committed
nav
1 parent 990160f commit bf4b550

File tree

1 file changed

+31
-63
lines changed

1 file changed

+31
-63
lines changed

β€Ž.github/workflows/check-url-changes.ymlβ€Ž

Lines changed: 31 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,111 +1,79 @@
1-
name: Check Documentation URL Changes
1+
name: Navigation File Change Checker
22

33
on:
44
pull_request_target:
55
branches:
6-
- master # target branch of PR
6+
- master # target branch
77
paths:
8-
- '**/*.md'
98
- '**/.nav.yml'
109
- '**/.nav.yaml'
1110

1211
jobs:
13-
check-url-changes:
12+
check-nav-changes:
1413
runs-on: ubuntu-latest
1514
steps:
16-
- name: Checkout code
15+
# 1️⃣ Checkout the PR branch safely (fork-safe)
16+
- name: Checkout PR
1717
uses: actions/checkout@v4
1818
with:
1919
fetch-depth: 0
2020
ref: ${{ github.event.pull_request.head.ref }}
2121
repository: ${{ github.event.pull_request.head.repo.full_name }}
2222

23-
- name: Identify deleted, renamed, and nav changes
23+
# 2️⃣ Identify nav file changes
24+
- name: Detect nav file changes
2425
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)
3628
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)
4231
4332
NAV_CHANGES=""
4433
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)
5242
NAV_CHANGES+="$FILE:\n$DIFF\n\n"
5343
done
5444
45+
# Export to environment
5546
echo "NAV_CHANGES<<EOF" >> $GITHUB_ENV
5647
echo -e "$NAV_CHANGES" >> $GITHUB_ENV
5748
echo "EOF" >> $GITHUB_ENV
5849
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
6152
echo "warning=true" >> $GITHUB_ENV
6253
else
6354
echo "warning=false" >> $GITHUB_ENV
6455
fi
6556
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"
7359
74-
- name: Post PR warning
60+
# 3️⃣ Post PR comment if changes exist
61+
- name: Post PR comment
7562
if: env.warning == 'true'
7663
uses: actions/github-script@v7
7764
with:
7865
github-token: ${{ secrets.GITHUB_TOKEN }}
7966
script: |
8067
const issue_number = context.payload.pull_request.number;
8168
const repo = context.repo;
82-
const deletedFiles = `${process.env.DELETED_FILES}`.trim();
83-
const renamedFiles = `${process.env.RENAMED_FILES}`.trim();
8469
const navChanges = `${process.env.NAV_CHANGES}`.trim();
8570
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');
10775
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`;
10977
11078
github.rest.issues.createComment({
11179
owner: repo.owner,

0 commit comments

Comments
Β (0)