Skip to content

Commit 2e6753a

Browse files
committed
Merge remote-tracking branch 'upstream/test-redirect-gh-action' into regex
2 parents 080b85a + de44868 commit 2e6753a

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

.github/workflows/add-redirects.yml

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ jobs:
3636
RENAMED_FILES: ${{ steps.changed-files.outputs.all_old_new_renamed_files }}
3737
run: |
3838
renamed_redirects=""
39+
3940
for file in $RENAMED_FILES; do
4041
4142
# only run for .txt files
@@ -56,11 +57,13 @@ jobs:
5657
5758
# if redirect not already in file, add to string to add to PR description
5859
if ! grep -qx "$redirect" $REDIRECTS_FILE; then
59-
renamed_redirects+="<li>[&lt;v&gt;-*]: $redirect</li>"
60-
echo "${renamed_redirects}"
60+
renamed_redirects+="$redirect,"
6161
fi
6262
done
6363
64+
# cut trailing comma
65+
renamed_redirects="${renamed_redirects%,}"
66+
6467
echo "redirects=${renamed_redirects}" >> "$GITHUB_OUTPUT"
6568
6669
- name: Find Missing Redirects for Deleted Files
@@ -70,6 +73,7 @@ jobs:
7073
DELETED_FILES: ${{ steps.changed-files.outputs.deleted_files }}
7174
run: |
7275
deleted_redirects=""
76+
7377
for file in $DELETED_FILES; do
7478
7579
# only run for .txt files
@@ -87,10 +91,12 @@ jobs:
8791
8892
# if redirect not already in file, add to string to add to PR description
8993
if ! grep -qx "$redirect" $REDIRECTS_FILE; then
90-
deleted_redirects+="<li>[&lt;v&gt;-*]: $redirect</li>"
91-
echo "${deleted_redirects}"
94+
deleted_redirects+="$redirect,"
9295
fi
9396
done
97+
98+
# cut trailing comma
99+
deleted_redirects="${deleted_redirects%,}"
94100
95101
echo "redirects=${deleted_redirects}" >> "$GITHUB_OUTPUT"
96102
@@ -100,17 +106,30 @@ jobs:
100106
RENAMED_REDIRECTS: ${{ steps.renamed-files.outputs.redirects }}
101107
DELETED_REDIRECTS: ${{ steps.deleted-files.outputs.redirects }}
102108
run: |
103-
combined_redirect_html="${RENAMED_REDIRECTS}${DELETED_REDIRECTS}"
109+
# empty string that stays empty if there are no redirects to suggest
110+
redirect_html=""
104111
105-
echo "redirect_html=${combined_redirect_html}" >> "$GITHUB_OUTPUT"
112+
combined_redirect_string="${RENAMED_REDIRECTS},${DELETED_REDIRECTS}"
113+
114+
IFS=','
115+
for redirect in $combined_redirect_string; do
116+
if [[ ! -z "$redirect" ]]; then
117+
if [[ -z "$redirect_html" ]]; then
118+
redirect_html="<i>Suggested redirects for moved/deleted files (replace &lt;v&gt; with earliest backport target version):</i>"
119+
fi
120+
redirect_html+="<li>[&lt;v&gt;-\*]: $redirect</li>"
121+
fi
122+
done
123+
124+
echo "redirect_html=${redirect_html}" >> "$GITHUB_OUTPUT"
106125
107126
- name: Update PR Description
108127
uses: MongoCaleb/pr-description-action@4bdfe35b98f64532b419ad20b350a92546cd3aa1
109128
with:
110129
regex: "- \\[ \\] Did you add redirects\\?.*"
111130
appendContentOnMatchOnly: false
112131
regexFlags: is
113-
content: "- [ ] Did you add redirects?\n ${{ steps.renamed-files.outputs.redirects }}${{ steps.deleted-files.outputs.redirects }}"
132+
content: "- [ ] Did you add redirects?\n ${{ steps.build-redirect-html.outputs.redirect_html }}"
114133
token: ${{ secrets.GITHUB_TOKEN }}
115134

116135
- name: Check for duplicates in redirects file
@@ -123,5 +142,5 @@ jobs:
123142
exit 1 # error
124143
fi
125144
else
126-
echo "Redirects file doesn't exist. Skipping duplicate check."
145+
"Redirects file doesn't exist. Skipping duplicate check."
127146
fi

0 commit comments

Comments
 (0)