Skip to content

Commit c8d2f78

Browse files
0xLuccaeshabennhussein11
authored
Add workflow to detect url changes (#396)
* Add url checker workflow * Update message * Apply suggestions from code review Co-authored-by: Nicolás Hussein <[email protected]> --------- Co-authored-by: Erin Shaben <[email protected]> Co-authored-by: Nicolás Hussein <[email protected]>
1 parent f826212 commit c8d2f78

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Check Documentation URL Changes
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
8+
jobs:
9+
check-url-changes:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v4
14+
with:
15+
fetch-depth: 0
16+
17+
- name: Identify deleted and renamed files
18+
run: |
19+
# Store deleted files
20+
DELETED_FILES=$(git diff --name-status origin/master ${{ github.event.pull_request.head.sha }} | grep '^D.*\.md$' | cut -f2- || true)
21+
echo "DELETED_FILES<<EOF" >> $GITHUB_ENV
22+
echo "$DELETED_FILES" >> $GITHUB_ENV
23+
echo "EOF" >> $GITHUB_ENV
24+
25+
# Store renamed/moved files
26+
RENAMED_FILES=$(git diff --name-status origin/master ${{ github.event.pull_request.head.sha }} | grep '^R.*\.md$' | awk '{print $2 " -> " $3}' || true)
27+
echo "RENAMED_FILES<<EOF" >> $GITHUB_ENV
28+
echo "$RENAMED_FILES" >> $GITHUB_ENV
29+
echo "EOF" >> $GITHUB_ENV
30+
31+
# Set warning flag if there are any changes
32+
if [ ! -z "$DELETED_FILES" ] || [ ! -z "$RENAMED_FILES" ]; then
33+
echo "warning=true" >> $GITHUB_ENV
34+
else
35+
echo "warning=false" >> $GITHUB_ENV
36+
fi
37+
38+
# Print to console for logging
39+
echo "Deleted files:"
40+
echo "$DELETED_FILES"
41+
echo -e "\nRenamed/Moved files:"
42+
echo "$RENAMED_FILES"
43+
44+
- name: Post PR warning
45+
if: env.warning == 'true'
46+
uses: actions/github-script@v7
47+
with:
48+
github-token: ${{ secrets.GITHUB_TOKEN }}
49+
script: |
50+
const issue_number = context.payload.pull_request.number;
51+
const repo = context.repo;
52+
const deletedFiles = `${process.env.DELETED_FILES}`.trim();
53+
const renamedFiles = `${process.env.RENAMED_FILES}`.trim();
54+
55+
let message = `🔍 **Documentation URL Checker**\n\nThis PR modifies documentation files in ways that could potentially create broken links.\n\n`;
56+
57+
if (deletedFiles) {
58+
message += `**Deleted files:**\n\`\`\`\n${deletedFiles}\n\`\`\`\n\n`;
59+
}
60+
61+
if (renamedFiles) {
62+
message += `**Renamed/Moved files:**\n\`\`\`\n${renamedFiles}\n\`\`\`\n\n`;
63+
}
64+
65+
message += `🚨 Please review these changes carefully 🚨\n\n If 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`;
66+
67+
github.rest.issues.createComment({
68+
owner: repo.owner,
69+
repo: repo.repo,
70+
issue_number: issue_number,
71+
body: message
72+
});

0 commit comments

Comments
 (0)