Skip to content

Check for 404 redirect URLs #2190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/scripts/find_redirect_404s.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash
# Takes a list of docs.substrate.io URLs from the netlify _redirects file,
# and checks which of them return 404 response code after following redirects.

# Check if curl is installed
if ! command -v curl &> /dev/null; then
echo "::error::Error: curl is required but not installed"
exit 1
fi

# Check if input file is provided
if [ "$#" -ne 1 ]; then
echo "::error::Usage: $0 <url_list_file>"
echo "::error::url_list_file: Invalid number of arguments"
exit 1
fi

input_file="$1"

# Check if input file exists
if [ ! -f "$input_file" ]; then
echo "::error::Error: File '$input_file' not found"
exit 1
fi

# Process each URL
echo "::warning::The following polkadot.com URLs are missing:"
while IFS= read -r line || [ -n "$line" ]; do
# Skip empty lines
[ -z "$line" ] && continue

# Extract path and destination
path=$(echo "$line" | awk '{print $1}' | xargs)
destination=$(echo "$line" | awk '{print $2}' | xargs)
source_url="https://docs.substrate.io${path}"

# Get HTTP response code with timeout, following redirects
response=$(curl -L -o /dev/null -s -w "%{http_code}" -m 10 "$destination")

if [ "$response" = "404" ]; then
echo "::warning::$destination"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this ain't going fail/report anywhere?
may be collect 404s into array and if it's empty exit 0, if there are elements 1 ?
alternatively send an email/matrix message to room?
otherwise im curious how will we not forget to check and analyze it periodically?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this ain't going fail/report anywhere?
otherwise im curious how will we not forget to check and analyze it periodically?

@RemyLeBerre and I have a recurring weekly call to go over this together (it's one of the call topics). It's a temporary check, and I expect we'll archive the repository/project before we stop having the call.

may be collect 404s into array and if it's empty exit 0, if there are elements 1 ?
alternatively send an email/matrix message to room?

I'd rather we try to avoid adding any integrations, since it's going to be decommissioned pretty soon. I think the same goes for the error code/status. I'd prefer classifying it as a warning, since it's not really a redirect error, and will be fixed on the other side (polkadot.com). This is more a source of information, rather than a trigger to do something in this repo.

fi
done < "$input_file"
25 changes: 25 additions & 0 deletions .github/workflows/404_redirect_checker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
name: Check Redirect 404s

on:
push:
workflow_dispatch:
inputs:
redirect_file:
description: 'Redirect file to check'
required: true
type: string
default: '.github/scripts/polkadot_com_redirects'
schedule:
- cron: '0 14 * * 1' # Every Monday at 2pm UTC

jobs:
check-redirects:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Run redirect checker
run: .github/scripts/find_redirect_404s.sh .netlify/_redirects