Git Repository
Mini Video Library
Mini Video Library scannt lokale Medienordner, verwaltet Metadaten und Vorschaubilder und streamt kompatible Videos direkt per HTTP an den Browser.
HTTPS
https://zanvex.de/git/mini-video-library.gitscripts/build.ps1
Zum Verzeichnis[CmdletBinding()]
param(
[string[]]$Targets,
[string]$OutputDirectory = "dist",
[string]$Version,
[switch]$KeepStaging
)
$ErrorActionPreference = "Stop"
Set-StrictMode -Version Latest
$repository = (Resolve-Path (Join-Path $PSScriptRoot "..")).Path
$output = [System.IO.Path]::GetFullPath((Join-Path $repository $OutputDirectory))
if (-not (Get-Command go -ErrorAction SilentlyContinue)) { throw "Go wurde nicht im PATH gefunden." }
if ([string]::IsNullOrWhiteSpace($Version)) {
$Version = (& git -C $repository describe --tags --always --dirty 2>$null)
if ($LASTEXITCODE -ne 0 -or [string]::IsNullOrWhiteSpace($Version)) { $Version = "dev" }
}
$safeVersion = $Version.Trim() -replace '[^0-9A-Za-z._-]', '-'
if (-not $Targets -or $Targets.Count -eq 0) {
$Targets = @(& go tool dist list)
if ($LASTEXITCODE -ne 0) { throw "Go-Targetliste konnte nicht gelesen werden." }
}
$Targets = @($Targets | Sort-Object -Unique)
if (Test-Path -LiteralPath $output) { Remove-Item -LiteralPath $output -Recurse -Force }
New-Item -ItemType Directory -Path $output | Out-Null
$stagingRoot = Join-Path $output ".staging"
New-Item -ItemType Directory -Path $stagingRoot | Out-Null
$oldGOOS, $oldGOARCH, $oldCGO = $env:GOOS, $env:GOARCH, $env:CGO_ENABLED
$built = [System.Collections.Generic.List[string]]::new()
$failed = [System.Collections.Generic.List[string]]::new()
try {
foreach ($target in $Targets) {
$parts = $target -split '/'
if ($parts.Count -ne 2) { throw "Ungültiges Target '$target'. Erwartet wird GOOS/GOARCH." }
$goos, $goarch = $parts
$archiveBase = "mini-video-library_${safeVersion}_${goos}_${goarch}"
$stage = Join-Path $stagingRoot $archiveBase
New-Item -ItemType Directory -Path $stage | Out-Null
$executable = if ($goos -eq "windows") { "video-library.exe" } else { "video-library" }
$env:GOOS, $env:GOARCH, $env:CGO_ENABLED = $goos, $goarch, "0"
Write-Host "Baue $target ..." -ForegroundColor Cyan
& go build -trimpath -buildvcs=false -ldflags "-s -w" -o (Join-Path $stage $executable) ./cmd/video-library
if ($LASTEXITCODE -ne 0) {
Write-Warning "Build für $target wird übersprungen (nicht von den Abhängigkeiten unterstützt)."
$failed.Add($target)
Remove-Item -LiteralPath $stage -Recurse -Force
continue
}
Copy-Item -LiteralPath (Join-Path $repository "README.md") -Destination $stage
Copy-Item -LiteralPath (Join-Path $repository "LICENSE") -Destination $stage
if (Test-Path -LiteralPath (Join-Path $repository "docs")) { Copy-Item -LiteralPath (Join-Path $repository "docs") -Destination $stage -Recurse }
$themeZips = @(Get-ChildItem -LiteralPath (Join-Path $repository "themes") -Filter "*.zip" -File -ErrorAction SilentlyContinue)
if ($themeZips.Count -gt 0) {
$themeDestination = Join-Path $stage "themes"
New-Item -ItemType Directory -Path $themeDestination | Out-Null
$themeZips | Copy-Item -Destination $themeDestination
}
$archive = Join-Path $output ($archiveBase + ".zip")
Compress-Archive -LiteralPath $stage -DestinationPath $archive -CompressionLevel Optimal
$built.Add($archive)
if (-not $KeepStaging) { Remove-Item -LiteralPath $stage -Recurse -Force }
}
}
finally {
$env:GOOS, $env:GOARCH, $env:CGO_ENABLED = $oldGOOS, $oldGOARCH, $oldCGO
if (-not $KeepStaging -and (Test-Path -LiteralPath $stagingRoot)) { Remove-Item -LiteralPath $stagingRoot -Recurse -Force }
}
if ($built.Count -eq 0) { throw "Für kein Target konnte ein Release gebaut werden." }
$checksums = foreach ($archive in $built) {
$hash = (Get-FileHash -LiteralPath $archive -Algorithm SHA256).Hash.ToLowerInvariant()
"$hash $([System.IO.Path]::GetFileName($archive))"
}
[System.IO.File]::WriteAllLines((Join-Path $output "SHA256SUMS.txt"), $checksums, [System.Text.UTF8Encoding]::new($false))
Write-Host "`n$($built.Count) Release-ZIP(s) wurden nach $output geschrieben." -ForegroundColor Green
if ($failed.Count -gt 0) { Write-Warning "$($failed.Count) Targets wurden nicht unterstützt: $($failed -join ', ')" }