8
8
name : Verifying Redirects
9
9
runs-on : ubuntu-latest
10
10
env :
11
- REDIRECTS_FILE : " config/redirects"
11
+ REDIRECTS_FILE : " pr/ config/redirects"
12
12
permissions :
13
13
pull-requests : write
14
14
steps :
15
15
- name : Check Out Base Branch
16
16
uses : actions/checkout@v4
17
-
17
+
18
+ - name : Checkout PR Head Branch
19
+ uses : actions/checkout@v4
20
+ with :
21
+ token : ${{ secrets.GITHUB_TOKEN }}
22
+ ref : ${{ github.event.pull_request.head.ref }}
23
+ repository : ${{ github.event.pull_request.head.repo.full_name }}
24
+ path : pr
25
+
18
26
- name : Get Changed Files
19
27
id : changed-files
20
28
uses : tj-actions/changed-files@c65cd883420fd2eb864698a825fc4162dd94482c
27
35
env :
28
36
RENAMED_FILES : ${{ steps.changed-files.outputs.all_old_new_renamed_files }}
29
37
run : |
30
- renamed_redirects=()
38
+ renamed_redirects=""
31
39
for file in $RENAMED_FILES; do
32
40
33
41
# only run for .txt files
@@ -44,22 +52,26 @@ jobs:
44
52
new="${new%.txt}"
45
53
46
54
# single quotes = ${var} rendered literally; double quotes = $var interpreted
47
- renamed_redirect ='${prefix}/${version}'"$old"'/ -> ${base}/${version}'"$new"'/'
55
+ redirect ='${prefix}/${version}'"$old"'/ -> ${base}/${version}'"$new"'/'
48
56
49
- # if redirect not already in file, add to array to add to PR description
50
- if ! grep -q "$renamed_redirect " $REDIRECTS_FILE; then
51
- renamed_redirects+=("$renamed_redirect")
57
+ # if redirect not already in file, add to string to add to PR description
58
+ if ! grep -q "$redirect " $REDIRECTS_FILE; then
59
+ renamed_redirects+="$redirect,"
52
60
fi
53
61
done
54
- echo "redirects=${renamed_redirects}" >> "$GITHUB_OUTPUT"
62
+
63
+ # cut trailing comma
64
+ renamed_redirects="${renamed_redirects%,}"
65
+
66
+ echo "redirects=${renamed_redirects}" >> "$GITHUB_OUTPUT"
55
67
56
68
- name : Find Missing Redirects for Deleted Files
57
69
id : deleted-files
58
70
if : steps.changed-files.outputs.deleted_files_count > 0
59
71
env :
60
72
DELETED_FILES : ${{ steps.changed-files.outputs.deleted_files }}
61
73
run : |
62
- deleted_redirects=()
74
+ deleted_redirects=""
63
75
for file in $DELETED_FILES; do
64
76
65
77
# only run for .txt files
@@ -73,15 +85,18 @@ jobs:
73
85
old="${old%.txt}"
74
86
75
87
# single quotes = ${var} rendered literally; double quotes = $var interpreted
76
- deleted_redirect ='${prefix}/${version}'"$old"'/ -> ${base}/${version}/'
88
+ redirect ='${prefix}/${version}'"$old"'/ -> ${base}/${version}/'
77
89
78
- # if redirect not already in file, add to array to add to PR description
79
- if ! grep -q "$deleted_redirect " $REDIRECTS_FILE; then
80
- deleted_redirects+=("$deleted_redirect")
90
+ # if redirect not already in file, add to string to add to PR description
91
+ if ! grep -q "$redirect " $REDIRECTS_FILE; then
92
+ deleted_redirects+="$redirect,"
81
93
fi
82
-
83
94
done
84
- echo "redirects=${deleted_redirects}" >> "$GITHUB_OUTPUT"
95
+
96
+ # cut trailing comma
97
+ deleted_redirects="${deleted_redirects%,}"
98
+
99
+ echo "redirects=${deleted_redirects}" >> "$GITHUB_OUTPUT"
85
100
86
101
- name : Build Redirect HTML
87
102
id : build-redirect-html
@@ -91,41 +106,38 @@ jobs:
91
106
run : |
92
107
# empty string that stays empty if there are no redirects to suggest
93
108
redirect_html=""
94
-
95
- for renamed_redirect in "${RENAMED_REDIRECTS[@]}"; do
96
- redirect_html+="<li>[<v>-*]: $renamed_redirect</li>"
109
+
110
+ combined_redirect_string="${RENAMED_REDIRECTS},${DELETED_REDIRECTS}"
111
+
112
+ for redirect in $combined_redirect_string; do
113
+ if [[ ! -z "$redirect" ]]; then
114
+ if [[ redirect_html="" ]]; then
115
+ redirect_html="*Suggested redirects for moved/deleted files (replace <v> with earliest backport target version):*"
116
+ fi
117
+ redirect_html+="<li>[<v>-*]: $redirect</li>"
118
+ fi
97
119
done
98
-
99
- for deleted_redirect in "${DELETED_REDIRECTS[@]}"; do
100
- redirect_html+="<li>[<v>-*]: $deleted_redirect</li>"
101
- done
102
-
120
+
103
121
echo "redirect_html=${redirect_html}" >> "$GITHUB_OUTPUT"
104
122
105
123
- name : Update PR Description
106
- if : steps.build-redirect-html.outputs.redirect_html
107
124
uses : MongoCaleb/pr-description-action@4bdfe35b98f64532b419ad20b350a92546cd3aa1
108
- env :
109
- REDIRECT_HTML : ${{ steps.build-redirect-html.outputs.redirect_html }}
110
125
with :
111
126
regex : " - \\ [ \\ ] Did you add redirects\\ ?.*"
112
127
appendContentOnMatchOnly : false
113
128
regexFlags : is
114
- content : " - [ ] Did you add redirects?\n *Suggested redirects for moved/deleted files (replace <v> with earliest backport target version):* \n ${{ steps.build-redirect-html.outputs.redirect_html }}\n "
129
+ content : " - [ ] Did you add redirects?\n ${{ steps.build-redirect-html.outputs.redirect_html }}"
115
130
token : ${{ secrets.GITHUB_TOKEN }}
116
131
117
132
- name : Check for duplicates in redirects file
118
133
run : |
119
- # Specify the file to check
120
- file="$REDIRECTS_FILE"
121
-
122
- if [[ -f "$file" ]]; then
123
- duplicates=$(sort "$file" | uniq -d)
134
+ if [[ -f "$REDIRECTS_FILE" ]]; then
135
+ duplicates=$(sort "$REDIRECTS_FILE" | uniq -d)
124
136
if [[ -n "$duplicates" ]]; then
125
- echo "Duplicate lines found in $file:"
137
+ echo "Duplicate lines found in $REDIRECTS_FILE:"
126
138
echo "$duplicates"
127
139
exit 1 # error
128
140
fi
129
141
else
130
- echo "File $ file does not exist. Skipping duplicate check."
142
+ echo "Redirects file doesn't exist. Skipping duplicate check."
131
143
fi
0 commit comments