feat: Add function to read APP_VERSION from .env or .env.example in create_release.ps1
This commit is contained in:
parent
03c9cbe802
commit
bba6caf7c5
1 changed files with 37 additions and 5 deletions
|
|
@ -1,5 +1,6 @@
|
|||
# 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)
|
||||
# First run will prompt for credentials and save them to this session
|
||||
|
||||
|
|
@ -24,6 +25,37 @@ param(
|
|||
|
||||
$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
|
||||
if ($ClearCredentials) {
|
||||
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
|
||||
}
|
||||
|
||||
# Verify Version parameter
|
||||
# Verify Version parameter - if not provided, read from .env.example
|
||||
if (-not $Version) {
|
||||
Write-Host "ERROR: Version parameter required" -ForegroundColor Red
|
||||
Write-Host "Usage: .\create_release.ps1 -Version 1.0.0" -ForegroundColor Yellow
|
||||
exit 1
|
||||
Write-Host "Version not provided, reading from .env.example..." -ForegroundColor Cyan
|
||||
$Version = Get-VersionFromEnv
|
||||
Write-Host "Using version: $Version" -ForegroundColor Green
|
||||
}
|
||||
|
||||
# Verify files exist
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue