Add release packaging and automatic update support

This commit is contained in:
Elijah 2026-10-03 19:07:11 -07:00
parent 94cd6b984b
commit f971c374f8
20 changed files with 722 additions and 16 deletions

47
packaging/Publish.ps1 Normal file
View file

@ -0,0 +1,47 @@
param([string]$Version = '', [string]$Directory = 'artifacts/releases', [switch]$Publish)
$ErrorActionPreference = 'Stop'
Set-Location (Split-Path $PSScriptRoot)
if (!$Version) { [xml]$props = Get-Content Directory.Build.props; $Version = $props.Project.PropertyGroup.Version }
if ($Version -notmatch '^\d+\.\d+\.\d+$') { throw 'Use a stable version such as 1.0.0.' }
if (!$env:ASTROFRAME_RELEASE_TOKEN) { throw 'Set ASTROFRAME_RELEASE_TOKEN to a Gitea token with repository write permission. Never put it in source control.' }
$headers = @{ Authorization = "token $env:ASTROFRAME_RELEASE_TOKEN" }
$api = 'https://git.elijahkuntz.com/api/v1/repos/Elijah/AstroFrame'
$files = @()
foreach ($channel in @('win-x64','linux-x64')) {
$folder = Join-Path $Directory $channel
$feedPath = Join-Path $folder "releases.$channel.json"
if (!(Test-Path $feedPath)) { throw "Missing release feed: $feedPath" }
$feed = Get-Content $feedPath -Raw | ConvertFrom-Json
$latest = @($feed.Assets | Where-Object { $_.Type -eq 'Full' -and $_.Version -eq $Version })
if ($latest.Count -ne 1) { throw "No full $Version release for $channel" }
$files += @(Get-ChildItem -LiteralPath $folder -File | Where-Object { $_.Extension -in @('.exe','.AppImage','.nupkg','.json','.sh','.png','.zip') -or $_.Name -like 'RELEASES-*' })
}
foreach ($file in $files) {
if ($file.Extension -eq '.nupkg' -and $file.Name -notlike "AstroFrame-$Version-*") { continue }
if ($file.Length -eq 0) { throw "Empty release asset: $($file.Name)" }
}
$commit = (& git rev-parse HEAD).Trim()
if ($LASTEXITCODE) { throw 'Cannot identify the release commit.' }
if (@(& git status --porcelain).Count -gt 0) { throw 'Commit the release source and push it before publishing.' }
Invoke-RestMethod "$api/commits/$commit" -Headers $headers | Out-Null
$tag = "v$Version"
$release = $null
try { $release = Invoke-RestMethod "$api/releases/tags/$tag" -Headers $headers }
catch { if ([int]$_.Exception.Response.StatusCode -ne 404) { throw } }
if ($release -and !$release.draft) { throw "$tag is already published. Release assets are immutable; build a new version." }
if (!$release) {
$body = @{ tag_name=$tag; target_commitish=$commit; name="AstroFrame $Version"; body="AstroFrame $Version for Windows and Linux. See the repository README for installation and update instructions."; draft=$true; prerelease=$false } | ConvertTo-Json
$release = Invoke-RestMethod "$api/releases" -Method Post -Headers $headers -ContentType 'application/json' -Body $body
}
$attached = @(Invoke-RestMethod "$api/releases/$($release.id)/assets" -Headers $headers)
foreach ($file in $files) {
if ($file.Extension -eq '.nupkg' -and $file.Name -notlike "AstroFrame-$Version-*") { continue }
if ($attached.name -contains $file.Name) { throw "Draft already contains $($file.Name). Remove the conflicting asset explicitly before retrying." }
$name = [Uri]::EscapeDataString($file.Name)
Invoke-RestMethod "$api/releases/$($release.id)/assets?name=$name" -Method Post -Headers $headers -Form @{ attachment=$file } | Out-Null
Write-Output "Attached $($file.Name)"
}
if ($Publish) {
Invoke-RestMethod "$api/releases/$($release.id)" -Method Patch -Headers $headers -ContentType 'application/json' -Body '{"draft":false}' | Out-Null
Write-Output "Published $($release.html_url)"
} else { Write-Output "Draft release ready: $($release.html_url). Review it, then publish in Gitea." }

