Sorted alphabetically and fixed scripts Gitea detection
All checks were successful
Generate Release Files / generate-releases (push) Successful in 40s

This commit is contained in:
2026-02-06 16:11:45 +01:00
parent 88c581d816
commit 72aa9f54e9
8 changed files with 277 additions and 228 deletions

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env python3
"""
Generate RELEASE_X.ini files by fetching latest GitHub release tags
Generate RELEASE_X.ini files by fetching latest GitHub/Gitea release tags
for sysmodules, overlays, apps, and emulation.
"""
@@ -12,7 +12,7 @@ import urllib.request
import urllib.error
import configparser
from pathlib import Path
from typing import Dict, List, Tuple, Optional
from typing import Dict, List, Tuple, Optional, Any
# GitHub API base URL
GITHUB_API = "https://api.github.com/repos"
@@ -20,7 +20,7 @@ GITHUB_API = "https://api.github.com/repos"
# Get GitHub token from environment variable if available
GITHUB_TOKEN = os.environ.get('GITHUB_TOKEN', '')
def extract_repo_from_url(url: str) -> Optional[Tuple[str, str]]:
def extract_repo_from_github_url(url: str) -> Optional[Tuple[str, str]]:
"""Extract owner and repo from GitHub API URL."""
# Pattern: https://api.github.com/repos/owner/repo/releases?...
match = re.search(r'/repos/([^/]+)/([^/]+)/releases', url)
@@ -28,7 +28,15 @@ def extract_repo_from_url(url: str) -> Optional[Tuple[str, str]]:
return (match.group(1), match.group(2))
return None
def get_latest_tag(owner: str, repo: str) -> Optional[str]:
def extract_repo_from_gitea_url(url: str) -> Optional[Tuple[str, str, str]]:
"""Extract API base, owner and repo from Gitea API URL. Returns (api_base, owner, repo)."""
# Pattern: https://host/api/v1/repos/owner/repo/releases?...
match = re.search(r'(https://[^/]+/api/v1)/repos/([^/]+)/([^/]+)/releases', url)
if match:
return (match.group(1), match.group(2), match.group(3))
return None
def get_latest_tag_github(owner: str, repo: str) -> Optional[str]:
"""Fetch the latest release tag from GitHub API."""
url = f"{GITHUB_API}/{owner}/{repo}/releases?per_page=1"
try:
@@ -52,8 +60,34 @@ def get_latest_tag(owner: str, repo: str) -> Optional[str]:
print(f" Error: {e}")
return None
def parse_ini_file(file_path: Path) -> List[Dict[str, str]]:
"""Parse .ini file and extract entries with GitHub API URLs."""
def get_latest_tag_gitea(api_base: str, owner: str, repo: str) -> Optional[str]:
"""Fetch the latest release tag from Gitea API."""
url = f"{api_base}/repos/{owner}/{repo}/releases?limit=1"
try:
req = urllib.request.Request(url)
req.add_header('User-Agent', 'Release-Tag-Fetcher/1.0')
with urllib.request.urlopen(req, timeout=10) as response:
releases = json.loads(response.read().decode('utf-8'))
if releases and len(releases) > 0:
return releases[0].get('tag_name', releases[0].get('name', ''))
except urllib.error.HTTPError as e:
if e.code == 404:
print(f" Repository not found")
else:
print(f" HTTP {e.code}: {e.reason}")
except Exception as e:
print(f" Error: {e}")
return None
def get_latest_tag(entry: Dict[str, Any]) -> Optional[str]:
"""Fetch the latest release tag from GitHub or Gitea depending on entry source."""
if entry.get('source') == 'gitea':
return get_latest_tag_gitea(entry['api_base'], entry['owner'], entry['repo'])
return get_latest_tag_github(entry['owner'], entry['repo'])
def parse_ini_file(file_path: Path) -> List[Dict[str, Any]]:
"""Parse .ini file and extract entries with GitHub or Gitea API URLs."""
entries = []
with open(file_path, 'r', encoding='utf-8') as f:
@@ -71,22 +105,37 @@ def parse_ini_file(file_path: Path) -> List[Dict[str, str]]:
section_end = section_start + (next_section.start() if next_section else len(content[section_start:]))
section_content = content[section_start:section_end]
# Look for GitHub API URLs in this section
# Look for GitHub API URLs first
github_urls = re.findall(r'https://api\.github\.com/repos/[^\s]+', section_content)
if github_urls:
repo_info = extract_repo_from_url(github_urls[0])
repo_info = extract_repo_from_github_url(github_urls[0])
if repo_info:
entries.append({
'name': section_name,
'owner': repo_info[0],
'repo': repo_info[1],
'source': 'github',
'url': github_urls[0]
})
continue
# Look for Gitea API URLs (e.g. https://host/api/v1/repos/owner/repo/releases?...)
gitea_urls = re.findall(r'https://[^\s]+/api/v1/repos/[^\s]+/releases[^\s]*', section_content)
if gitea_urls:
repo_info = extract_repo_from_gitea_url(gitea_urls[0])
if repo_info:
entries.append({
'name': section_name,
'api_base': repo_info[0],
'owner': repo_info[1],
'repo': repo_info[2],
'source': 'gitea',
'url': gitea_urls[0]
})
return entries
def generate_release_ini(category: str, entries: List[Dict[str, str]], output_path: Path):
def generate_release_ini(category: str, entries: List[Dict[str, Any]], output_path: Path):
"""Generate RELEASE_X.ini file for a category."""
print(f"\nGenerating {output_path.name}...")
print(f"Found {len(entries)} entries")
@@ -120,8 +169,9 @@ def generate_release_ini(category: str, entries: List[Dict[str, str]], output_pa
if i > 0:
time.sleep(0.5) # 500ms delay between requests
print(f" Fetching {entry['name']} ({entry['owner']}/{entry['repo']})...", end=' ')
tag = get_latest_tag(entry['owner'], entry['repo'])
source = entry.get('source', 'github')
print(f" Fetching {entry['name']} ({entry['owner']}/{entry['repo']}) [{source}]...", end=' ')
tag = get_latest_tag(entry)
if tag:
# Remove 'v' prefix if present for cleaner version
clean_tag = tag.lstrip('v')
@@ -170,7 +220,7 @@ def main():
base_path = Path(__file__).parent
include_path = base_path / "include"
print("GitHub Release Tag Fetcher")
print("GitHub / Gitea Release Tag Fetcher")
if GITHUB_TOKEN:
print("✓ Using GitHub token (higher rate limit)")
else: