Add complete Gitea package publishing support

 Features:
- GiteaPackageRegistry client for PyPI-compatible uploads
- Enhanced release.py with upload/registry commands
- New Makefile targets for Gitea publishing workflow
- Comprehensive documentation with examples

📦 New Commands:
- `release.py registry` - Show registry info & authentication
- `release.py upload` - Upload packages to Gitea
- `release.py publish --to-gitea` - Complete release + upload
- `make release-publish-gitea VERSION=x.y.z` - One-command release

🔧 Infrastructure:
- Automatic package detection (wheel + sdist)
- Dry-run support for safe testing
- Error handling and detailed feedback
- Authentication validation

📚 Documentation:
- PACKAGE_PUBLISHING.md with complete setup guide
- Usage examples and troubleshooting

🚀 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-08 21:06:03 +01:00
parent ab67997324
commit d8d823b101
5 changed files with 575 additions and 4 deletions

View File

@@ -6,7 +6,7 @@ This simplified script works with setuptools-scm for automatic version managemen
Versions are automatically derived from git tags - no manual version bumping needed.
Usage:
python release_simplified.py [command] [options]
python release.py [command] [options]
Commands:
status Show current release status
@@ -14,11 +14,14 @@ Commands:
tag Create git tag for version (e.g., v0.8.0)
build Build release packages
publish Complete release workflow (tag + build + distribute)
upload Upload packages to Gitea registry
registry Show Gitea package registry information
Options:
--version VERSION Git tag version (e.g., 0.8.0, 1.0.0-rc1)
--dry-run Show what would be done without making changes
--force Force operation even with warnings
--to-gitea Upload to Gitea package registry
"""
import subprocess
@@ -28,6 +31,12 @@ from pathlib import Path
from datetime import datetime
from typing import Dict, List, Optional, Tuple
try:
from gitea.package_registry import GiteaPackageRegistry
GITEA_AVAILABLE = True
except ImportError:
GITEA_AVAILABLE = False
class SimpleReleaseManager:
"""Simplified release manager using setuptools-scm."""
@@ -203,6 +212,105 @@ class SimpleReleaseManager:
print(f"🏷️ Git tag v{version} created")
return True
def upload_to_gitea(self, dry_run: bool = False) -> bool:
"""Upload packages to Gitea package registry."""
if not GITEA_AVAILABLE:
print("❌ Gitea package registry not available (missing gitea module)")
return False
try:
registry = GiteaPackageRegistry()
print(f"📡 Uploading to Gitea registry: {registry.pypi_registry_url}")
# Find built packages
dist_dir = self.project_root / "dist"
if not dist_dir.exists():
print("❌ No dist/ directory found. Run 'build' command first.")
return False
wheel_files = list(dist_dir.glob("*.whl"))
sdist_files = list(dist_dir.glob("*.tar.gz"))
if not wheel_files and not sdist_files:
print("❌ No package files found in dist/")
return False
# Upload each package
success = True
for wheel_file in wheel_files:
# Find matching sdist
sdist_file = None
for sdist in sdist_files:
if wheel_file.stem.split('-')[0] == sdist.stem.split('-')[0]:
sdist_file = sdist
break
if not registry.upload_package(wheel_file, sdist_file, dry_run=dry_run):
success = False
# Upload any remaining sdists
uploaded_sdists = []
for wheel_file in wheel_files:
for sdist in sdist_files:
if wheel_file.stem.split('-')[0] == sdist.stem.split('-')[0]:
uploaded_sdists.append(sdist)
for sdist_file in sdist_files:
if sdist_file not in uploaded_sdists:
if not registry.upload_package(sdist_file, dry_run=dry_run):
success = False
return success
except Exception as e:
print(f"❌ Upload to Gitea failed: {e}")
return False
def show_gitea_registry_info(self):
"""Show Gitea package registry information."""
if not GITEA_AVAILABLE:
print("❌ Gitea package registry not available (missing gitea module)")
return
try:
registry = GiteaPackageRegistry()
info = registry.get_registry_info()
print("📦 Gitea Package Registry Information")
print("=" * 50)
print(f"Gitea URL: {info['gitea_url']}")
print(f"Repository: {info['repo_owner']}/{info['repo_name']}")
print(f"PyPI Registry URL: {info['pypi_registry_url']}")
print(f"Package List URL: {info['package_list_url']}")
print(f"Authentication Configured: {'' if info['auth_configured'] else ''}")
print(f"Authentication Valid: {'' if info['auth_valid'] else '' if info['auth_configured'] else 'N/A'}")
if info['auth_configured']:
try:
packages = registry.list_packages()
print(f"\nExisting Packages: {len(packages)}")
for package in packages[:5]: # Show first 5
print(f" - {package.get('name', 'unknown')} (type: {package.get('type', 'unknown')})")
except Exception as e:
print(f"\nError listing packages: {e}")
else:
print("\n Set GITEA_API_TOKEN environment variable for package management")
except Exception as e:
print(f"❌ Error getting registry info: {e}")
def publish_with_gitea(self, version: str, dry_run: bool = False) -> bool:
"""Complete release workflow including Gitea upload."""
if not self.publish_release(version):
return False
if not self.upload_to_gitea(dry_run=dry_run):
print("⚠️ Release completed but Gitea upload failed")
return False
print("🎉 Complete release with Gitea upload successful!")
return True
def main():
parser = argparse.ArgumentParser(
@@ -211,11 +319,12 @@ def main():
epilog=__doc__.split('\n\n')[1]
)
parser.add_argument('command', choices=['status', 'validate', 'tag', 'build', 'publish'],
parser.add_argument('command', choices=['status', 'validate', 'tag', 'build', 'publish', 'upload', 'registry'],
help='Release command to execute')
parser.add_argument('--version', type=str, help='Target version for git tag (e.g., 0.8.0)')
parser.add_argument('--dry-run', action='store_true', help='Show what would be done')
parser.add_argument('--force', action='store_true', help='Force operation despite warnings')
parser.add_argument('--to-gitea', action='store_true', help='Include Gitea package registry upload')
args = parser.parse_args()
manager = SimpleReleaseManager(dry_run=args.dry_run, force=args.force)
@@ -247,7 +356,17 @@ def main():
if not args.version:
print("❌ --version is required for publish command")
sys.exit(1)
manager.publish_release(args.version)
if args.to_gitea:
manager.publish_with_gitea(args.version, args.dry_run)
else:
manager.publish_release(args.version)
elif args.command == 'upload':
manager.upload_to_gitea(args.dry_run)
elif args.command == 'registry':
manager.show_gitea_registry_info()
except Exception as e:
print(f"❌ Error: {e}")