Skip to content

Add github action to verify if a redirect was added #3417

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

svekars
Copy link
Contributor

@svekars svekars commented Jun 26, 2025

This PR adds a GitHub Action that automatically checks if redirects are properly set up when files are deleted or renamed. The action:

  1. Runs on pull requests that modify .rst, .py, or .md files in subdirectories excluding files directly in the root.
  2. Identifies deleted or renamed files in the PR.
  3. Verifies that each deleted/renamed file has a corresponding entry in redirects.py
  4. Fails the check if any redirects are missing, prompting the contributor to add them

This gh-action goal is to help maintain proper navigation and prevents broken links when content is moved or removed.

Local testing:

rm -rf beginner_source/text_sentiment_ngrams_tutorial.rst
rm -rf beginner_source/introyt/trainingyt.py
git add -A
git commit -m "Removed test files"
BASE_BRANCH=main CURRENT_BRANCH=$(git branch --show-current) ./.github/scripts/check_redirects.sh

output:

Deleted or renamed files:
beginner_source/introyt/trainingyt.py
beginner_source/text_sentiment_ngrams_tutorial.rst
ERROR: Files were deleted or renamed but redirects.py was not updated. Please update .github/scripts/redirects.py to redirect these files.

Add the following to redirects.py:

redirects = {
    ...
    "beginner/text_sentiment_ngrams_tutorial.html": "../index.html",
    "beginner/introyt/trainingyt.html": "../index.html",
}
git add -A
git commit -m "Updated redirects.py"

Run again:

BASE_BRANCH=main CURRENT_BRANCH=$(git branch --show-current) ./.github/scripts/check_redirects.sh
Deleted or renamed files:
beginner_source/introyt/trainingyt.py
beginner_source/text_sentiment_ngrams_tutorial.rst
All deleted/renamed files have proper redirects. Check passed!
Copy link

pytorch-bot bot commented Jun 26, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/tutorials/3417

Note: Links to docs will display an error until the docs builds have been completed.

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

✅ No Failures

As of commit f753459 with merge base a47d520 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@svekars svekars requested review from clee2000 and malfet June 26, 2025 17:53
@svekars svekars changed the title Add github action to test for redirects Add github action to verify if a redirect was added Jun 26, 2025
Copy link
Contributor

@malfet malfet left a comment

Choose a reason for hiding this comment

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

Looks fine, though it would be nice to change .sh to .py (at least I'm much more comfortable reading Python code than shell script)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment