131 lines
No EOL
3.8 KiB
PowerShell
131 lines
No EOL
3.8 KiB
PowerShell
param(
|
|
[switch]$Build = $false,
|
|
[string]$Version,
|
|
[switch]$Help = $false
|
|
)
|
|
|
|
Set-StrictMode -Version Latest
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
function Show-Help {
|
|
Write-Host @"
|
|
Upload wheel to the Forgejo PyPI registry for ebay-rest-client
|
|
|
|
USAGE:
|
|
.\upload_wheel_to_forgejo_pypi.ps1 [-Build] [-Version <version>]
|
|
|
|
OPTIONS:
|
|
-Build Force a rebuild before uploading
|
|
-Version <version> Set the package version before building
|
|
-Help Display this help message
|
|
|
|
SETUP:
|
|
1. Copy .pypirc.example to .pypirc in the project root
|
|
2. Add your Forgejo access token to .pypirc
|
|
3. Run this script again
|
|
|
|
EXAMPLES:
|
|
.\upload_wheel_to_forgejo_pypi.ps1
|
|
.\upload_wheel_to_forgejo_pypi.ps1 -Build
|
|
.\upload_wheel_to_forgejo_pypi.ps1 -Build -Version 0.1.1
|
|
"@
|
|
}
|
|
|
|
if ($Help) {
|
|
Show-Help
|
|
exit 0
|
|
}
|
|
|
|
$projectRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
$python = Join-Path $projectRoot ".venv\Scripts\python.exe"
|
|
$pypiRcPath = Join-Path $projectRoot ".pypirc"
|
|
$buildScript = Join-Path $projectRoot "scripts\build_wheel.py"
|
|
$distPath = Join-Path $projectRoot "dist"
|
|
|
|
Write-Host ""
|
|
Write-Host "========================================================================"
|
|
Write-Host "eBay REST Client - Upload to Forgejo PyPI"
|
|
Write-Host "========================================================================"
|
|
Write-Host ""
|
|
|
|
if (!(Test-Path $python)) {
|
|
Write-Host "[!] Virtual environment Python not found at .venv\\Scripts\\python.exe" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
if (!(Test-Path $pypiRcPath)) {
|
|
Write-Host "[!] .pypirc not found in project root." -ForegroundColor Red
|
|
Write-Host ""
|
|
Write-Host "Setup instructions:"
|
|
Write-Host " 1. Copy .pypirc.example to .pypirc"
|
|
Write-Host " 2. Edit .pypirc and add your Forgejo access token"
|
|
Write-Host " 3. Run this script again"
|
|
Write-Host ""
|
|
Write-Host "For help: .\upload_wheel_to_forgejo_pypi.ps1 -Help"
|
|
exit 1
|
|
}
|
|
|
|
if (!(Test-Path $buildScript)) {
|
|
Write-Host "[!] Build script not found at scripts\\build_wheel.py" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
$null = & $python -c "import importlib.util, sys; sys.exit(0 if importlib.util.find_spec('twine') else 1)"
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Host "Installing twine..."
|
|
& $python -m pip install twine
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Host "[!] Failed to install twine." -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
}
|
|
|
|
$wheelFiles = @(Get-ChildItem -Path $distPath -Filter "*.whl" -ErrorAction SilentlyContinue)
|
|
|
|
if ($Build -or $wheelFiles.Count -eq 0) {
|
|
if ($Build) {
|
|
Write-Host "Building wheel (forced)..."
|
|
} else {
|
|
Write-Host "Building wheel..."
|
|
}
|
|
|
|
$buildArgs = @($buildScript)
|
|
if ($Version) {
|
|
$buildArgs += "--version"
|
|
$buildArgs += $Version
|
|
}
|
|
|
|
& $python @buildArgs
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Host "[!] Wheel build failed." -ForegroundColor Red
|
|
exit $LASTEXITCODE
|
|
}
|
|
|
|
$wheelFiles = @(Get-ChildItem -Path $distPath -Filter "*.whl" -ErrorAction Stop)
|
|
}
|
|
|
|
if ($wheelFiles.Count -eq 0) {
|
|
Write-Host "[!] No wheel files found in dist." -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
Write-Host ""
|
|
Write-Host "========================================================================"
|
|
Write-Host "Uploading to Forgejo PyPI..."
|
|
Write-Host "========================================================================"
|
|
Write-Host ""
|
|
|
|
& $python -m twine upload --config-file $pypiRcPath -r forgejo $wheelFiles.FullName
|
|
$uploadResult = $LASTEXITCODE
|
|
|
|
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 |