118 lines
3.4 KiB
PowerShell
118 lines
3.4 KiB
PowerShell
# Upload Python distribution artifacts to Forgejo PyPI
|
|
#
|
|
# Prerequisites:
|
|
# 1. Create .pypirc in the project root
|
|
# 2. Copy from .pypirc.example and add your Forgejo credentials
|
|
#
|
|
# Usage:
|
|
# .\upload_dist_to_forgejo_pypi.ps1
|
|
# .\upload_dist_to_forgejo_pypi.ps1 -Build
|
|
|
|
param(
|
|
[switch]$Build = $false,
|
|
[switch]$Help = $false
|
|
)
|
|
|
|
if ($Help) {
|
|
Write-Host @"
|
|
Upload distribution artifacts to Forgejo PyPI for Booklooker Client
|
|
|
|
USAGE:
|
|
.\upload_dist_to_forgejo_pypi.ps1 [-Build]
|
|
|
|
OPTIONS:
|
|
-Build Force rebuild the package before uploading
|
|
-Help Display this help message
|
|
|
|
SETUP:
|
|
1. Create .pypirc in the project root
|
|
2. Copy from .pypirc.example as template
|
|
3. Add your Forgejo repository URL and credentials:
|
|
[distutils]
|
|
index-servers = forgejo
|
|
|
|
[forgejo]
|
|
repository = https://your-forgejo-instance.com/api/packages/YOUR_USERNAME/pypi
|
|
username = __token__
|
|
password = YOUR_ACCESS_TOKEN
|
|
|
|
EXAMPLES:
|
|
.\upload_dist_to_forgejo_pypi.ps1 # Upload existing dist artifacts
|
|
.\upload_dist_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"
|
|
$activateScript = Join-Path $projectRoot ".venv\Scripts\Activate.ps1"
|
|
|
|
Write-Host ""
|
|
Write-Host "========================================================================"
|
|
Write-Host "Booklooker Client - Upload to Forgejo PyPI"
|
|
Write-Host "========================================================================"
|
|
Write-Host ""
|
|
|
|
if (!(Test-Path $pypiRcSrc)) {
|
|
Write-Host "[!] .pypirc not found in the project root." -ForegroundColor Red
|
|
Write-Host ""
|
|
Write-Host "Setup instructions:"
|
|
Write-Host " 1. Copy .pypirc.example to .pypirc"
|
|
Write-Host " 2. Edit .pypirc with your Forgejo credentials"
|
|
Write-Host " 3. Run this script again"
|
|
Write-Host ""
|
|
exit 1
|
|
}
|
|
|
|
if (!(Test-Path $activateScript)) {
|
|
Write-Host "[!] Virtual environment activation script not found: $activateScript" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
Write-Host "Configuring credentials..."
|
|
Copy-Item -Path $pypiRcSrc -Destination $pypiRcDest -Force
|
|
|
|
try {
|
|
& $activateScript
|
|
|
|
python -m pip show twine *> $null
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Host "Installing twine..."
|
|
python -m pip install twine
|
|
if ($LASTEXITCODE -ne 0) {
|
|
exit $LASTEXITCODE
|
|
}
|
|
}
|
|
|
|
Push-Location $projectRoot
|
|
|
|
$distArtifacts = Get-ChildItem -Path "dist" -File -ErrorAction SilentlyContinue
|
|
if ($Build -or !$distArtifacts) {
|
|
if ($Build) {
|
|
Write-Host "Rebuilding distribution artifacts..."
|
|
} else {
|
|
Write-Host "No distribution artifacts found. Building package..."
|
|
}
|
|
|
|
python .\build_dist.py
|
|
if ($LASTEXITCODE -ne 0) {
|
|
exit $LASTEXITCODE
|
|
}
|
|
}
|
|
|
|
Write-Host ""
|
|
Write-Host "========================================================================"
|
|
Write-Host "Uploading distribution artifacts to Forgejo PyPI..."
|
|
Write-Host "========================================================================"
|
|
Write-Host ""
|
|
|
|
twine upload -r forgejo dist/*
|
|
exit $LASTEXITCODE
|
|
}
|
|
finally {
|
|
Pop-Location -ErrorAction SilentlyContinue
|
|
if (Test-Path $pypiRcDest) {
|
|
Remove-Item $pypiRcDest -Force -ErrorAction SilentlyContinue
|
|
}
|
|
}
|