130 lines
3.7 KiB
PowerShell
130 lines
3.7 KiB
PowerShell
# upload_wheel_to_forgejo_pypi.ps1
|
|
# Upload wheel to Forgejo PyPI for Agravity Client
|
|
#
|
|
# Prerequisites:
|
|
# 1. Create .pypirc file with your Forgejo credentials
|
|
# 2. Copy from .pypirc.example and add your credentials
|
|
#
|
|
# Usage:
|
|
# .\upload_wheel_to_forgejo_pypi.ps1
|
|
|
|
param(
|
|
[switch]$Build = $false,
|
|
[switch]$Help = $false
|
|
)
|
|
|
|
if ($Help) {
|
|
Write-Host @"
|
|
Upload wheel to Forgejo PyPI for Agravity Client
|
|
|
|
USAGE:
|
|
.\upload_wheel_to_forgejo_pypi.ps1 [-Build]
|
|
|
|
OPTIONS:
|
|
-Build Force rebuild wheel before uploading
|
|
-Help Display this help message
|
|
|
|
SETUP:
|
|
1. Create .pypirc in project root
|
|
2. Copy from .pypirc.example as template
|
|
3. Add your Forgejo repository URL and credentials:
|
|
[distutils]
|
|
index-servers = forgejo
|
|
|
|
[forgejo]
|
|
repository = https://git.him-tools.de/api/packages/HIM-public/pypi
|
|
username = __token__
|
|
password = YOUR_ACCESS_TOKEN
|
|
|
|
4. Keep .pypirc in .gitignore (already added)
|
|
|
|
EXAMPLE:
|
|
.\upload_wheel_to_forgejo_pypi.ps1 # Upload existing wheel
|
|
.\upload_wheel_to_forgejo_pypi.ps1 -Build # Rebuild and upload
|
|
"@
|
|
exit 0
|
|
}
|
|
|
|
$projectRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
$pypiRcSrc = Join-Path $projectRoot ".pypirc"
|
|
$pypiRcDest = Join-Path $env:USERPROFILE ".pypirc"
|
|
|
|
Write-Host ""
|
|
Write-Host "========================================================================"
|
|
Write-Host "Agravity Client - Upload to Forgejo PyPI"
|
|
Write-Host "========================================================================"
|
|
Write-Host ""
|
|
|
|
# Check for .pypirc
|
|
if (!(Test-Path $pypiRcSrc)) {
|
|
Write-Host "[!] .pypirc not found in project root!" -ForegroundColor Red
|
|
Write-Host ""
|
|
Write-Host "Setup instructions:"
|
|
Write-Host " 1. cp .pypirc.example .pypirc"
|
|
Write-Host " 2. Edit .pypirc with your Forgejo credentials"
|
|
Write-Host " 3. Run this script again"
|
|
Write-Host ""
|
|
Write-Host "For help: .\upload_wheel_to_forgejo_pypi.ps1 -Help"
|
|
Write-Host ""
|
|
exit 1
|
|
}
|
|
|
|
# Copy .pypirc to user profile
|
|
Write-Host "Configuring credentials..."
|
|
Copy-Item -Path $pypiRcSrc -Destination $pypiRcDest -Force
|
|
|
|
# Activate virtual environment
|
|
$activateScript = Join-Path $projectRoot ".venv\Scripts\Activate.ps1"
|
|
if (Test-Path $activateScript) {
|
|
& $activateScript
|
|
}
|
|
|
|
# Install/upgrade twine if needed
|
|
python -m pip list | Select-String "^twine " > $null
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Host "Installing twine..."
|
|
python -m pip install -q twine
|
|
}
|
|
|
|
# Build wheel if requested or not present
|
|
Push-Location $projectRoot
|
|
if ($Build -or !(Get-ChildItem -Path "dist" -Filter "*.whl" -ErrorAction SilentlyContinue)) {
|
|
if ($Build) {
|
|
Write-Host "Building wheel (forced)..."
|
|
Remove-Item "dist" -Recurse -Force -ErrorAction SilentlyContinue
|
|
} else {
|
|
Write-Host "Building wheel..."
|
|
}
|
|
python build_wheel.py
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Remove-Item $pypiRcDest -Force
|
|
exit 1
|
|
}
|
|
}
|
|
|
|
# Upload to Forgejo PyPI
|
|
Write-Host ""
|
|
Write-Host "========================================================================"
|
|
Write-Host "Uploading to Forgejo PyPI..."
|
|
Write-Host "========================================================================"
|
|
Write-Host ""
|
|
|
|
twine upload -r forgejo dist/*.whl
|
|
$uploadResult = $LASTEXITCODE
|
|
|
|
Pop-Location
|
|
|
|
# Cleanup credentials
|
|
Remove-Item $pypiRcDest -Force
|
|
|
|
Write-Host ""
|
|
Write-Host "========================================================================"
|
|
if ($uploadResult -eq 0) {
|
|
Write-Host "Upload successful!" -ForegroundColor Green
|
|
} else {
|
|
Write-Host "Upload failed" -ForegroundColor Red
|
|
}
|
|
Write-Host "========================================================================"
|
|
Write-Host ""
|
|
|
|
exit $uploadResult
|