diff --git a/.githooks/pre-commit b/.githooks/pre-commit index 5de24d0da1c..b3d66f3f69a 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -8,7 +8,11 @@ if git diff --cached --name-only | grep -q "^torch_pin.py$"; then echo "📝 Updating PyTorch commit pin..." # Run the update script - if python .github/scripts/update_pytorch_pin.py; then + hook_output=$(python .github/scripts/update_pytorch_pin.py 2>&1) + hook_status=$? + echo "$hook_output" + + if [ $hook_status -eq 0 ]; then # Check if pytorch.txt was modified if ! git diff --quiet .ci/docker/ci_commit_pins/pytorch.txt; then echo "✅ PyTorch commit pin updated successfully" @@ -19,9 +23,14 @@ if git diff --cached --name-only | grep -q "^torch_pin.py$"; then echo "â„šī¸ PyTorch commit pin unchanged" fi else - echo "❌ Failed to update PyTorch commit pin" - echo "Please run: python .github/scripts/update_pytorch_pin.py" - exit 1 + if echo "$hook_output" | grep -qi "rate limit exceeded"; then + echo "âš ī¸ PyTorch commit pin not updated due to GitHub API rate limiting." + echo " Please manually update .ci/docker/ci_commit_pins/pytorch.txt if needed." + else + echo "❌ Failed to update PyTorch commit pin" + echo "Please run: python .github/scripts/update_pytorch_pin.py" + exit 1 + fi fi fi diff --git a/.github/scripts/update_pytorch_pin.py b/.github/scripts/update_pytorch_pin.py index 85ffd680019..2df0eb8d5a1 100644 --- a/.github/scripts/update_pytorch_pin.py +++ b/.github/scripts/update_pytorch_pin.py @@ -4,7 +4,6 @@ import re import sys import urllib.request -from datetime import datetime def parse_nightly_version(nightly_version): @@ -53,7 +52,7 @@ def get_commit_hash_for_nightly(date_str): Commit hash string """ api_url = "https://api.github.com/repos/pytorch/pytorch/commits" - params = f"?sha=nightly&per_page=100" + params = f"?sha=nightly&per_page=50" url = api_url + params req = urllib.request.Request(url) @@ -74,14 +73,21 @@ def get_commit_hash_for_nightly(date_str): commit_msg = commit.get("commit", {}).get("message", "") # Check if the first line of commit message matches first_line = commit_msg.split("\n")[0].strip() - if first_line == target_title or first_line.startswith(f"{date_str} nightly"): - return commit["sha"] + if first_line.startswith(f"{date_str} nightly"): + return extract_hash_from_title(first_line) raise ValueError( f"Could not find commit with title matching '{target_title}' in nightly branch" ) +def extract_hash_from_title(title): + match = re.search(r"\(([0-9a-fA-F]{7,40})\)", title) + if not match: + raise ValueError(f"Could not extract commit hash from title '{title}'") + return match.group(1) + + def update_pytorch_pin(commit_hash): """ Update .ci/docker/ci_commit_pins/pytorch.txt with the new commit hash.