Skip to content

Add Node.js WebSocket server example #1528

Add Node.js WebSocket server example

Add Node.js WebSocket server example #1528

name: Check if a deleted file needs a redirect
permissions: {}
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
are-redirects-needed:
permissions:
contents: read
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
- name: Get deleted .mdx files
id: deleted-files
run: |
git fetch origin ${{ github.base_ref }}
deleted_files=$(git diff --name-only --diff-filter=D origin/${{ github.base_ref }}...HEAD | grep '\.mdx$' | grep -v '^snippets/' | grep -v '^custom/' || true)
# Reject paths that could break shell when used later (code-injection safe)
while IFS= read -r file; do
[ -z "$file" ] && continue
if [[ "$file" =~ [\"\\] ]]; then
echo "::error file=$file::Path contains invalid characters"
exit 1
fi
printf '%s\n' "$file"
done <<< "$deleted_files" > deleted_files.txt
- name: Check for redirects
run: |
if [ ! -s deleted_files.txt ]; then
echo "No .mdx files were deleted in this PR."
exit 0
fi
echo "Checking redirects for deleted .mdx files..."
missing_redirects=()
while IFS= read -r file; do
if [ -z "$file" ]; then
continue
fi
path_without_ext="${file%.mdx}"
navigation_json=$(jq -c '.navigation' docs.json)
if echo "$navigation_json" | grep -q "$path_without_ext"; then
echo "File $file is in docs.json navigation, checking for redirect..."
if [[ "$path_without_ext" == */index ]]; then
redirect_source="/${path_without_ext%/index}"
else
redirect_source="/$path_without_ext"
fi
echo "Checking for redirect from: $redirect_source"
if ! jq -e --arg source "$redirect_source" '.redirects[] | select(.source == $source)' docs.json > /dev/null; then
echo "::error file=$file::No redirect found for deleted file: $file (expected redirect source: $redirect_source)"
missing_redirects+=("$file")
else
echo "✓ Redirect found for: $file"
fi
else
echo "File $file is not in docs.json navigation, checking if it was removed from docs.json..."
git fetch origin ${{ github.base_ref }}
if git diff --name-only origin/${{ github.base_ref }}...HEAD | grep -q '^docs.json$'; then
echo "docs.json was changed, checking diff for deletions..."
diff_output=$(git diff origin/${{ github.base_ref }}...HEAD -- docs.json)
if echo "$diff_output" | grep -E '^\-' | grep -q "$path_without_ext"; then
echo "File $file was removed from docs.json, checking for redirect..."
if [[ "$path_without_ext" == */index ]]; then
redirect_source="/${path_without_ext%/index}"
else
redirect_source="/$path_without_ext"
fi
echo "Checking for redirect from: $redirect_source"
if ! jq -e --arg source "$redirect_source" '.redirects[] | select(.source == $source)' docs.json > /dev/null; then
echo "::error file=$file::No redirect found for deleted file: $file (expected redirect source: $redirect_source)"
missing_redirects+=("$file")
else
echo "✓ Redirect found for: $file"
fi
else
echo "File $file was not found in docs.json deletions, skipping redirect check"
fi
else
echo "docs.json was not changed, skipping redirect check for $file"
fi
fi
done < deleted_files.txt
if [ ${#missing_redirects[@]} -gt 0 ]; then
echo ""
echo "❌ The following deleted files are missing redirects in docs.json:"
printf ' - %s\n' "${missing_redirects[@]}"
echo ""
echo "Please add redirects to prevent broken links."
exit 1
else
echo ""
echo "✓ All deleted .mdx files have redirects configured."
fi