46
packaging/Release.ps1 Normal file
View file

@ -0,0 +1,46 @@
param(
[string]$Version = '',
[ValidateSet('Both','Windows','Linux')][string]$Platform = 'Both',
[string]$Output = 'artifacts/releases',
[string]$PublishRoot = 'artifacts/publish'
)
$ErrorActionPreference = 'Stop'
$root = Split-Path $PSScriptRoot
Set-Location $root
if (!$Version) { [xml]$props = Get-Content Directory.Build.props; $Version = $props.Project.PropertyGroup.Version }
if ($Version -notmatch '^\d+\.\d+\.\d+$') { throw 'Use a stable version such as 1.0.0.' }
$env:DOTNET_CLI_HOME = Join-Path $root '.tools/home'
$env:NUGET_PACKAGES = Join-Path $root '.tools/packages'
$env:DOTNET_CLI_TELEMETRY_OPTOUT = '1'
New-Item -ItemType Directory -Force '.tools/feed' | Out-Null
$sdk = Join-Path $root '.tools/dotnet/dotnet.exe'
if (!(Test-Path $sdk)) { $sdk = 'dotnet' }
$localVpk = Join-Path $root '.tools/vpk/vpk.exe'
if (!(Test-Path $localVpk)) {
& dotnet tool restore
if ($LASTEXITCODE) { throw 'Velopack restore failed. Its CLI requires a .NET 10 SDK/runtime.' }
}
function Invoke-Vpk([string[]]$Arguments) {
if (Test-Path $localVpk) { & $localVpk @Arguments } else { & dotnet tool run vpk -- @Arguments }
if ($LASTEXITCODE) { throw 'Velopack packaging failed.' }
}
foreach ($rid in @('win-x64','linux-x64')) {
if ($Platform -eq 'Windows' -and $rid -ne 'win-x64') { continue }
if ($Platform -eq 'Linux' -and $rid -ne 'linux-x64') { continue }
$publish = Join-Path (Join-Path $root $PublishRoot) "$Version/$rid"
$releases = Join-Path $Output $rid
if (Test-Path $publish) { throw "Publish folder already exists: $publish. Use a fresh version or remove that build folder explicitly." }
& $sdk publish src/AstroFrame.Desktop -c Release -r $rid --self-contained true "-p:Version=$Version" -o $publish
if ($LASTEXITCODE) { throw "Publish failed for $rid" }
$argsList = @("[$(if($rid -eq 'win-x64'){'win'}else{'linux'})]", 'pack', '--packId', 'AstroFrame', '--packTitle', 'AstroFrame', '--packAuthors', 'Elijah Kuntz', '--packVersion', $Version, '--packDir', $publish, '--runtime', $rid, '--channel', $rid, '--outputDir', $releases)
if ($rid -eq 'win-x64') { $argsList += @('--mainExe','AstroFrame.Desktop.exe','--icon','src/AstroFrame.Desktop/Assets/astroframe.ico','--noPortable') }
else { $argsList += @('--mainExe','AstroFrame.Desktop','--icon','src/AstroFrame.Desktop/Assets/astroframe.png','--categories','Science;Astronomy;') }
Invoke-Vpk $argsList
if ($rid -eq 'linux-x64') {
Copy-Item -LiteralPath 'packaging/install-linux.sh' -Destination $releases
Copy-Item -LiteralPath 'src/AstroFrame.Desktop/Assets/astroframe.png' -Destination (Join-Path $releases 'astroframe.png')
$bundle = Join-Path $releases "AstroFrame-$Version-linux-x64.zip"
Compress-Archive -LiteralPath @((Join-Path $releases 'AstroFrame-linux-x64.AppImage'),(Join-Path $releases 'install-linux.sh'),(Join-Path $releases 'astroframe.png')) -DestinationPath $bundle -Force
}
}
Write-Output "Release $Version built in $Output. Upload all channel files to one Gitea release; see docs/releases.md."

