sdlparser-scrap/scripts/test-all-releases.py

191 lines
5.6 KiB
Python

#!/usr/bin/env python3
import json
import os
import shutil
import subprocess
import sys
from pathlib import Path
# Store original directory
ORIG_DIR = os.getcwd()
# Repository URLs from build.zig
CASTHOLM_REPO = "castholm/SDL"
OFFICIAL_REPO = "libsdl-org/SDL"
def fetch_tags(owner_repo):
"""Fetch tags from GitHub API for a given owner/repo."""
url = f"https://api.github.com/repos/{owner_repo}/tags"
try:
result = subprocess.run(
["curl", "-s", url],
capture_output=True,
text=True,
check=True
)
tags_data = json.loads(result.stdout)
return [tag["name"] for tag in tags_data]
except Exception as e:
print(f"Error fetching tags for {owner_repo}: {e}", file=sys.stderr)
return []
def test_release(repo_name, tag, sdl_url_flag, clean=False):
"""Test a single release tag by running zig build generate."""
os.chdir(ORIG_DIR)
# Change to sdlparser-scrap root (parent of scripts/)
root_dir = Path(__file__).parent.parent
os.chdir(root_dir)
if clean and os.path.exists("sdl3"):
cmd = [
"zig", "build", "fetch-sdl",
sdl_url_flag,
"-Dclean"
]
try:
result = subprocess.run(
cmd,
capture_output=True,
text=True,
check=False
)
if result.returncode == 0:
print(f"fetched sdl repo from {sdl_url_flag}")
else:
print(f"✗ FAILED: {repo_name}/{tag}")
if result.stdout:
print("STDOUT:", result.stdout[-500:]) # Last 500 chars
if result.stderr:
print("STDERR:", result.stderr[-500:])
return result.returncode == 0
except Exception as e:
print(f"✗ ERROR: {repo_name}/{tag} - {e}")
return False
basedir = f"./all-releases/{repo_name}/{tag}"
basedir = basedir.replace("+", '-')
print(f"\n{'='*60}")
print(f"Testing {repo_name}/{tag}")
print(f"Base directory: {basedir}")
print(f"{'='*60}")
cmd = [
"zig", "build", "generate",
f"-Dref={tag}",
f"-Dbasedir={basedir}",
sdl_url_flag
]
try:
result = subprocess.run(
cmd,
capture_output=True,
text=True,
check=False
)
if result.returncode == 0:
print(f"✓ SUCCESS: {repo_name}/{tag}")
else:
print(f"✗ FAILED: {repo_name}/{tag}")
if result.stdout:
print("STDOUT:", result.stdout[-500:]) # Last 500 chars
if result.stderr:
print("STDERR:", result.stderr[-500:])
return result.returncode == 0
except Exception as e:
print(f"✗ ERROR: {repo_name}/{tag} - {e}")
return False
def test_all_releases(releases_data):
"""Test all releases from the releases.json data."""
results = {
"castholm": {"success": 0, "failed": 0},
"official": {"success": 0, "failed": 0}
}
# Test castholm releases
print("\n" + "="*60)
print("TESTING CASTHOLM RELEASES")
print("="*60)
first = True
for tag in releases_data["repos"]["castholm"]["tags"]:
success = test_release("castholm", tag, "-Dsdl-url=git@github.com:castholm/SDL.git", first)
first = False
if success:
results["castholm"]["success"] += 1
else:
results["castholm"]["failed"] += 1
# Test official releases
print("\n" + "="*60)
print("TESTING OFFICIAL RELEASES")
print("="*60)
first = True
for tag in releases_data["repos"]["official"]["tags"]:
success = test_release("official", tag, "-Dofficial", first)
first = False
if success:
results["official"]["success"] += 1
else:
results["official"]["failed"] += 1
# Print summary
print("\n" + "="*60)
print("SUMMARY")
print("="*60)
print(f"Castholm: {results['castholm']['success']} success, {results['castholm']['failed']} failed")
print(f"Official: {results['official']['success']} success, {results['official']['failed']} failed")
total_success = results['castholm']['success'] + results['official']['success']
total_failed = results['castholm']['failed'] + results['official']['failed']
print(f"Total: {total_success} success, {total_failed} failed")
def main():
os.chdir(ORIG_DIR)
# Fetch tags from both repositories
print("Fetching tags from GitHub...")
castholm_tags = fetch_tags(CASTHOLM_REPO)
official_tags = fetch_tags(OFFICIAL_REPO)
official_tags = [x for x in official_tags if not x.startswith("release-2") ]
# Build JSON structure
releases_data = {
"repos": {
"castholm": {
"url": f"git@github.com:{CASTHOLM_REPO}.git",
"tags": castholm_tags
},
"official": {
"url": f"git@github.com:{OFFICIAL_REPO}.git",
"tags": official_tags
}
}
}
# Write to releases.json
output_path = "releases.json"
with open(output_path, "w") as f:
json.dump(releases_data, f, indent=2)
print(f"> Wrote {len(castholm_tags)} castholm tags and {len(official_tags)} official tags to {output_path}")
# Ask if user wants to test all releases
response = input("\nTest all releases? (y/n): ").strip().lower()
if response == 'y':
test_all_releases(releases_data)
if __name__ == "__main__":
main()