File tree Expand file tree Collapse file tree 2 files changed +71
-0
lines changed Expand file tree Collapse file tree 2 files changed +71
-0
lines changed Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+
3
+ if [ " $CURRENT_BRANCH " == " $BASE_BRANCH " ]; then
4
+ echo " Running on $BASE_BRANCH branch. Skipping check."
5
+ exit 0
6
+ fi
7
+
8
+
9
+ # Get list of deleted or renamed files in this branch compared to base
10
+ DELETED_FILES=$( git diff --name-status $BASE_BRANCH $CURRENT_BRANCH --diff-filter=DR | awk ' {print $2}' | grep -E ' \.(rst|py|md)$' | grep -v ' redirects.py' )
11
+ # Check if any deleted or renamed files were found
12
+ if [ -z " $DELETED_FILES " ]; then
13
+ echo " No deleted or renamed files found. Skipping check."
14
+ exit 0
15
+ fi
16
+
17
+ echo " Deleted or renamed files:"
18
+ echo " $DELETED_FILES "
19
+
20
+ # Check if redirects.py has been updated
21
+ REDIRECTS_UPDATED=$( git diff --name-status $BASE_BRANCH $CURRENT_BRANCH --diff-filter=AM | grep ' redirects.py' && echo " yes" || echo " no" )
22
+
23
+ if [ " $REDIRECTS_UPDATED " == " no" ]; then
24
+ echo " ERROR: Files were deleted or renamed but redirects.py was not updated. Please update .github/scripts/redirects.py to redirect these files."
25
+ exit 1
26
+ fi
27
+
28
+ # Check if each deleted file has a redirect entry
29
+ MISSING_REDIRECTS=0
30
+ for FILE in $DELETED_FILES ; do
31
+ # Convert file path to URL path format (remove extension and adjust path)
32
+ REDIRECT_PATH=$( echo $FILE | sed -E ' s/(.+)_source\/(.+)\.(py|rst|md)$/\1\/\2.html/' )
33
+
34
+ # Check if this path exists in redirects.py as a key. We don't check for values.
35
+ if ! grep -q " \" $REDIRECT_PATH \" :" redirects.py; then
36
+ echo " ERROR: Missing redirect for deleted file: $FILE (should have entry for \" $REDIRECT_PATH \" )"
37
+ MISSING_REDIRECTS=1
38
+ fi
39
+ done
40
+
41
+ if [ $MISSING_REDIRECTS -eq 1 ]; then
42
+ echo " ERROR: Please add redirects for all deleted/renamed files to redirects.py"
43
+ exit 1
44
+ fi
45
+
46
+ echo " All deleted/renamed files have proper redirects. Check passed!"
Original file line number Diff line number Diff line change
1
+ name : Check Redirects for Deleted or Renamed Files
2
+
3
+ on :
4
+ pull_request :
5
+ paths :
6
+ - ' */**/*.rst'
7
+ - ' */**/*.py'
8
+ - ' */**/*.md'
9
+
10
+ jobs :
11
+ check-redirects :
12
+ runs-on : ubuntu-latest
13
+ steps :
14
+ - name : Checkout code
15
+ uses : actions/checkout@v4
16
+ with :
17
+ fetch-depth : 0
18
+
19
+ - name : Run redirect check script
20
+ run : |
21
+ chmod +x ./.github/scripts/check_redirects.sh
22
+ ./.github/scripts/check_redirects.sh
23
+ env :
24
+ BASE_BRANCH : ${{ github.base_ref }}
25
+ CURRENT_BRANCH : ${{ github.head_ref }}
You can’t perform that action at this time.
0 commit comments