Skip to content

Commit 9b76c0e

Browse files
committed
udpate script
1 parent 196004c commit 9b76c0e

File tree

1 file changed

+37
-19
lines changed

1 file changed

+37
-19
lines changed

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

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
name: Check Documentation URL Changes
22

33
on:
4-
pull_request:
4+
pull_request_target:
55
branches:
66
- url-test
77
paths:
88
- '**/*.md'
99
- '**/.nav.yml'
10-
10+
\
1111

1212
jobs:
1313
check-url-changes:
@@ -17,6 +17,8 @@ jobs:
1717
uses: actions/checkout@v4
1818
with:
1919
fetch-depth: 0
20+
ref: ${{ github.event.pull_request.head.ref }}
21+
repository: ${{ github.event.pull_request.head.repo.full_name }}
2022

2123
- name: Identify deleted, renamed, and nav changes
2224
run: |
@@ -25,62 +27,78 @@ jobs:
2527
echo "DELETED_FILES<<EOF" >> $GITHUB_ENV
2628
echo "$DELETED_FILES" >> $GITHUB_ENV
2729
echo "EOF" >> $GITHUB_ENV
28-
30+
2931
# Renamed markdown files
3032
RENAMED_FILES=$(git diff --name-status origin/master ${{ github.event.pull_request.head.sha }} | grep '^R.*\.md$' | awk '{print $2 " -> " $3}' || true)
3133
echo "RENAMED_FILES<<EOF" >> $GITHUB_ENV
3234
echo "$RENAMED_FILES" >> $GITHUB_ENV
3335
echo "EOF" >> $GITHUB_ENV
3436
35-
# Nav file changes (.nav.yml and .nav.yaml)
36-
NAV_FILES=$(git diff --name-only origin/master ${{ github.event.pull_request.head.sha }} | grep -E '\.nav\.ya?ml$' || true)
37+
# Deleted nav files
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)
3742
3843
NAV_CHANGES=""
39-
for FILE in $NAV_FILES; do
40-
DIFF=$(git diff origin/master ${{ github.event.pull_request.head.sha }} -- "$FILE" | grep -vE '^\+\+\+|^---' || true)
41-
if [ ! -z "$DIFF" ]; then
42-
NAV_CHANGES+="$FILE:\n$DIFF\n\n"
44+
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]"
4351
fi
52+
NAV_CHANGES+="$FILE:\n$DIFF\n\n"
4453
done
4554
4655
echo "NAV_CHANGES<<EOF" >> $GITHUB_ENV
4756
echo -e "$NAV_CHANGES" >> $GITHUB_ENV
4857
echo "EOF" >> $GITHUB_ENV
49-
50-
# Set warning flag if anything risky is found
58+
59+
# Set warning flag if any risky changes found
5160
if [ -n "$DELETED_FILES" ] || [ -n "$RENAMED_FILES" ] || [ -n "$NAV_CHANGES" ]; then
5261
echo "warning=true" >> $GITHUB_ENV
5362
else
5463
echo "warning=false" >> $GITHUB_ENV
5564
fi
5665
66+
# Log changes
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:"
72+
echo -e "$NAV_CHANGES"
73+
5774
- name: Post PR warning
5875
if: env.warning == 'true'
5976
uses: actions/github-script@v7
6077
with:
78+
github-token: ${{ secrets.GITHUB_TOKEN }}
6179
script: |
6280
const issue_number = context.payload.pull_request.number;
6381
const repo = context.repo;
6482
const deletedFiles = `${process.env.DELETED_FILES}`.trim();
6583
const renamedFiles = `${process.env.RENAMED_FILES}`.trim();
6684
const navChanges = `${process.env.NAV_CHANGES}`.trim();
67-
85+
6886
let message = `🔍 **Documentation URL Checker**\n\nThis PR modifies documentation files in ways that could potentially create broken links.\n\n`;
69-
87+
7088
if (deletedFiles) {
71-
message += `**Deleted files:**\n\`\`\`\n${deletedFiles}\n\`\`\`\n\n`;
89+
message += `**Deleted markdown files:**\n\`\`\`\n${deletedFiles}\n\`\`\`\n\n`;
7290
}
73-
91+
7492
if (renamedFiles) {
75-
message += `**Renamed/Moved files:**\n\`\`\`\n${renamedFiles}\n\`\`\`\n\n`;
93+
message += `**Renamed/Moved markdown files:**\n\`\`\`\n${renamedFiles}\n\`\`\`\n\n`;
7694
}
7795
7896
if (navChanges) {
79-
message += `**Modified navigation files (possible URL changes):**\n\`\`\`\n${navChanges}\n\`\`\`\n\n`;
97+
message += `**Modified or deleted navigation files:**\n\`\`\`\n${navChanges}\n\`\`\`\n\n`;
8098
}
81-
99+
82100
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.`;
83-
101+
84102
github.rest.issues.createComment({
85103
owner: repo.owner,
86104
repo: repo.repo,

0 commit comments

Comments
 (0)