Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/create-rpi-image-json.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ jobs:
run: |
chmod +x scripts/generate-imager-json.py
python3 scripts/generate-imager-json.py
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Delete existing RPI Imager JSON release
uses: actions/github-script@v9
Expand Down
13 changes: 12 additions & 1 deletion scripts/generate-imager-json.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import io
import json
import os
import sys
import re
import urllib.request
Expand All @@ -16,14 +17,24 @@
OUTPUT_FILE = "rpi-imager.json"
API_URL = f"https://api.github.com/repos/{OWNER}/{REPO}/releases?per_page=100"

def get_api_headers():
"""Build the GitHub API headers, authenticated when GITHUB_TOKEN is set to avoid the anonymous rate limit."""
headers = {'Accept': 'application/vnd.github+json'}
token = os.environ.get('GITHUB_TOKEN')
if token:
headers['Authorization'] = f'Bearer {token}'
return headers


def fetch_releases():
"""Fetch releases from GitHub API."""
print("Fetching releases from GitHub...")
releases_data = []
try:
page = 1
while True:
with urllib.request.urlopen(f"{API_URL}&page={page}") as response:
request = urllib.request.Request(f"{API_URL}&page={page}", headers=get_api_headers())
with urllib.request.urlopen(request) as response:
page_data = json.loads(response.read().decode())
if not page_data:
break
Expand Down