diff --git a/.github/workflows/manifest-docs.yml b/.github/workflows/manifest-docs.yml index a6764b9..de3fc8e 100644 --- a/.github/workflows/manifest-docs.yml +++ b/.github/workflows/manifest-docs.yml @@ -42,6 +42,8 @@ jobs: with: python-version: '3.12' - name: Generate preview from public sources + env: + GITHUB_TOKEN: ${{ github.token }} run: python scripts/sync-docs.py - uses: actions/upload-artifact@v4 with: diff --git a/scripts/sync-docs.py b/scripts/sync-docs.py index b2982b7..c191c48 100644 --- a/scripts/sync-docs.py +++ b/scripts/sync-docs.py @@ -8,6 +8,7 @@ import re import subprocess import tempfile +import time import tomllib import urllib.error import urllib.request @@ -48,16 +49,25 @@ def load_manifest(path): def release(org, repo): - request = urllib.request.Request(f'https://api.github.com/repos/{org}/{repo}/releases/latest', - headers={'Accept': 'application/vnd.github+json', 'User-Agent': 'crewloom-docs-sync'}) - try: - with urllib.request.urlopen(request, timeout=30) as response: - value = json.load(response) - return {'tag': value['tag_name'], 'url': value['html_url'], 'published_at': value['published_at']} - except urllib.error.HTTPError as error: - if error.code == 404: - return None - raise + headers = {'Accept': 'application/vnd.github+json', 'User-Agent': 'crewloom-docs-sync'} + token = os.environ.get('GITHUB_TOKEN') + if token: + headers['Authorization'] = f'Bearer {token}' + request = urllib.request.Request(f'https://api.github.com/repos/{org}/{repo}/releases/latest', headers=headers) + for attempt in range(3): + try: + with urllib.request.urlopen(request, timeout=30) as response: + value = json.load(response) + return {'tag': value['tag_name'], 'url': value['html_url'], 'published_at': value['published_at']} + except urllib.error.HTTPError as error: + if error.code == 404: + return None + # Shared runner IPs can hit the unauthenticated rate limit; retry transient errors. + if error.code in (403, 429) or error.code >= 500: + if attempt < 2: + time.sleep(2 * (attempt + 1)) + continue + raise def collect(project, checkout, latest):