Skip to content

Commit dac447a

Browse files
committed
fix: Enhance IndexNow submission with key file verification and retry logic
1 parent 0f5bc9b commit dac447a

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

.github/workflows/docs.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ jobs:
6969
python - <<'PY'
7070
import json
7171
import os
72+
import time
7273
import xml.etree.ElementTree as ET
7374
from urllib import request
7475
from urllib.error import HTTPError
@@ -78,6 +79,31 @@ jobs:
7879
key_location = f"https://aalmada.github.io/BookStore/{key}.txt"
7980
sitemap_url = "https://aalmada.github.io/BookStore/sitemap.xml"
8081
82+
# GitHub Pages can take a short time to serve the just-deployed content.
83+
# Retry key-file verification before attempting IndexNow submission.
84+
max_attempts = 8
85+
for attempt in range(1, max_attempts + 1):
86+
try:
87+
with request.urlopen(key_location, timeout=30) as resp:
88+
body = resp.read().decode("utf-8").strip()
89+
if body == key:
90+
print(f"IndexNow key file verified on attempt {attempt}.")
91+
break
92+
raise RuntimeError(
93+
f"Key file content mismatch on attempt {attempt}. "
94+
f"Expected key value, got: {body!r}"
95+
)
96+
except Exception as ex:
97+
if attempt == max_attempts:
98+
print(
99+
"IndexNow key file is not reachable/valid after deployment. "
100+
"Skipping IndexNow submission to avoid failing docs publish."
101+
)
102+
print(f"Last verification error: {ex}")
103+
raise SystemExit(0)
104+
print(f"Waiting for key file propagation (attempt {attempt}/{max_attempts}): {ex}")
105+
time.sleep(15)
106+
81107
with request.urlopen(sitemap_url, timeout=30) as resp:
82108
xml_data = resp.read()
83109
@@ -113,5 +139,12 @@ jobs:
113139
print(response.read().decode("utf-8"))
114140
except HTTPError as e:
115141
print(f"IndexNow error: {e.code} {e.reason}")
142+
if e.code == 403:
143+
print(
144+
"IndexNow returned 403. This usually means key validation is "
145+
"not yet visible to IndexNow or the key/keyLocation does not match. "
146+
"Skipping failure so docs deployment still succeeds."
147+
)
148+
raise SystemExit(0)
116149
raise
117150
PY

0 commit comments

Comments
 (0)