Skip to content

Commit 4c33bc8

Browse files
authored
Check for 404 redirect URLs (#2190)
* add new redirects * add redirect everything * create direct community redirects * add a 404 url checker script * read urls from netlify redirects
1 parent bbde935 commit 4c33bc8

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

.github/scripts/find_redirect_404s.sh

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
# Takes a list of docs.substrate.io URLs from the netlify _redirects file,
3+
# and checks which of them return 404 response code after following redirects.
4+
5+
# Check if curl is installed
6+
if ! command -v curl &> /dev/null; then
7+
echo "::error::Error: curl is required but not installed"
8+
exit 1
9+
fi
10+
11+
# Check if input file is provided
12+
if [ "$#" -ne 1 ]; then
13+
echo "::error::Usage: $0 <url_list_file>"
14+
echo "::error::url_list_file: Invalid number of arguments"
15+
exit 1
16+
fi
17+
18+
input_file="$1"
19+
20+
# Check if input file exists
21+
if [ ! -f "$input_file" ]; then
22+
echo "::error::Error: File '$input_file' not found"
23+
exit 1
24+
fi
25+
26+
# Process each URL
27+
echo "::warning::The following polkadot.com URLs are missing:"
28+
while IFS= read -r line || [ -n "$line" ]; do
29+
# Skip empty lines
30+
[ -z "$line" ] && continue
31+
32+
# Extract path and destination
33+
path=$(echo "$line" | awk '{print $1}' | xargs)
34+
destination=$(echo "$line" | awk '{print $2}' | xargs)
35+
source_url="https://docs.substrate.io${path}"
36+
37+
# Get HTTP response code with timeout, following redirects
38+
response=$(curl -L -o /dev/null -s -w "%{http_code}" -m 10 "$destination")
39+
40+
if [ "$response" = "404" ]; then
41+
echo "::warning::$destination"
42+
fi
43+
done < "$input_file"
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
name: Check Redirect 404s
3+
4+
on:
5+
push:
6+
workflow_dispatch:
7+
inputs:
8+
redirect_file:
9+
description: 'Redirect file to check'
10+
required: true
11+
type: string
12+
default: '.github/scripts/polkadot_com_redirects'
13+
schedule:
14+
- cron: '0 14 * * 1' # Every Monday at 2pm UTC
15+
16+
jobs:
17+
check-redirects:
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v4
23+
24+
- name: Run redirect checker
25+
run: .github/scripts/find_redirect_404s.sh .netlify/_redirects

0 commit comments

Comments
 (0)