|
69 | 69 | python - <<'PY' |
70 | 70 | import json |
71 | 71 | import os |
| 72 | + import time |
72 | 73 | import xml.etree.ElementTree as ET |
73 | 74 | from urllib import request |
74 | 75 | from urllib.error import HTTPError |
|
78 | 79 | key_location = f"https://aalmada.github.io/BookStore/{key}.txt" |
79 | 80 | sitemap_url = "https://aalmada.github.io/BookStore/sitemap.xml" |
80 | 81 |
|
| 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 | +
|
81 | 107 | with request.urlopen(sitemap_url, timeout=30) as resp: |
82 | 108 | xml_data = resp.read() |
83 | 109 |
|
@@ -113,5 +139,12 @@ jobs: |
113 | 139 | print(response.read().decode("utf-8")) |
114 | 140 | except HTTPError as e: |
115 | 141 | 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) |
116 | 149 | raise |
117 | 150 | PY |
0 commit comments