View file

@ -0,0 +1,42 @@
#!/usr/bin/env bash
set -euo pipefail
# Install per-user, keeping the AppImage writable for in-app updates.
source_image="${1:?Usage: bash install-linux.sh /path/to/AstroFrame.AppImage}"
[[ -f "$source_image" ]] || { echo 'AppImage file does not exist.' >&2; exit 1; }
[[ "$(uname -m)" == x86_64 ]] || { echo 'This release requires an x64 PC.' >&2; exit 1; }
install_dir="${XDG_DATA_HOME:-$HOME/.local/share}/AstroFrame/app"
menu_dir="${XDG_DATA_HOME:-$HOME/.local/share}/applications"
icon_dir="${XDG_DATA_HOME:-$HOME/.local/share}/icons/hicolor/256x256/apps"
mkdir -p "$install_dir" "$menu_dir" "$icon_dir"
target="$install_dir/AstroFrame.AppImage"
if [[ -e "$target" && "$source_image" -ef "$target" ]]; then
chmod +x "$target"
else
install -m 755 "$source_image" "$target"
fi
script_dir="$(cd "$(dirname "$0")" && pwd)"
if [[ -f "$script_dir/astroframe.png" ]]; then
install -m 644 "$script_dir/astroframe.png" "$icon_dir/astroframe.png"
fi
# Use a wrapper so desktop files do not need to parse/escape user directory paths.
printf '#!/usr/bin/env bash\nexec %q "$@"\n' "$target" > "$install_dir/launch"
chmod +x "$install_dir/launch"
escaped_launcher="${install_dir//\\/\\\\}/launch"
escaped_launcher="${escaped_launcher//\"/\\\"}"
escaped_launcher="${escaped_launcher//\$/\\\$}"
escaped_launcher="${escaped_launcher//\`/\\\`}"
escaped_launcher="${escaped_launcher//%/%%}"
cat > "$menu_dir/astroframe.desktop" <<EOF
[Desktop Entry]
Type=Application
Name=AstroFrame
Comment=Select astrophotography light frames
Exec="$escaped_launcher" %U
Icon=astroframe
Terminal=false
Categories=Science;Astronomy;
StartupWMClass=AstroFrame.Desktop
EOF
chmod 644 "$menu_dir/astroframe.desktop"
if command -v update-desktop-database >/dev/null 2>&1; then update-desktop-database "$menu_dir"; fi
echo "Installed to $target. Launch AstroFrame from your application menu."

17
packaging/release.sh Normal file
View file

@ -0,0 +1,17 @@
#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")/.."
version="${1:-$(sed -n 's:.*<Version>\(.*\)</Version>.*:\1:p' Directory.Build.props | tr -d '\r')}"
[[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || { echo 'Use a stable version such as 1.0.0.' >&2; exit 1; }
export DOTNET_CLI_HOME="$PWD/.tools/home-linux"
export NUGET_PACKAGES="$PWD/.tools/packages-linux"
export DOTNET_CLI_TELEMETRY_OPTOUT=1
mkdir -p .tools/feed
dotnet tool restore
publish="$PWD/artifacts/publish/$version/linux-x64"
output="$PWD/artifacts/releases/linux-x64"
[[ ! -e "$publish" ]] || { echo "Publish folder already exists: $publish" >&2; exit 1; }
dotnet publish src/AstroFrame.Desktop -c Release -r linux-x64 --self-contained true "-p:Version=$version" -o "$publish"
dotnet tool run vpk -- '[linux]' pack --packId AstroFrame --packTitle AstroFrame --packAuthors 'Elijah Kuntz' --packVersion "$version" --packDir "$publish" --mainExe AstroFrame.Desktop --runtime linux-x64 --channel linux-x64 --icon src/AstroFrame.Desktop/Assets/astroframe.png --categories 'Science;Astronomy;' --outputDir "$output"
cp packaging/install-linux.sh src/AstroFrame.Desktop/Assets/astroframe.png "$output/"
echo "Release $version built in $output. See docs/releases.md before publishing."