1
1
#! /bin/bash
2
2
3
- # Get the base branch (usually main or master)
4
- BASE_BRANCH=" main"
5
- CURRENT_BRANCH=$( git branch --show-current)
3
+ if [ " $CURRENT_BRANCH " == " $BASE_BRANCH " ]; then
4
+ echo " Running on $BASE_BRANCH branch. Skipping check."
5
+ exit 0
6
+ fi
7
+
6
8
7
9
# Get list of deleted or renamed files in this branch compared to base
8
- DELETED_FILES=$( git diff --name-status $BASE_BRANCH $CURRENT_BRANCH | grep ' ^D\|^R' | awk ' {print $2}' | grep -E ' \.(rst|py|ipynb)$' | grep -v ' redirects.py' )
10
+ DELETED_FILES=$( git diff --name-status $BASE_BRANCH $CURRENT_BRANCH --diff-filter=DR | grep -E ' \.(rst|py|md)$' | grep
11
+ | awk ' {print $2}' | grep -E ' \.(rst|py|md)$' | grep -v ' redirects.py' )
9
12
13
+ # Check if any deleted or renamed files were found
10
14
if [ -z " $DELETED_FILES " ]; then
11
15
echo " No deleted or renamed files found. Skipping check."
12
16
exit 0
@@ -16,22 +20,22 @@ echo "Deleted or renamed files:"
16
20
echo " $DELETED_FILES "
17
21
18
22
# Check if redirects.py has been updated
19
- REDIRECTS_UPDATED=$( git diff --name-status $BASE_BRANCH $CURRENT_BRANCH | grep -E ' ^M|^A ' | grep ' redirects.py' && echo " yes" || echo " no" )
23
+ REDIRECTS_UPDATED=$( git diff --name-status $BASE_BRANCH $CURRENT_BRANCH --diff-filter=AM | grep ' redirects.py' && echo " yes" || echo " no" )
20
24
21
25
if [ " $REDIRECTS_UPDATED " == " no" ]; then
22
- echo " ERROR: Files were deleted or renamed but redirects.py was not updated."
26
+ echo " ERROR: Files were deleted or renamed but redirects.py was not updated. Please update .github/scripts/redirects.py to redirect these files. "
23
27
exit 1
24
28
fi
25
29
26
30
# Check if each deleted file has a redirect entry
27
31
MISSING_REDIRECTS=0
28
32
for FILE in $DELETED_FILES ; do
29
33
# Convert file path to URL path format (remove extension and adjust path)
30
- URL_PATH =$( echo $FILE | sed ' s/\.rst$//g ' | sed ' s/\.py$//g ' | sed ' s/\. ipynb$//g ' | sed ' s/^tutorials\///g ' )
31
-
32
- # Check if this path exists in redirects.py
33
- if ! grep -q " \" $URL_PATH \" " tutorials/ redirects.py; then
34
- echo " ERROR: Missing redirect for deleted file: $FILE (URL path: $URL_PATH )"
34
+ REDIRECT_PATH =$( echo $FILE | sed -E ' s/(.+)_source\/(.+)\.(py|rst|md| ipynb)$/\1\/\2.html/ ' )
35
+
36
+ # Check if this path exists in redirects.py as a key (without checking the target)
37
+ if ! grep -q " \" $REDIRECT_PATH \" : " redirects.py; then
38
+ echo " ERROR: Missing redirect for deleted file: $FILE (should have entry for \" $REDIRECT_PATH \" )"
35
39
MISSING_REDIRECTS=1
36
40
fi
37
41
done
@@ -42,4 +46,3 @@ if [ $MISSING_REDIRECTS -eq 1 ]; then
42
46
fi
43
47
44
48
echo " All deleted/renamed files have proper redirects. Check passed!"
45
-
0 commit comments