Skip to content

Commit 56f595e

Browse files
committed
Test
1 parent dc211cb commit 56f595e

File tree

1 file changed

+33
-19
lines changed

1 file changed

+33
-19
lines changed

.github/workflows/check-url-changes.yml

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,57 @@
11
name: Documentation & Navigation Change Checker
22

33
on:
4-
pull_request:
4+
pull_request_target:
55
branches:
6-
- url-test
7-
paths:
6+
- url-test # target branch
7+
# paths can stay as a hint, but we will rely on Git runtime check
8+
paths:
89
- '**/*.md'
910
- '**/*.nav.yml'
11+
- '**/*.nav.yaml'
1012

1113
jobs:
1214
check-doc-nav-changes:
1315
runs-on: ubuntu-latest
1416
steps:
17+
# 1️⃣ Checkout PR branch safely (fork-safe)
1518
- name: Checkout PR branch
1619
uses: actions/checkout@v4
1720
with:
1821
fetch-depth: 0
1922
ref: ${{ github.event.pull_request.head.ref }}
2023
repository: ${{ github.event.pull_request.head.repo.full_name }}
2124

25+
# 2️⃣ Fetch base branch for diff
2226
- name: Fetch base branch
2327
run: git fetch origin ${{ github.event.pull_request.base.ref }} --depth=1
2428

25-
- name: Identify .md and .nav changes
29+
# 3️⃣ Detect .md and .nav changes
30+
- name: Identify changed files
2631
run: |
2732
BASE=origin/${{ github.event.pull_request.base.ref }}
2833
HEAD=${{ github.event.pull_request.head.sha }}
2934
30-
# Markdown changes
31-
DELETED_MD=$(git diff --name-status $BASE $HEAD | grep '^D.*\.md$' | cut -f2- || true)
32-
RENAMED_MD=$(git diff --name-status $BASE $HEAD | grep '^R.*\.md$' | awk '{print $2 " -> " $3}' || true)
35+
# Detect any relevant changes
36+
CHANGED_MD=$(git diff --name-status $BASE $HEAD | grep -E '^([ADM]|R).*\.md$' || true)
37+
CHANGED_NAV=$(git diff --name-status $BASE $HEAD | grep -E '^([ADM]|R).*\.nav\.ya?ml$' || true)
3338
34-
# Nav changes
35-
DELETED_NAV=$(git diff --name-status $BASE $HEAD | grep '^D.*\.nav\.ya?ml$' | cut -f2- || true)
36-
MODIFIED_NAV=$(git diff --name-status $BASE $HEAD | grep -E '^[AM].*\.nav\.ya?ml$' | cut -f2- || true)
37-
RENAMED_NAV=$(git diff --name-status $BASE $HEAD | grep '^R.*\.nav\.ya?ml$' | awk '{print $2 " -> " $3}' || true)
39+
# Exit early if no relevant files changed
40+
if [ -z "$CHANGED_MD$CHANGED_NAV" ]; then
41+
echo "No .md or .nav.yml/.nav.yaml changes detected. Exiting."
42+
exit 0
43+
fi
44+
45+
# Prepare environment variables
46+
DELETED_MD=$(echo "$CHANGED_MD" | grep '^D' | cut -f2- || true)
47+
RENAMED_MD=$(echo "$CHANGED_MD" | grep '^R' | awk '{print $2 " -> " $3}' || true)
48+
49+
DELETED_NAV=$(echo "$CHANGED_NAV" | grep '^D' | cut -f2- || true)
50+
MODIFIED_NAV=$(echo "$CHANGED_NAV" | grep '^A\|^M' | cut -f2- || true)
51+
RENAMED_NAV=$(echo "$CHANGED_NAV" | grep '^R' | awk '{print $2 " -> " $3}' || true)
3852
3953
NAV_CHANGES=""
54+
4055
for f in $DELETED_NAV; do NAV_CHANGES+="$f: [DELETED]\n\n"; done
4156
for f in $MODIFIED_NAV; do DIFF=$(git diff $BASE $HEAD -- "$f" | grep -vE '^\+\+\+|^---'); NAV_CHANGES+="$f:\n$DIFF\n\n"; done
4257
for f in $RENAMED_NAV; do NAV_CHANGES+="$f [RENAMED]\n\n"; done
@@ -53,13 +68,10 @@ jobs:
5368
echo -e "$NAV_CHANGES" >> $GITHUB_ENV
5469
echo "EOF" >> $GITHUB_ENV
5570
56-
if [ -n "$DELETED_MD$RENAMED_MD$NAV_CHANGES" ]; then
57-
echo "warning=true" >> $GITHUB_ENV
58-
else
59-
echo "warning=false" >> $GITHUB_ENV
60-
fi
71+
echo "warning=true" >> $GITHUB_ENV
6172
62-
- name: Post PR comment if relevant
73+
# 4️⃣ Post PR comment if relevant
74+
- name: Post PR comment
6375
if: env.warning == 'true'
6476
uses: actions/github-script@v7
6577
with:
@@ -69,13 +81,15 @@ jobs:
6981
const renamedMd = `${process.env.RENAMED_MD}`.trim();
7082
const navChanges = `${process.env.NAV_CHANGES}`.trim();
7183
72-
let message = "🔍 **Documentation & Navigation Checker**\n\nThis PR modifies `.md` or `.nav.yml/.nav.yaml` files.\n\n";
84+
// ✅ Requested intro
85+
let message = `🔍 **Documentation URL Checker**\n\nThis PR modifies documentation files in ways that could potentially create broken links.\n\n`;
7386
7487
if (deletedMd) message += `**Deleted Markdown files:**\n\`\`\`\n${deletedMd}\n\`\`\`\n\n`;
7588
if (renamedMd) message += `**Renamed Markdown files:**\n\`\`\`\n${renamedMd}\n\`\`\`\n\n`;
7689
if (navChanges) message += `**Navigation file changes:**\n\`\`\`\n${navChanges}\n\`\`\`\n\n`;
7790
78-
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";
91+
// ✅ Requested closing
92+
message += `🚨 Please review these changes carefully 🚨\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`;
7993
8094
github.rest.issues.createComment({
8195
owner: context.repo.owner,

0 commit comments

Comments
 (0)