feat: Add function to read APP_VERSION from .env or .env.example in create_release.ps1

This commit is contained in:
claudi 2026-01-30 09:57:08 +01:00
parent 03c9cbe802
commit bba6caf7c5

View file

@ -1,5 +1,6 @@
# Create Forgejo Release with Binary Assets # Create Forgejo Release with Binary Assets
# Usage: .\create_release.ps1 -Version 1.0.0 # Usage: .\create_release.ps1 [-Version 1.0.0]
# If -Version is not provided, it will be read from src/webdrop_bridge/__init__.py
# Uses your Forgejo credentials (same as git) # Uses your Forgejo credentials (same as git)
# First run will prompt for credentials and save them to this session # First run will prompt for credentials and save them to this session
@ -24,6 +25,37 @@ param(
$ErrorActionPreference = "Stop" $ErrorActionPreference = "Stop"
# Function to read version from .env or .env.example
function Get-VersionFromEnv {
# PSScriptRoot is build/scripts, go up to project root with ../../
$projectRoot = Resolve-Path (Join-Path $PSScriptRoot "..\..")
# Try .env first (runtime config), then .env.example (template)
$envFile = Join-Path $projectRoot ".env"
$envExampleFile = Join-Path $projectRoot ".env.example"
# Check .env first
if (Test-Path $envFile) {
$content = Get-Content $envFile -Raw
if ($content -match 'APP_VERSION=([^\r\n]+)') {
Write-Host "Version read from .env" -ForegroundColor Gray
return $matches[1].Trim()
}
}
# Fall back to .env.example
if (Test-Path $envExampleFile) {
$content = Get-Content $envExampleFile -Raw
if ($content -match 'APP_VERSION=([^\r\n]+)') {
Write-Host "Version read from .env.example" -ForegroundColor Gray
return $matches[1].Trim()
}
}
Write-Host "ERROR: Could not find APP_VERSION in .env or .env.example" -ForegroundColor Red
exit 1
}
# Handle --ClearCredentials flag # Handle --ClearCredentials flag
if ($ClearCredentials) { if ($ClearCredentials) {
Remove-Item env:FORGEJO_USER -ErrorAction SilentlyContinue Remove-Item env:FORGEJO_USER -ErrorAction SilentlyContinue
@ -61,11 +93,11 @@ if (-not $ForgejoUser -or -not $ForgejoPW) {
Write-Host "Tip: Credentials will persist until you close PowerShell or run: .\create_release.ps1 -ClearCredentials" -ForegroundColor Gray Write-Host "Tip: Credentials will persist until you close PowerShell or run: .\create_release.ps1 -ClearCredentials" -ForegroundColor Gray
} }
# Verify Version parameter # Verify Version parameter - if not provided, read from .env.example
if (-not $Version) { if (-not $Version) {
Write-Host "ERROR: Version parameter required" -ForegroundColor Red Write-Host "Version not provided, reading from .env.example..." -ForegroundColor Cyan
Write-Host "Usage: .\create_release.ps1 -Version 1.0.0" -ForegroundColor Yellow $Version = Get-VersionFromEnv
exit 1 Write-Host "Using version: $Version" -ForegroundColor Green
} }
# Verify files exist # Verify files exist